Skip to main content

TextLayoutEngine

Trait TextLayoutEngine 

Source
pub trait TextLayoutEngine {
    // Required methods
    fn shape(
        &self,
        req: &ShapeRequest<'_>,
        provider: &dyn FontProvider,
    ) -> Result<ZenithGlyphRun, LayoutError>;
    fn shape_with_fallback(
        &self,
        req: &ShapeRequest<'_>,
        provider: &dyn FontProvider,
    ) -> Result<FallbackResult, LayoutError>;
}
Expand description

Trait implemented by every shaping engine.

Engines are free to resolve fonts, call native shapers, and accumulate any internal state, but they must not expose third-party types through this trait.

Required Methods§

Source

fn shape( &self, req: &ShapeRequest<'_>, provider: &dyn FontProvider, ) -> Result<ZenithGlyphRun, LayoutError>

Shape req.text into a ZenithGlyphRun using fonts from provider.

§Errors

Returns LayoutError if no font can be resolved, if the font bytes are malformed, if units_per_em is zero, or if any other shaping step fails.

Source

fn shape_with_fallback( &self, req: &ShapeRequest<'_>, provider: &dyn FontProvider, ) -> Result<FallbackResult, LayoutError>

Shape req.text with per-glyph font fallback, returning a FallbackResult with one ZenithGlyphRun per contiguous sub-run that resolved to a single face, plus any characters that no registered face could cover.

The primary face (resolved from req.families/weight/style) shapes every character it covers; characters the primary lacks are itemized to the first face in provider.all_faces() (deterministic order) that covers them, falling back to the primary (rendering .notdef) when no registered face covers a character. Whitespace and punctuation the primary covers stay with the primary, so mixed-script runs do not fragment on shared characters.

When every character is covered by the primary face this returns exactly one run, identical to Self::shape, with an empty missing_chars.

§Errors

Returns LayoutError under the same conditions as Self::shape (no resolvable primary font, malformed bytes, zero units_per_em).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§