logo
pub trait TextShaper {
    type LengthPrimitive: Mul + Div + Add<Output = Self::LengthPrimitive> + AddAssign + Zero + One + From<i16> + Copy;
    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>;
    type PlatformGlyphData: Clone;

    fn shape_text<GlyphStorage: Extend<Glyph<Self::Length, Self::PlatformGlyphData>>>(
        &self,
        text: &str,
        glyphs: &mut GlyphStorage
    ); fn glyph_for_char(
        &self,
        ch: char
    ) -> Option<Glyph<Self::Length, Self::PlatformGlyphData>>; }
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 performans an M:N mapping from unicode characters to glyphs, via glyph substitions 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

Required Methods

Implementors