BidiText

interface BidiText(source)

The result of the bidirectional analysis of a text.

The analysis resolves embedding levels for whole paragraphs, reordering happens per line. A typical use is:

  1. shape every run returned by runs using its direction and script

  2. break lines on the shaped runs (in logical order)

  3. call visualRuns for every line to find the order in which the line's runs are displayed

All indices are UTF-16 indices into text, line ranges are half-open (lineEnd is exclusive).

Properties

Link copied to clipboard
abstract val levels: ByteArray

The resolved embedding levels per UTF-16 unit, before applying the line based rule L1. Both units of a surrogate pair have the same level. The array must not be modified.

Link copied to clipboard

The paragraphs in text, in logical order

Link copied to clipboard
abstract val text: String

The analyzed text

Functions

Link copied to clipboard
abstract fun lineLevels(lineStart: Int, lineEnd: Int): ByteArray

Returns the embedding levels for the line [lineStart, lineEnd) after applying rule L1: segment separators, paragraph separators and trailing whitespace are reset to the paragraph level.

Link copied to clipboard
abstract fun paragraphAt(index: Int): BidiParagraph

Returns the paragraph containing the UTF-16 index

Link copied to clipboard
abstract fun runs(start: Int = 0, end: Int = text.length): List<BidiRun>

Returns the runs of uniform embedding level and script in [start, end) in logical order. Runs never cross paragraph boundaries.

Link copied to clipboard
abstract fun scriptAt(index: Int): Script

Returns the resolved script of the character at UTF-16 index. Characters of the Common and Inherited scripts are resolved to the script of the surrounding text, they are only reported as Script.COMMON or Script.INHERITED when the paragraph has no other script.

Link copied to clipboard
abstract fun visualOrder(lineStart: Int, lineEnd: Int): IntArray

Returns the visual order of the line [lineStart, lineEnd) (rules L1 and L2): element i is the UTF-16 index of the unit displayed at visual position i, from left to right. Surrogate pairs are kept in logical order. Characters are not mirrored, see BidiTextDriver.mirroredCodePoint.

Link copied to clipboard
abstract fun visualRuns(lineStart: Int, lineEnd: Int): List<BidiRun>

Returns the runs of the line [lineStart, lineEnd) in visual order, from left to right, with levels after rule L1. The characters of a run with a right-to-left BidiRun.direction are displayed right to left; shaping such a run with Direction.RIGHT_TO_LEFT produces glyphs in visual order.