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
impl FontMetricsCache
Sourcepub fn default_capacity() -> Self
pub fn default_capacity() -> Self
Create a cache with default capacity (10,000 entries).
Sourcepub fn get(
&mut self,
font_name: &str,
font_size: f64,
text: &str,
) -> Option<&TextMeasurement>
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.
Sourcepub fn put(
&mut self,
font_name: &str,
font_size: f64,
text: &str,
measurement: TextMeasurement,
)
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).
Sourcepub fn get_or_compute<F>(
&mut self,
font_name: &str,
font_size: f64,
text: &str,
compute: F,
) -> TextMeasurementwhere
F: FnOnce() -> TextMeasurement,
pub fn get_or_compute<F>(
&mut self,
font_name: &str,
font_size: f64,
text: &str,
compute: F,
) -> TextMeasurementwhere
F: FnOnce() -> TextMeasurement,
Get or compute a measurement, using the cache if available.
Sourcepub fn estimate_width(
&mut self,
font_name: &str,
font_size: f64,
text: &str,
char_widths: &HashMap<char, f64>,
default_width: f64,
) -> TextMeasurement
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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FontMetricsCache
impl RefUnwindSafe for FontMetricsCache
impl Send for FontMetricsCache
impl Sync for FontMetricsCache
impl Unpin for FontMetricsCache
impl UnsafeUnpin for FontMetricsCache
impl UnwindSafe for FontMetricsCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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