visual_order
Mojo function 🡭
visual_order
fn def visual_order(codepoints: List[Int], base_level: Int) -> List[Int]The full pipeline: resolve each codepoint’s embedding level, reorder into visual (left-to-right-drawable) order, and mirror any paired character left at an odd (RTL) level. The result is a sequence a caller walks strictly left to right, accumulating glyph advances rightward, exactly as it walks a plain LTR line.
Explicit formatting characters (LRE/RLE/LRO/RLO/PDF and the isolates) are dropped: they are structure, not text, and have no glyph. LRM/RLM/ALM are dropped for the same reason by the caller that renders, but are kept here because they are strong characters whose direction has already been used.
Args:
- codepoints (
List[Int]): A line’s Unicode codepoints, in logical order. - base_level (
Int): The paragraph’s base embedding level – 0 for LTR, 1 for RTL, typically from detect_base_level.
Returns:
List[Int]: The codepoints in visual order, mirrored where an RTL level
requires it, with the explicit formatting characters removed.