pub struct TextRasterizer { /* private fields */ }Expand description
Deterministic text host with version-key result caching.
Results are LRU-cached by content version within a byte budget
(DEFAULT_TEXT_CACHE_BYTES by default) and shared as the same Arc.
Implementations§
Source§impl TextRasterizer
impl TextRasterizer
Sourcepub fn layout(
&self,
request: &TextRasterRequest,
) -> Result<TextLayout, TextRasterError>
pub fn layout( &self, request: &TextRasterRequest, ) -> Result<TextLayout, TextRasterError>
Lays out request’s clusters and lines as Self::rasterize would.
§Errors
Returns the same errors as Self::rasterize.
Sourcepub fn rasterize_animated(
&mut self,
request: &TextRasterRequest,
states: &[ClusterState],
) -> Result<Arc<TextRasterResult>, TextRasterError>
pub fn rasterize_animated( &mut self, request: &TextRasterRequest, states: &[ClusterState], ) -> Result<Arc<TextRasterResult>, TextRasterError>
Self::rasterize with one state per Self::layout cluster, in logical order. Identity
states match Self::rasterize exactly. Results are cached by content version, so give
each set of states its own version.
§Errors
Returns TextRasterError::InvalidRequest when the state count or a value is out of
range, otherwise what Self::rasterize returns.
Source§impl TextRasterizer
impl TextRasterizer
Sourcepub fn empty() -> Self
pub fn empty() -> Self
A rasterizer with no fonts yet; add them with Self::add_font.
Sourcepub fn new(fonts: Vec<TextFont>) -> Result<Self, TextRasterError>
pub fn new(fonts: Vec<TextFont>) -> Result<Self, TextRasterError>
Takes a fallback-ordered OpenType stack.
§Errors
Returns TextRasterError::NoFonts or the first malformed font.
Sourcepub fn add_font(&mut self, source: TextFont) -> Result<(), TextRasterError>
pub fn add_font(&mut self, source: TextFont) -> Result<(), TextRasterError>
Appends a font to the end of the fallback stack.
Clears the result cache.
§Errors
Returns TextRasterError::InvalidFont for malformed font bytes.
Sourcepub fn font_count(&self) -> usize
pub fn font_count(&self) -> usize
Number of fonts in the fallback stack.
Sourcepub fn unmatched_families(&self) -> Vec<String>
pub fn unmatched_families(&self) -> Vec<String>
Requested families no registered font had, sorted, as spelled. Adding fonts later does not clear the list.
Sourcepub fn rasterize(
&mut self,
request: &TextRasterRequest,
) -> Result<Arc<TextRasterResult>, TextRasterError>
pub fn rasterize( &mut self, request: &TextRasterRequest, ) -> Result<Arc<TextRasterResult>, TextRasterError>
Shapes, lays out and rasterizes one request, or returns the cached result for its version.
§Errors
Returns a typed validation, font, or size error.
Sourcepub fn invalidate(&mut self, content_version: u64)
pub fn invalidate(&mut self, content_version: u64)
Drops a single host version after content or font invalidation.
Sourcepub fn set_cache_budget(&mut self, bytes: usize)
pub fn set_cache_budget(&mut self, bytes: usize)
Sets the result cache budget in bytes, evicting down to it. Results larger than the budget are returned but not kept.
Sourcepub fn cache_bytes(&self) -> usize
pub fn cache_bytes(&self) -> usize
Bytes the cached results count against the budget.
Sourcepub fn measure(
&self,
request: &TextRasterRequest,
) -> Result<TextMeasure, TextRasterError>
pub fn measure( &self, request: &TextRasterRequest, ) -> Result<TextMeasure, TextRasterError>
Measures request as Self::rasterize would lay it out, without drawing or caching.
§Errors
Returns the same errors as Self::rasterize.
Sourcepub fn shape(
&self,
request: &TextRasterRequest,
) -> Result<ShapedText, TextRasterError>
pub fn shape( &self, request: &TextRasterRequest, ) -> Result<ShapedText, TextRasterError>
Shapes request as Self::rasterize would, so lines can be broken at any width later.
max_width, fill, strokes, background and content version are ignored.
§Errors
Returns TextRasterError::NoFonts without fonts, and
TextRasterError::InvalidRequest for values Self::rasterize rejects.