# Bidi
Module
## About
`Bidi` lays out text that mixes left-to-right and right-to-left scripts. It implements the parts of the Unicode Bidirectional Algorithm (UAX #9) that editable text needs: character classes, paragraph direction from the first strong character, the weak, neutral, and implicit level rules, and line reordering. Nodes use it through their text layouts; applications normally set `Editor.Direction` or `Node.Direction` instead of calling it.
## Constants
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| ClassAL | Integer | 2 | (None) |
| ClassAN | Integer | 6 | (None) |
| ClassB | Integer | 10 | (None) |
| ClassBN | Integer | 9 | (None) |
| ClassCS | Integer | 7 | (None) |
| ClassEN | Integer | 3 | (None) |
| ClassES | Integer | 4 | (None) |
| ClassET | Integer | 5 | (None) |
| ClassL | Integer | 0 | (None) |
| ClassNSM | Integer | 8 | (None) |
| ClassON | Integer | 13 | (None) |
| ClassR | Integer | 1 | (None) |
| ClassS | Integer | 11 | (None) |
| ClassWS | Integer | 12 | (None) |
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| CharacterClass | character As String | Integer | Returns the Unicode bidirectional class of the first code point of the supplied character, as one of the Class constants. |
| FirstStrongLevel | characters() As String <br> firstIndex As Integer <br> lastIndex As Integer | Integer | Returns 0 when the first strong character in the supplied range is left-to-right, 1 when it is right-to-left, or -1 when the range has no strong character. |
| HasRightToLeft | characters() As String <br> firstIndex As Integer <br> lastIndex As Integer | Boolean | Returns True when any character in the supplied range is right-to-left or an Arabic digit, so its line order may differ from its text order. |
| HitPosition | frames() As Rect <br> rightToLeft() As Boolean <br> text As String <br> x As Double <br> y As Double | Integer | Returns the text position nearest a point, given each storage position frame and whether its character reads right to left. |
| IsRightToLeftLanguage | identifier As String | Boolean | Returns True when the supplied BCP 47 or locale identifier names a language that is written right to left. |
| IsSpace | character As String | Boolean | Returns True for spaces and tabs, which a run leaves undrawn at its edges. |
| JoinsNeighbors | character As String | Boolean | Returns True when the character belongs to a script whose letters join to their neighbors, such as Arabic, so its width depends on the surrounding letters. |
| LeadingEdge | frames() As Rect <br> rightToLeft() As Boolean <br> position As Integer | Double | Returns where the caret goes before the character at the supplied storage position: its left side, or its right side when it reads right to left. |
| ResolvedLevels | characters() As String <br> firstIndex As Integer <br> lastIndex As Integer <br> paragraphLevel As Integer | Integer | Returns the embedding level of each character in the supplied paragraph range, indexed from firstIndex, following the Unicode Bidirectional Algorithm's weak, neutral, and implicit rules. |
| SystemIsRightToLeft | (None) | Boolean | Returns True when the user's system language is written right to left. |
| TrailingEdge | frames() As Rect <br> rightToLeft() As Boolean <br> position As Integer | Double | Returns where the caret goes after the character at the supplied storage position: its right side, or its left side when it reads right to left. |
| VisualNeighbor | frames() As Rect <br> rightToLeft() As Boolean <br> text As String <br> position As Integer <br> moveRight As Boolean | Integer | Returns the text position whose caret is nearest to the right of, or left of, the caret at the supplied position on the same line, or -1 when there is none on that line. |
| VisualOrder | characters() As String <br> levels() As Integer <br> paragraphFirstIndex As Integer <br> lineFirstIndex As Integer <br> lineLastIndex As Integer <br> paragraphLevel As Integer | Integer | Returns the indexes of one line of a paragraph in the order they appear on screen from left to right. levels holds the paragraph's resolved levels, indexed from paragraphFirstIndex. |
## Notes
Explicit embedding, override, and isolate controls (U+202A to U+202E and U+2066 to U+2069) are treated as boundary neutrals, so their effect is ignored. Character classes come from a compact table of ranges rather than the full Unicode database; characters outside the listed ranges are left-to-right.
Levels are indexed from the first character of the paragraph passed to `ResolvedLevels`. `VisualOrder` reorders one line of that paragraph and returns absolute character indexes from left to right. Even levels are left-to-right and odd levels are right-to-left.