Skip to main content

TextProvider

Trait TextProvider 

Source
pub trait TextProvider: Send + Sync {
    // Required method
    fn rasterize_run(&self, run: &TextRun) -> Vec<RasterizedGlyph>;

    // Provided methods
    fn shape_paragraph(&self, _text: &str, _px: f32) -> Option<ShapedParagraph> { ... }
    fn cache_tag(&self) -> u64 { ... }
    fn line_metrics(&self, px: f32) -> Option<LineMetrics> { ... }
    fn measure_run(&self, run: &TextRun) -> f32 { ... }
    fn register_web_font(
        &self,
        _family: &str,
        _data: Vec<u8>,
        _weight: u16,
        _style: FontStyle,
    ) -> Result<bool> { ... }
}
Expand description

Text provider interface. Implementations convert a TextRun into positioned glyph masks.

Required Methods§

Provided Methods§

Source

fn shape_paragraph(&self, _text: &str, _px: f32) -> Option<ShapedParagraph>

Optional paragraph shaping hook for advanced wrappers.

Implementors that can expose Harfbuzz/cosmic-text shaping results should return glyphs with cluster indices and advances. The default implementation returns None, in which case callers must fall back to approximate methods.

Source

fn cache_tag(&self) -> u64

Optional cache tag to distinguish providers in text caches. The default implementation returns 0, which is sufficient when a single provider is used with a given PassManager.

Source

fn line_metrics(&self, px: f32) -> Option<LineMetrics>

Source

fn measure_run(&self, run: &TextRun) -> f32

Measure the total advance width of a styled text run (in the same pixel units as run.size). The default delegates to shape_paragraph, ignoring weight/style/family. Providers that support multiple font faces should override this to select the correct face.

Source

fn register_web_font( &self, _family: &str, _data: Vec<u8>, _weight: u16, _style: FontStyle, ) -> Result<bool>

Register a web font from raw TTF/OTF bytes. Returns Ok(true) if newly registered, Ok(false) if already present. Default implementation returns Ok(false) (no-op).

Implementors§