# BidiAlgorithm

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/media/text_formatting/unicode/struct-bidialgorithm/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
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.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L30)

## Members

- [`new`](#function-new)
- [`resolved_levels`](#function-resolved_levels)
- [`resolved_paragraph_embedding_level`](#function-resolved_paragraph_embedding_level)
- [`FIRST_RIGHT_TO_LEFT`](#assoc_const-first_right_to_left)
- [`is_left_to_right_text`](#function-is_left_to_right_text)
- [`process_left_to_right`](#function-process_left_to_right)
- [`process`](#function-process)
- [`process_classes`](#function-process_classes)
- [`resolve_embedding_level`](#function-resolve_embedding_level)
- [`reset`](#function-reset)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```

Initializes a new instance of the `BidiAlgorithm` class.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L91)

<a id="function-resolved_levels"></a>

### resolved_levels

```rust
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).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L116)

<a id="function-resolved_paragraph_embedding_level"></a>

### resolved_paragraph_embedding_level

```rust
fn resolved_paragraph_embedding_level(self: &Self) -> i32
```

Gets the resolved paragraph embedding level

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L122)

<a id="assoc_const-first_right_to_left"></a>

### FIRST_RIGHT_TO_LEFT

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L129)

<a id="function-is_left_to_right_text"></a>

### is_left_to_right_text

```rust
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).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L137)

<a id="function-process_left_to_right"></a>

### process_left_to_right

```rust
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).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L147)

<a id="function-process"></a>

### process

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L164)

<a id="function-process_classes"></a>

### process_classes

```rust
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.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L187)

<a id="function-resolve_embedding_level"></a>

### resolve_embedding_level

```rust
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 last
  `process` call (or a prefix of it), because the isolate pairs found by
  that call are used to skip isolates.

Returns the resolved embedding level

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L280)

<a id="function-reset"></a>

### reset

```rust
fn reset(self: &mut Self)
```

Resets the bidi algorithm to a clean state.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/media/text_formatting/unicode/bidi_algorithm.rs#L1153)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ErasedDestructor`
- `IntoEither`
- `Debug`
- `Default`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
