Skip to main content

TextRasterizer

Struct TextRasterizer 

Source
pub struct TextRasterizer { /* private fields */ }
Expand description

Deterministic text host with version-key result caching.

Results are cached by content version, least recently used first out, within a byte budget (DEFAULT_TEXT_CACHE_BYTES unless Self::set_cache_budget changes it). A cached result is shared, not copied: a request whose version is cached returns the same Arc.

Implementations§

Source§

impl TextRasterizer

Source

pub fn empty() -> Self

A rasterizer with no fonts yet; add them with Self::add_font.

Source

pub fn new(fonts: Vec<TextFont>) -> Result<Self, TextRasterError>

Takes a fallback-ordered OpenType stack.

§Errors

Returns TextRasterError::NoFonts or the first malformed font.

Source

pub fn add_font(&mut self, source: TextFont) -> Result<(), TextRasterError>

Appends a font to the end of the fallback stack.

Fonts change what every request draws, so the result cache is cleared.

§Errors

Returns TextRasterError::InvalidFont for malformed font bytes.

Source

pub fn font_count(&self) -> usize

Number of fonts in the fallback stack.

Source

pub fn rasterize( &mut self, request: &TextRasterRequest, ) -> Result<Arc<TextRasterResult>, TextRasterError>

Shapes, lays out, and rasterizes one request, or returns the cached result of its exact version, shared rather than copied.

§Errors

Returns a typed validation, font, or size error.

Source

pub fn invalidate(&mut self, content_version: u64)

Drops a single host version after content or font invalidation.

Source

pub fn set_cache_budget(&mut self, bytes: usize)

Sets how many bytes of results the cache keeps, evicting the least recently used down to it. Each result counts its pixels and a small fixed overhead; a result larger than the budget is returned but not kept. Zero keeps nothing.

Source

pub fn cache_bytes(&self) -> usize

Bytes the cached results count against the budget.

Source

pub fn clear(&mut self)

Drops every rasterized result while retaining parsed fonts.

Source

pub fn cache_len(&self) -> usize

Number of versioned raster results currently retained.

Source

pub fn measure( &self, request: &TextRasterRequest, ) -> Result<TextMeasure, TextRasterError>

Where request’s text lies, laid out as Self::rasterize lays it out, without drawing it or touching the result cache.

§Errors

Returns the validation, font, or size error Self::rasterize returns for the same request.

Source

pub fn shape( &self, request: &TextRasterRequest, ) -> Result<ShapedText, TextRasterError>

Shapes request’s text as Self::rasterize would, for layout: its lines at any wrapping width come from the result without shaping again. The request’s max_width, color, outline, background and content version are ignored.

§Errors

Returns TextRasterError::NoFonts without fonts, and TextRasterError::InvalidRequest for a size, line height or text Self::rasterize rejects.

Trait Implementations§

Source§

impl Debug for TextRasterizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.