Skip to main content

VisualLine

Struct VisualLine 

Source
pub struct VisualLine {
    pub visual: Vec<char>,
    pub logical_to_visual: Vec<usize>,
    pub visual_to_logical: Vec<usize>,
    pub base_level: u8,
}
Expand description

The visual-order result of driving the full UAX #9 §3 + §3.4 bidirectional pipeline over one display line.

A renderer that wants correct bidirectional text walks VisualLine::visual left-to-right (the natural rendering direction of the output device), feeding each character to the shaper / cmap and laying the glyphs out in increasing x. The per-character permutation VisualLine::logical_to_visual and its inverse VisualLine::visual_to_logical let the caller map a visual glyph back to its source character (cursor hit-testing, selection-rectangle building) and vice versa.

visual already has rule L4 mirroring applied — every character whose resolved level is odd (right-to-left) and that has a Bidi_Mirroring_Glyph pair (a bracket, an angle quotation mark, a mathematical relation, …) is the mirrored code point, not the logical one — so the renderer must not mirror again.

Fields§

§visual: Vec<char>

The line’s characters in left-to-right visual order, with L4 mirroring applied. visual.len() equals the line’s character count.

§logical_to_visual: Vec<usize>

Permutation entry k is the logical index of the character that belongs at visual position k (the UAX #9 §3.4 L2 output). visual[k] is the L4-mirrored form of the logical character at index logical_to_visual[k].

§visual_to_logical: Vec<usize>

The inverse permutation: entry i is the visual position of the character whose logical index is i. Equivalent to inverting Self::logical_to_visual; precomputed for O(1) logical-to-visual hit-testing.

§base_level: u8

The paragraph embedding level resolved by P2 / P3 (or supplied by the caller as the HL1 override). 0 for an LTR line, 1 for an RTL line.

Implementations§

Source§

impl VisualLine

Source

pub fn to_visual_string(&self) -> String

Collect Self::visual into a String — the line in the order a left-to-right renderer paints it.

Source

pub fn len(&self) -> usize

Number of characters in the line.

Source

pub fn is_empty(&self) -> bool

Whether the line is empty.

Trait Implementations§

Source§

impl Clone for VisualLine

Source§

fn clone(&self) -> VisualLine

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VisualLine

Source§

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

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

impl Eq for VisualLine

Source§

impl PartialEq for VisualLine

Source§

fn eq(&self, other: &VisualLine) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for VisualLine

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.