visual_runs
Mojo function 🡭
visual_runs
fn def visual_runs(codepoints: List[Int], base_level: Int) -> List[BidiRun]The line’s level runs, left to right, each still holding its characters in logical order.
This is rule L2 applied at run granularity rather than to single
positions, which is the same reordering: a maximal span of positions
at or above some level is always a whole number of level runs, so
reversing the runs and then reversing inside each odd-level run
reproduces visual_order’s sequence exactly. Splitting it that way
is what lets a caller shape each run against its logical
neighbors – Arabic joining and ligature formation are defined
there, not against the reversed sequence – and reorder afterwards.
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[BidiRun]: The runs in visual order. A pure left-to-right line is one run.