Skip to main content

ShapeBackend

Trait ShapeBackend 

Source
pub trait ShapeBackend: Send + Sync {
    // Required method
    fn shape(
        &self,
        face_data: &Arc<[u8]>,
        text: &str,
        px_size: f32,
    ) -> Vec<ShapedGlyph>;

    // Provided methods
    fn shape_with_direction(
        &self,
        face_data: &Arc<[u8]>,
        text: &str,
        px_size: f32,
        rtl: bool,
    ) -> Vec<ShapedGlyph> { ... }
    fn shape_with_features(
        &self,
        face_data: &Arc<[u8]>,
        text: &str,
        px_size: f32,
        features: &[ShapeFeature],
    ) -> Vec<ShapedGlyph> { ... }
    fn shape_with_options(
        &self,
        face_data: &Arc<[u8]>,
        text: &str,
        px_size: f32,
        rtl: bool,
        features: &[ShapeFeature],
        _options: &ShapeRequest<'_>,
    ) -> Vec<ShapedGlyph> { ... }
    fn supports_script(&self, font_data: &Arc<[u8]>, script: [u8; 4]) -> bool { ... }
}
Expand description

Trait for swappable text shaping backends.

Implementors must be Send + Sync so they can be shared across threads.

All methods receive face_data: &Arc<[u8]> rather than &[u8] so that the pointer address is preserved across calls. This allows crate::ShapeCache (keyed on Arc::as_ptr) to produce cache hits when the same allocation is reused.

Required Methods§

Source

fn shape( &self, face_data: &Arc<[u8]>, text: &str, px_size: f32, ) -> Vec<ShapedGlyph>

Shape UTF-8 text using font bytes face_data at px_size pixels-per-em, returning one ShapedGlyph per output glyph.

Provided Methods§

Source

fn shape_with_direction( &self, face_data: &Arc<[u8]>, text: &str, px_size: f32, rtl: bool, ) -> Vec<ShapedGlyph>

Shape UTF-8 text with an explicit direction hint.

When rtl is false this is identical to Self::shape.

When rtl is true the backend shapes in the right-to-left direction and returns glyphs sorted in ascending cluster order (logical source order). Visual reordering is the caller’s responsibility.

Backends that do not override this method fall back to Self::shape for LTR and perform a post-sort for RTL, which is correct but may not select the best glyph forms for bidirectional scripts.

Source

fn shape_with_features( &self, face_data: &Arc<[u8]>, text: &str, px_size: f32, features: &[ShapeFeature], ) -> Vec<ShapedGlyph>

Shape UTF-8 text with an explicit set of OpenType feature overrides.

The default implementation ignores the features slice and delegates to Self::shape. Backends that support OpenType feature control should override this method to apply the requested features.

Source

fn shape_with_options( &self, face_data: &Arc<[u8]>, text: &str, px_size: f32, rtl: bool, features: &[ShapeFeature], _options: &ShapeRequest<'_>, ) -> Vec<ShapedGlyph>

Shape text with extended options.

The default implementation delegates to Self::shape_with_features when features is non-empty, or Self::shape otherwise, ignoring any options not covered by those methods. Backends that need to honour additional fields from options (script, language, direction, etc.) should override this method.

Source

fn supports_script(&self, font_data: &Arc<[u8]>, script: [u8; 4]) -> bool

Check if the font has shaping support for a given OpenType script tag.

Returns true if the font likely covers the script, false if a sentinel character from the script’s Unicode range returns no glyph. Unknown scripts (not in the built-in table) return true by default so callers that do not pass script tags are not affected.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§