i_slint_core::textlayout

Trait TextShaper

Source
pub trait TextShaper {
    type LengthPrimitive: Mul + Div + Add<Output = Self::LengthPrimitive> + AddAssign + Zero + One + From<i16> + Copy + Debug;
    type Length: Zero + AddAssign + Add<Output = Self::Length> + Sub<Output = Self::Length> + Default + Clone + Copy + PartialOrd + Mul<Self::LengthPrimitive, Output = Self::Length> + Div<Self::LengthPrimitive, Output = Self::Length> + Debug;

    // Required methods
    fn shape_text<GlyphStorage: Extend<Glyph<Self::Length>>>(
        &self,
        text: &str,
        glyphs: &mut GlyphStorage,
    );
    fn glyph_for_char(&self, ch: char) -> Option<Glyph<Self::Length>>;
    fn max_lines(&self, max_height: Self::Length) -> usize;
}
Expand description

This trait defines the interface between the text layout and the platform specific mapping of text to glyphs. An implementation of the TextShaper trait must provide metric types (Length, LengthPrimitive), which is used for the line breaking calculation and glyph positioning, as well as an opaque platform specific glyph data type.

Functionality wise it provides the ability to convert a string into a set of glyphs, each of which has basic metric fields as well as an offset back into the original string. Typically this is implemented by using a general text shaper, which performs an M:N mapping from unicode characters to glyphs, via glyph substitutions and script specific rules. In addition the glyphs may be positioned for the required appearance (such as stacked diacritics).

Finally, for convenience the TextShaper also provides a single glyph_for_char function, for example used to lookup single glyphs (such as the elision character) as well as additional metrics used for text paragraph layout.

Required Associated Types§

Source

type LengthPrimitive: Mul + Div + Add<Output = Self::LengthPrimitive> + AddAssign + Zero + One + From<i16> + Copy + Debug

Source

type Length: Zero + AddAssign + Add<Output = Self::Length> + Sub<Output = Self::Length> + Default + Clone + Copy + PartialOrd + Mul<Self::LengthPrimitive, Output = Self::Length> + Div<Self::LengthPrimitive, Output = Self::Length> + Debug

Required Methods§

Source

fn shape_text<GlyphStorage: Extend<Glyph<Self::Length>>>( &self, text: &str, glyphs: &mut GlyphStorage, )

Source

fn glyph_for_char(&self, ch: char) -> Option<Glyph<Self::Length>>

Source

fn max_lines(&self, max_height: Self::Length) -> usize

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§