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§
Sourcefn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<()>
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.
Sourcefn all_font_names(&self) -> Vec<String>
fn all_font_names(&self) -> Vec<String>
Returns the names of every font family available to layout.
Sourcefn font_id(&self, descriptor: &Font) -> Result<FontId>
fn font_id(&self, descriptor: &Font) -> Result<FontId>
Returns the id of the font that best matches descriptor.
Sourcefn font_metrics(&self, font_id: FontId) -> FontMetrics
fn font_metrics(&self, font_id: FontId) -> FontMetrics
Returns the metrics, such as ascent, descent and line gap, for font_id.
Sourcefn typographic_bounds(
&self,
font_id: FontId,
glyph_id: GlyphId,
) -> Result<Bounds<f32>>
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.
Sourcefn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>>
fn advance(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Size<f32>>
Returns the distance the pen moves after drawing this glyph.
Sourcefn glyph_for_char(&self, font_id: FontId, ch: char) -> Option<GlyphId>
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.
Sourcefn rasterize_glyph(&self, params: &RenderGlyphParams) -> Result<RasterizedGlyph>
fn rasterize_glyph(&self, params: &RenderGlyphParams) -> Result<RasterizedGlyph>
Rasterizes a glyph, including its atlas placement and pixels.
Sourcefn layout_text(&self, request: TextLayoutRequest<'_>) -> LineLayout
fn layout_text(&self, request: TextLayoutRequest<'_>) -> LineLayout
Lays out one complete text document, including hard breaks and optional wrapping.
Sourcefn layout_inline(&self, request: InlineLayoutRequest<'_>) -> InlineLayout
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§
Sourcefn font_generation(&self) -> u64
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.
Sourcefn prewarm_fonts(&self, _font_ids: &[FontId])
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.
Sourcefn prepare_raster_style(
&self,
request: RasterStyleRequest,
) -> PreparedRasterStyle
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.
Sourcefn recommended_rendering_mode(
&self,
_font_id: FontId,
_font_size: Pixels,
) -> TextRenderingMode
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".