Skip to main content

PlatformTextSystem

Trait PlatformTextSystem 

Source
pub trait PlatformTextSystem: Send + Sync {
Show 14 methods // Required methods fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<()>; fn all_font_names(&self) -> Vec<String>; fn font_id(&self, descriptor: &Font) -> Result<FontId>; fn font_metrics(&self, font_id: FontId) -> FontMetrics; fn typographic_bounds( &self, font_id: FontId, glyph_id: GlyphId, ) -> Result<Bounds<f32>>; fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>>; fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId>; fn rasterize_glyph( &self, params: &RenderGlyphParams, ) -> Result<RasterizedGlyph>; fn layout_text(&self, request: TextLayoutRequest<'_>) -> LineLayout; fn layout_inline(&self, request: InlineLayoutRequest<'_>) -> InlineLayout; // Provided methods fn font_generation(&self) -> u64 { ... } fn prewarm_fonts(&self, _font_ids: &[FontId]) { ... } fn prepare_raster_style( &self, request: RasterStyleRequest, ) -> PreparedRasterStyle { ... } fn recommended_rendering_mode( &self, _font_id: FontId, _font_size: Pixels, ) -> TextRenderingMode { ... }
}
Expand description

Loads fonts and lays out text for one platform. Each backend implements this trait.

Application code uses TextSystem, which calls these methods and caches the results. Glyph and layout methods run on whatever thread the caller uses, so implementations must be Send + Sync.

Required Methods§

Source

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

Adds fonts from their file bytes, such as TTF or OTF data, so layout can find them by family name.

Returns an error if any of the bytes can’t be parsed as a font.

Source

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

Returns the names of every font family available to layout.

Source

fn font_id(&self, descriptor: &Font) -> Result<FontId>

Returns the id of the font that best matches descriptor.

Source

fn font_metrics(&self, font_id: FontId) -> FontMetrics

Returns the metrics, such as ascent, descent and line gap, for font_id.

Source

fn typographic_bounds( &self, font_id: FontId, glyph_id: GlyphId, ) -> Result<Bounds<f32>>

Returns the glyph’s bounding box, relative to its origin on the baseline.

Source

fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>>

Returns the distance the pen moves after drawing this glyph.

Source

fn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId>

Returns the glyph that font_id uses for ch, or None if the font has no glyph for it.

Source

fn rasterize_glyph(&self, params: &RenderGlyphParams) -> Result<RasterizedGlyph>

Rasterizes a glyph, including its atlas placement and pixels.

Source

fn layout_text(&self, request: TextLayoutRequest<'_>) -> LineLayout

Lays out one complete text document, including hard breaks and optional wrapping.

Source

fn layout_inline(&self, request: InlineLayoutRequest<'_>) -> InlineLayout

Lays out one complete text document that contains atomic element boxes, which keep their size and sit on the text line.

Provided Methods§

Source

fn font_generation(&self) -> u64

Returns a number that changes whenever the font collection changes, so caches can detect stale entries.

The default returns 0, which means the collection never changes.

Source

fn prewarm_fonts(&self, _font_ids: &[FontId])

Loads the caches that shaping needs for font_ids, so the first layout with them is fast. The default does nothing.

Source

fn prepare_raster_style( &self, request: RasterStyleRequest, ) -> PreparedRasterStyle

Returns the raster style to use for request, normalized so that cached glyph pixels can be shared. The default uses the requested mode unchanged.

Source

fn recommended_rendering_mode( &self, _font_id: FontId, _font_size: Pixels, ) -> TextRenderingMode

Returns the text rendering mode the platform recommends for font_id at font_size.

The default returns TextRenderingMode::Subpixel.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§