Skip to main content

TextShaper

Trait TextShaper 

Source
pub trait TextShaper {
    // Required method
    fn shape(
        &mut self,
        text: &str,
        size_px: f32,
        opts: ShapeOptions,
    ) -> Option<ShapedRun>;

    // Provided methods
    fn measure(
        &mut self,
        text: &str,
        size_px: f32,
        max_width: Option<f32>,
        wrap: WrapMode,
        max_lines: Option<u32>,
    ) -> (f32, f32) { ... }
    fn measure_with_baseline(
        &mut self,
        text: &str,
        size_px: f32,
        opts: &ShapeOptions,
    ) -> (f32, f32, f32) { ... }
    fn cache_len(&self) -> usize { ... }
    fn set_capacity(&mut self, _entries: usize) { ... }
}
Expand description

Backend that turns strings into ShapedRuns.

Required Methods§

Source

fn shape( &mut self, text: &str, size_px: f32, opts: ShapeOptions, ) -> Option<ShapedRun>

Shape text at size_px under the given ShapeOptions. Returns None when the input is empty, when no font can be resolved, or when shaping fails (rare).

Pass ShapeOptions::default() for the no-wrap, unbounded case (caret / selection prefix measurement, label sizing without a container width).

Provided Methods§

Source

fn measure( &mut self, text: &str, size_px: f32, max_width: Option<f32>, wrap: WrapMode, max_lines: Option<u32>, ) -> (f32, f32)

Measure a text run for layout. Returns the tight (width, height) in logical pixels of the shaped paragraph at size_px under the wrap / max_lines policy, clamped to max_width when Some.

The layout engine calls this from taffy’s measure callback to size text leaves, and the caret-scroll pass calls it to place the caret on the shaped prefix.

Source

fn measure_with_baseline( &mut self, text: &str, size_px: f32, opts: &ShapeOptions, ) -> (f32, f32, f32)

Same as Self::measure, plus the first-line alphabetic baseline offset from the top of the leaf box - the y at which Latin, Cyrillic, and Greek glyphs sit. FlexAlign::Baseline and the AccessKit text-position report consume it.

The default walks the shaped glyphs: the width is the widest laid out line (taffy’s intrinsic content size), the height is the line count times ShapeOptions::resolved_line_height, and the baseline is 0.8 of that line height, the ratio the common font metrics tables produce. Empty input measures (0, 0, 0) so the leaf collapses. Override it when the backend can answer more cheaply or more precisely than by shaping.

Source

fn cache_len(&self) -> usize

Number of entries the backend currently holds in its shape cache. 0 for a backend that caches nothing.

Source

fn set_capacity(&mut self, _entries: usize)

Resize the shape cache to the given entry count. The per-tick memory-budget sweep calls this when the cache outgrows lumen_core::components::MemoryBudget. No-op for a backend that caches nothing.

Implementors§