unicode_bidi

Struct ParagraphBidiInfo

Source
pub struct ParagraphBidiInfo<'text> {
    pub text: &'text str,
    pub original_classes: Vec<BidiClass>,
    pub levels: Vec<Level>,
    pub paragraph_level: Level,
    pub is_pure_ltr: bool,
}
Expand description

Bidi information of text treated as a single paragraph.

The original_classes and levels vectors are indexed by byte offsets into the text. If a character is multiple bytes wide, then its class and level will appear multiple times in these vectors.

Fields§

§text: &'text str

The text

§original_classes: Vec<BidiClass>

The BidiClass of the character at each byte in the text.

§levels: Vec<Level>

The directional embedding level of each byte in the text.

§paragraph_level: Level

The paragraph embedding level.

§is_pure_ltr: bool

Whether the paragraph is purely LTR.

Implementations§

Source§

impl<'text> ParagraphBidiInfo<'text>

Source

pub fn new( text: &str, default_para_level: Option<Level>, ) -> ParagraphBidiInfo<'_>

Determine the bidi embedding level.

The hardcoded-data Cargo feature (enabled by default) must be enabled to use this.

TODO: In early steps, check for special cases that allow later steps to be skipped. like text that is entirely LTR. See the nsBidi class from Gecko for comparison.

TODO: Support auto-RTL base direction

Source

pub fn new_with_data_source<'a, D: BidiDataSource>( data_source: &D, text: &'a str, default_para_level: Option<Level>, ) -> ParagraphBidiInfo<'a>

Determine the bidi embedding level, with a custom BidiDataSource for Bidi data. If you just wish to use the hardcoded Bidi data, please use BidiInfo::new() instead (enabled with tbe default hardcoded-data Cargo feature).

(This is the single-paragraph equivalent of BidiInfo::new_with_data_source, and should be kept in sync with it.

Source

pub fn reordered_levels(&self, line: Range<usize>) -> Vec<Level>

Produce the levels for this paragraph as needed for reordering, one level per byte in the paragraph. The returned vector includes bytes that are not included in the line, but will not adjust them.

See BidiInfo::reordered_levels for details.

(This should be kept in sync with BidiInfo::reordered_levels.)

Source

pub fn reordered_levels_per_char(&self, line: Range<usize>) -> Vec<Level>

Produce the levels for this paragraph as needed for reordering, one level per character in the paragraph. The returned vector includes characters that are not included in the line, but will not adjust them.

See BidiInfo::reordered_levels_per_char for details.

(This should be kept in sync with BidiInfo::reordered_levels_per_char.)

Source

pub fn reorder_line(&self, line: Range<usize>) -> Cow<'text, str>

Re-order a line based on resolved levels and return the line in display order.

See BidiInfo::reorder_line for details.

(This should be kept in sync with BidiInfo::reorder_line.)

Source

pub fn reorder_visual(levels: &[Level]) -> Vec<usize>

Reorders pre-calculated levels of a sequence of characters.

See BidiInfo::reorder_visual for details.

Source

pub fn visual_runs(&self, line: Range<usize>) -> (Vec<Level>, Vec<LevelRun>)

Find the level runs within a line and return them in visual order.

line is a range of bytes indices within levels.

See BidiInfo::visual_runs for details.

(This should be kept in sync with BidiInfo::visual_runs.)

Source

pub fn has_rtl(&self) -> bool

If processed text has any computed RTL levels

This information is usually used to skip re-ordering of text when no RTL level is present

Source

pub fn direction(&self) -> Direction

Return the paragraph’s Direction (Ltr, Rtl, or Mixed) based on its levels.

Trait Implementations§

Source§

impl<'text> Debug for ParagraphBidiInfo<'text>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'text> PartialEq for ParagraphBidiInfo<'text>

Source§

fn eq(&self, other: &ParagraphBidiInfo<'text>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'text> StructuralPartialEq for ParagraphBidiInfo<'text>

Auto Trait Implementations§

§

impl<'text> Freeze for ParagraphBidiInfo<'text>

§

impl<'text> RefUnwindSafe for ParagraphBidiInfo<'text>

§

impl<'text> Send for ParagraphBidiInfo<'text>

§

impl<'text> Sync for ParagraphBidiInfo<'text>

§

impl<'text> Unpin for ParagraphBidiInfo<'text>

§

impl<'text> UnwindSafe for ParagraphBidiInfo<'text>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.