Level-based reordering of bidirectional text

ID: level-based-reordering-of-bidirectional-text

Level-based reordering of bidirectional text is the final positional reversal procedure of the Unicode Bidirectional Algorithm after directional levels and line boundaries have been resolved. RuleL2 processes thresholds from the largest level down through the smallest level whose value is an odd integer. Each pass reverses every maximal consecutive run whose levels meet or exceed the threshold.[ref]
An original trace supplies the resolved levels rather than attempting to infer them. Take the logical items
At threshold2, reverse only the two middle digits, obtaining . At threshold1, reverse the entire middle five-item run, giving
The digits underwent two reversals, preserving their internal order. The labels each denote one abstract right-to-left text character; every array is written in physical left-to-right order.
Figure 1.
Descending level passes reverse nested runs and restore the internal order of digits
. Reused supplied-level illustration. It demonstrates ruleL2, rather than a complete implementation that resolves levels, shapes glyphs or chooses line boundaries. Details.
Thresholds include intermediate values that no item happens to have. For example, a pair at level4 surrounded by level1 items participates in passes4,3,2 and then the enclosing pass1. Omitting pass3 changes the result, as the bidirectional embedding level example demonstrates.
An implementation may carry levels with the items, as the figure generator does. It can also locate each reversal range from the original fixed level array: earlier passes permute items only inside higher-level runs, preserving the boundaries of every later lower-threshold run. Keeping logical indices on the displayed items supplies the eventual position map. Line-final whitespace resetting belongs to ruleL1, and combining-mark handling and mirroring require their separate rules.[ref]

New to topics? Read the docs here!