Skip to main content

TextSystem

Trait TextSystem 

Source
pub trait TextSystem:
    Send
    + Sync
    + Any {
Show 39 methods // Required methods fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ; fn all_font_names(&self) -> Vec<String>; fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<()>; fn take_missing_glyph_receiver( &self, ) -> Option<Box<dyn MissingGlyphReports>>; fn enable_missing_glyph_reporting(&self); fn disable_missing_glyph_reporting(&self); fn get_font_for_id(&self, id: FontId) -> Option<Font>; fn resolve_font(&self, font: &Font) -> FontId; fn prewarm_fonts(&self, fonts: &[Font]); fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>; fn typographic_bounds( &self, font_id: FontId, font_size: Pixels, character: char, ) -> Result<Bounds<Pixels>>; fn advance( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Result<Size<Pixels>>; fn layout_width( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Pixels; fn em_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>; fn em_advance(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>; fn ch_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>; fn ch_advance(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>; fn units_per_em(&self, font_id: FontId) -> u32; fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels; fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels; fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels; fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels; fn baseline_offset( &self, font_id: FontId, font_size: Pixels, line_height: Pixels, ) -> Pixels; fn take_font_runs(&self) -> Vec<FontRun>; fn recycle_font_runs(&self, font_runs: Vec<FontRun>); fn line_wrapper( self: Arc<Self>, font: Font, font_size: Pixels, ) -> LineWrapperHandle; fn raster_bounds( &self, params: &RenderGlyphParams, ) -> Result<Bounds<DevicePixels>>; fn rasterize_glyph( &self, params: &RenderGlyphParams, ) -> Result<(Size<DevicePixels>, Vec<u8>)>; fn glyph_dilation_for_color(&self, color: Hsla) -> u8; fn recommended_rendering_mode( &self, font_id: FontId, font_size: Pixels, ) -> TextRenderingMode; fn layout_index(&self) -> LineLayoutIndex; fn reuse_layouts(&self, range: Range<LineLayoutIndex>); fn truncate_layouts(&self, index: LineLayoutIndex); fn finish_frame(&self); fn layout_wrapped_line( &self, text: &str, font_size: Pixels, runs: &[FontRun], wrap_width: Option<Pixels>, max_lines: Option<usize>, ) -> Arc<WrappedLineLayout> ⓘ; fn layout_line( &self, text: &str, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Arc<LineLayout> ⓘ; fn try_layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Option<Arc<LineLayout>>; fn layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, materialize_text: Box<dyn FnOnce() -> SharedString>, ) -> Arc<LineLayout> ⓘ; // Provided method fn report_missing_glyphs_in_test(&self, _missing_glyphs: Vec<MissingGlyph>) { ... }
}
Expand description

The text shaping, metric, wrapping, and line-layout surface.

Implementations wrap a PlatformTextSystem with the engine’s font-id, metric, raster-bounds, and line-wrapper pools, and with the per-frame line-layout cache the authoring layer reuses.

Required Methods§

Source

fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ

The platform text system this engine wraps.

Source

fn all_font_names(&self) -> Vec<String>

All font names known to the text system, including fallbacks.

Source

fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<()>

Add font data to the text system.

Source

fn take_missing_glyph_receiver(&self) -> Option<Box<dyn MissingGlyphReports>>

Takes the receiver for missing-glyph reports.

Only one receiver is available for each text system. Returns None when the receiver was already taken or another caller is taking it.

Source

fn enable_missing_glyph_reporting(&self)

Starts reporting grapheme clusters that exhaust font fallback.

Source

fn disable_missing_glyph_reporting(&self)

Stops reporting missing glyphs and discards any reports collected so far.

Source

fn get_font_for_id(&self, id: FontId) -> Option<Font>

The font for a font id, if it was resolved through this system.

Source

fn resolve_font(&self, font: &Font) -> FontId

Resolve a font to its id, falling back to the default stack.

Source

fn prewarm_fonts(&self, fonts: &[Font])

Prewarm any system font caches needed to shape text.

Source

fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>

The bounding box for a font, at a size.

Source

fn typographic_bounds( &self, font_id: FontId, font_size: Pixels, character: char, ) -> Result<Bounds<Pixels>>

The typographic bounds for a character, in a font and size.

Source

fn advance( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Result<Size<Pixels>>

The advance width for a character, in a font and size.

Source

fn layout_width(&self, font_id: FontId, font_size: Pixels, ch: char) -> Pixels

The shaped layout width of a character, in a font and size.

Source

fn em_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>

The width of an em, in a font and size.

Source

fn em_advance(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>

The advance width of an em, in a font and size.

Source

fn ch_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>

The width of the 0 character, in a font and size.

Source

fn ch_advance(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels>

The advance width of the 0 character, in a font and size.

Source

fn units_per_em(&self, font_id: FontId) -> u32

The number of font units per em square.

Source

fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels

The cap height of a font, at a size.

Source

fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels

The x-height of a font, at a size.

Source

fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels

The ascent of a font, at a size.

Source

fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels

The descent of a font, at a size.

Source

fn baseline_offset( &self, font_id: FontId, font_size: Pixels, line_height: Pixels, ) -> Pixels

The recommended baseline offset for a font, size, and line height.

Source

fn take_font_runs(&self) -> Vec<FontRun>

Take a pooled font-run buffer, or an empty one when the pool is dry.

Source

fn recycle_font_runs(&self, font_runs: Vec<FontRun>)

Return a font-run buffer to the pool for reuse.

Source

fn line_wrapper( self: Arc<Self>, font: Font, font_size: Pixels, ) -> LineWrapperHandle

A line wrapper for the given font and size, returned from a pool.

Source

fn raster_bounds( &self, params: &RenderGlyphParams, ) -> Result<Bounds<DevicePixels>>

The rasterized size and location of a glyph.

Source

fn rasterize_glyph( &self, params: &RenderGlyphParams, ) -> Result<(Size<DevicePixels>, Vec<u8>)>

Rasterize a glyph, returning its size and coverage bitmap.

Source

fn glyph_dilation_for_color(&self, color: Hsla) -> u8

The dilation level to use for a glyph painted in the given color.

Source

fn recommended_rendering_mode( &self, font_id: FontId, font_size: Pixels, ) -> TextRenderingMode

The rendering mode recommended for a font and size.

Source

fn layout_index(&self) -> LineLayoutIndex

Saves the current cache position so it can be reused or truncated later.

Source

fn reuse_layouts(&self, range: Range<LineLayoutIndex>)

Re-inserts layouts from the previous frame created before range.

Source

fn truncate_layouts(&self, index: LineLayoutIndex)

Drops layouts created after index.

Source

fn finish_frame(&self)

Ages the current frame’s layouts into the previous frame.

Source

fn layout_wrapped_line( &self, text: &str, font_size: Pixels, runs: &[FontRun], wrap_width: Option<Pixels>, max_lines: Option<usize>, ) -> Arc<WrappedLineLayout> ⓘ

Shapes and wraps text, reusing a cached layout when the inputs match.

Source

fn layout_line( &self, text: &str, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Arc<LineLayout> ⓘ

Shapes a single line of text, reusing a cached layout when the inputs match.

Source

fn try_layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, ) -> Option<Arc<LineLayout>>

Probe the line-layout cache using a caller-provided content hash.

Source

fn layout_line_by_hash( &self, text_hash: u64, text_len: usize, font_size: Pixels, runs: &[FontRun], force_width: Option<Pixels>, materialize_text: Box<dyn FnOnce() -> SharedString>, ) -> Arc<LineLayout> ⓘ

Layout a line using a caller-provided content hash as the cache key.

Provided Methods§

Source

fn report_missing_glyphs_in_test(&self, _missing_glyphs: Vec<MissingGlyph>)

Reports missing glyphs as if the platform text system had observed them.

Defaults to doing nothing, for systems with no report stream. The declaration is deliberately not feature-gated: a #[cfg] here reflects this crate’s feature selection, and feature unification can enable it without the implementing crate’s matching feature - which leaves that implementation reporting E0046 missing report_missing_glyphs_in_test.

Implementations§

Source§

impl dyn TextSystem

Source

pub fn as_any(&self) -> &dyn Any

A type-erased view of this text system, for downcasting to a concrete implementation (e.g. ParleyTextSystem) when a caller needs implementation-specific layout features that the shared SPI does not expose.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§