BidiAlgorithm
struct · ferroui-base · v0.5.0
struct BidiAlgorithm
Implementation of Unicode bidirectional algorithm (UAX #9) https://unicode.org/reports/tr9/
The Bidi algorithm uses a number of memory arrays for resolved types, level information, bracket types, x9 removal maps and more...
This implementation of the BiDi algorithm has been designed to reduce memory pressure by re-using the same work buffers, so instances of this class should be re-used as much as possible.
The caller's tables (original classes, paired bracket types and values,
and the optional output levels) are borrowed for the duration of a
process call instead of being stored as slices like upstream does.
Members
newresolved_levelsresolved_paragraph_embedding_levelFIRST_RIGHT_TO_LEFTis_left_to_right_textprocess_left_to_rightprocessprocess_classesresolve_embedding_levelreset
new
fn new() -> Self
Initializes a new instance of the BidiAlgorithm class.
resolved_levels
fn resolved_levels(self: &Self) -> &[i8]
Gets the resolved levels.
Empty when the last process_classes call was given an output buffer
(the levels were written there).
resolved_paragraph_embedding_level
fn resolved_paragraph_embedding_level(self: &Self) -> i32
Gets the resolved paragraph embedding level
FIRST_RIGHT_TO_LEFT
const FIRST_RIGHT_TO_LEFT: u16
The first code unit of a character whose class is right-to-left (R, AL), an Arabic number (AN) or an explicit embedding, override or isolate control: U+0590, the start of the Hebrew block. The classes below it are L, EN, ES, ET, CS, NSM, BN, B, S, WS and ON.
is_left_to_right_text
fn is_left_to_right_text(text: &[u16]) -> bool
Whether every code unit of text is below Self::FIRST_RIGHT_TO_LEFT: in a paragraph
whose embedding level is 0 every level of such a text is 0. No character opens an
embedding (X1-X8), the start of the one level run is L, so every European number has an L
or the start before it and becomes L (W7), with the separators and terminators next to it
(W4, W5); what is left is neutral and takes the embedding direction (W6, N0-N2), and L
keeps the even level (I1).
process_left_to_right
fn process_left_to_right(self: &mut Self, length: usize)
The result of Self::process for a paragraph of length code units whose embedding
level is 0 and of whose text Self::is_left_to_right_text holds: every resolved level
is 0, and so is the resolved embedding level. The classes are not looked up and no rule is
run (step 7 of docs/porting/text-layout-performance.md).
process
fn process(self: &mut Self, data: &mut BidiData)
Process data from a BiDiData instance
data- The BiDi Unicode data.
The classes of data are updated in place by rule N0 (nonspacing marks
after resolved brackets take the bracket direction), as upstream.
process_classes
fn process_classes(self: &mut Self, types: &mut [BidiClass], paired_bracket_types: &[BidiPairedBracketType], paired_bracket_values: &[i32], paragraph_embedding_level: i8, has_brackets: Option<bool>, has_embeddings: Option<bool>, has_isolates: Option<bool>, out_levels: Option<&mut [i8]>)
Processes Bidi Data
Panics when out_levels is given and its length differs from the input data.
resolve_embedding_level
fn resolve_embedding_level(self: &Self, data: &[BidiClass]) -> i8
Resolve the paragraph embedding level if not explicitly passed by the caller. Also used by rule X5c for FSI isolating sequences.
data- The data to be evaluated; it must be the data of the lastprocesscall (or a prefix of it), because the isolate pairs found by that call are used to skip isolates.
Returns the resolved embedding level
reset
fn reset(self: &mut Self)
Resets the bidi algorithm to a clean state.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEitherDebugDefault
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.