pub trait TextSystem:
Send
+ Sync
+ Any {
Show 38 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<(), Error>;
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>, Error>;
fn advance(
&self,
font_id: FontId,
font_size: Pixels,
ch: char,
) -> Result<Size<Pixels>, Error>;
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, Error>;
fn em_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>;
fn ch_width(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>;
fn ch_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>;
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>, Error>;
fn rasterize_glyph(
&self,
params: &RenderGlyphParams,
) -> Result<(Size<DevicePixels>, Vec<u8>), Error>;
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> ⓘ;
}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§
Sourcefn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ
fn platform_text_system(&self) -> &Arc<dyn PlatformTextSystem> ⓘ
The platform text system this engine wraps.
Sourcefn all_font_names(&self) -> Vec<String>
fn all_font_names(&self) -> Vec<String>
All font names known to the text system, including fallbacks.
Sourcefn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<(), Error>
fn add_fonts(&self, fonts: Vec<Cow<'static, [u8]>>) -> Result<(), Error>
Add font data to the text system.
Sourcefn take_missing_glyph_receiver(&self) -> Option<Box<dyn MissingGlyphReports>>
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.
Sourcefn enable_missing_glyph_reporting(&self)
fn enable_missing_glyph_reporting(&self)
Starts reporting grapheme clusters that exhaust font fallback.
Sourcefn disable_missing_glyph_reporting(&self)
fn disable_missing_glyph_reporting(&self)
Stops reporting missing glyphs and discards any reports collected so far.
Sourcefn get_font_for_id(&self, id: FontId) -> Option<Font>
fn get_font_for_id(&self, id: FontId) -> Option<Font>
The font for a font id, if it was resolved through this system.
Sourcefn resolve_font(&self, font: &Font) -> FontId
fn resolve_font(&self, font: &Font) -> FontId
Resolve a font to its id, falling back to the default stack.
Sourcefn prewarm_fonts(&self, fonts: &[Font])
fn prewarm_fonts(&self, fonts: &[Font])
Prewarm any system font caches needed to shape text.
Sourcefn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>
fn bounding_box(&self, font_id: FontId, font_size: Pixels) -> Bounds<Pixels>
The bounding box for a font, at a size.
Sourcefn typographic_bounds(
&self,
font_id: FontId,
font_size: Pixels,
character: char,
) -> Result<Bounds<Pixels>, Error>
fn typographic_bounds( &self, font_id: FontId, font_size: Pixels, character: char, ) -> Result<Bounds<Pixels>, Error>
The typographic bounds for a character, in a font and size.
Sourcefn advance(
&self,
font_id: FontId,
font_size: Pixels,
ch: char,
) -> Result<Size<Pixels>, Error>
fn advance( &self, font_id: FontId, font_size: Pixels, ch: char, ) -> Result<Size<Pixels>, Error>
The advance width for a character, in a font and size.
Sourcefn layout_width(&self, font_id: FontId, font_size: Pixels, ch: char) -> Pixels
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.
Sourcefn em_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
fn em_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
The width of an em, in a font and size.
Sourcefn em_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
fn em_advance( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
The advance width of an em, in a font and size.
Sourcefn ch_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
fn ch_width(&self, font_id: FontId, font_size: Pixels) -> Result<Pixels, Error>
The width of the 0 character, in a font and size.
Sourcefn ch_advance(
&self,
font_id: FontId,
font_size: Pixels,
) -> Result<Pixels, Error>
fn ch_advance( &self, font_id: FontId, font_size: Pixels, ) -> Result<Pixels, Error>
The advance width of the 0 character, in a font and size.
Sourcefn units_per_em(&self, font_id: FontId) -> u32
fn units_per_em(&self, font_id: FontId) -> u32
The number of font units per em square.
Sourcefn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn cap_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
The cap height of a font, at a size.
Sourcefn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn x_height(&self, font_id: FontId, font_size: Pixels) -> Pixels
The x-height of a font, at a size.
Sourcefn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn ascent(&self, font_id: FontId, font_size: Pixels) -> Pixels
The ascent of a font, at a size.
Sourcefn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels
fn descent(&self, font_id: FontId, font_size: Pixels) -> Pixels
The descent of a font, at a size.
Sourcefn baseline_offset(
&self,
font_id: FontId,
font_size: Pixels,
line_height: Pixels,
) -> Pixels
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.
Sourcefn take_font_runs(&self) -> Vec<FontRun>
fn take_font_runs(&self) -> Vec<FontRun>
Take a pooled font-run buffer, or an empty one when the pool is dry.
Sourcefn recycle_font_runs(&self, font_runs: Vec<FontRun>)
fn recycle_font_runs(&self, font_runs: Vec<FontRun>)
Return a font-run buffer to the pool for reuse.
Sourcefn line_wrapper(
self: Arc<Self>,
font: Font,
font_size: Pixels,
) -> LineWrapperHandle
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.
Sourcefn raster_bounds(
&self,
params: &RenderGlyphParams,
) -> Result<Bounds<DevicePixels>, Error>
fn raster_bounds( &self, params: &RenderGlyphParams, ) -> Result<Bounds<DevicePixels>, Error>
The rasterized size and location of a glyph.
Sourcefn rasterize_glyph(
&self,
params: &RenderGlyphParams,
) -> Result<(Size<DevicePixels>, Vec<u8>), Error>
fn rasterize_glyph( &self, params: &RenderGlyphParams, ) -> Result<(Size<DevicePixels>, Vec<u8>), Error>
Rasterize a glyph, returning its size and coverage bitmap.
Sourcefn glyph_dilation_for_color(&self, color: Hsla) -> u8
fn glyph_dilation_for_color(&self, color: Hsla) -> u8
The dilation level to use for a glyph painted in the given color.
Sourcefn recommended_rendering_mode(
&self,
font_id: FontId,
font_size: Pixels,
) -> TextRenderingMode
fn recommended_rendering_mode( &self, font_id: FontId, font_size: Pixels, ) -> TextRenderingMode
The rendering mode recommended for a font and size.
Sourcefn layout_index(&self) -> LineLayoutIndex
fn layout_index(&self) -> LineLayoutIndex
Saves the current cache position so it can be reused or truncated later.
Sourcefn reuse_layouts(&self, range: Range<LineLayoutIndex>)
fn reuse_layouts(&self, range: Range<LineLayoutIndex>)
Re-inserts layouts from the previous frame created before range.
Sourcefn truncate_layouts(&self, index: LineLayoutIndex)
fn truncate_layouts(&self, index: LineLayoutIndex)
Drops layouts created after index.
Sourcefn finish_frame(&self)
fn finish_frame(&self)
Ages the current frame’s layouts into the previous frame.
Sourcefn layout_wrapped_line(
&self,
text: &str,
font_size: Pixels,
runs: &[FontRun],
wrap_width: Option<Pixels>,
max_lines: Option<usize>,
) -> Arc<WrappedLineLayout> ⓘ
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.
Sourcefn layout_line(
&self,
text: &str,
font_size: Pixels,
runs: &[FontRun],
force_width: Option<Pixels>,
) -> Arc<LineLayout> ⓘ
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.
Sourcefn 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 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.
Sourcefn 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> ⓘ
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.
Implementations§
Trait Implementations§
Source§impl DefaultTextSystemExt for dyn TextSystem + '_
impl DefaultTextSystemExt for dyn TextSystem + '_
Source§fn as_default_text_system(&self) -> Option<&DefaultTextSystem>
fn as_default_text_system(&self) -> Option<&DefaultTextSystem>
DefaultTextSystem, when it is one.Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".