Skip to main content

FontMetricsCache

Struct FontMetricsCache 

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

A font metrics cache that stores computed measurements to avoid redundant width calculations during pipeline processing.

Implementations§

Source§

impl FontMetricsCache

Source

pub fn new(max_entries: usize) -> Self

Create a new cache with a maximum entry limit.

Source

pub fn default_capacity() -> Self

Create a cache with default capacity (10,000 entries).

Source

pub fn get( &mut self, font_name: &str, font_size: f64, text: &str, ) -> Option<&TextMeasurement>

Look up a cached measurement. Returns None on cache miss.

Source

pub fn put( &mut self, font_name: &str, font_size: f64, text: &str, measurement: TextMeasurement, )

Store a measurement in the cache. If the cache is full, it will be cleared (simple eviction strategy).

Source

pub fn get_or_compute<F>( &mut self, font_name: &str, font_size: f64, text: &str, compute: F, ) -> TextMeasurement
where F: FnOnce() -> TextMeasurement,

Get or compute a measurement, using the cache if available.

Source

pub fn estimate_width( &mut self, font_name: &str, font_size: f64, text: &str, char_widths: &HashMap<char, f64>, default_width: f64, ) -> TextMeasurement

Estimate the width of a text string given per-character widths from a font. This is a convenience method using a simple character-width lookup.

Source

pub fn hits(&self) -> u64

Number of cache hits.

Source

pub fn misses(&self) -> u64

Number of cache misses.

Source

pub fn hit_rate(&self) -> f64

Cache hit rate as a fraction (0.0 to 1.0).

Source

pub fn len(&self) -> usize

Number of entries currently in the cache.

Source

pub fn is_empty(&self) -> bool

Whether the cache is empty.

Source

pub fn clear(&mut self)

Clear all cached entries and reset counters.

Trait Implementations§

Source§

impl Debug for FontMetricsCache

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V