pub struct FontContext { /* private fields */ }Expand description
Shared font context used by layout and PDF serialization. Provides text measurement with real glyph metrics.
Implementations§
Source§impl FontContext
impl FontContext
pub fn new() -> Self
Sourcepub fn sentinel_digit_count(&self) -> u32
pub fn sentinel_digit_count(&self) -> u32
Get the current sentinel digit count.
Sourcepub fn set_sentinel_digit_count(&mut self, count: u32)
pub fn set_sentinel_digit_count(&mut self, count: u32)
Set the number of digits used to measure page number sentinel width.
Sourcepub fn saw_page_sentinel(&self) -> bool
pub fn saw_page_sentinel(&self) -> bool
Whether a page-number sentinel was measured since the last reset. Used to decide if the sentinel re-layout loop is needed at all.
Sourcepub fn reset_page_sentinel(&self)
pub fn reset_page_sentinel(&self)
Clear the sentinel-seen flag before a layout pass.
Sourcepub fn char_width(
&self,
ch: char,
family: &str,
weight: u32,
italic: bool,
font_size: f64,
) -> f64
pub fn char_width( &self, ch: char, family: &str, weight: u32, italic: bool, font_size: f64, ) -> f64
Get the advance width of a single character in points.
When family contains a comma (font fallback chain), resolves the
best font for this specific character before measuring.
Sourcepub fn measure_string(
&self,
text: &str,
family: &str,
weight: u32,
italic: bool,
font_size: f64,
letter_spacing: f64,
) -> f64
pub fn measure_string( &self, text: &str, family: &str, weight: u32, italic: bool, font_size: f64, letter_spacing: f64, ) -> f64
Measure the width of a string in points.
Sourcepub fn resolve(&self, family: &str, weight: u32, italic: bool) -> &FontData
pub fn resolve(&self, family: &str, weight: u32, italic: bool) -> &FontData
Resolve a font key to its font data.
Sourcepub fn registry(&self) -> &FontRegistry
pub fn registry(&self) -> &FontRegistry
Access the underlying font registry.
Sourcepub fn registry_mut(&mut self) -> &mut FontRegistry
pub fn registry_mut(&mut self) -> &mut FontRegistry
Access the underlying font registry mutably.
Sourcepub fn font_data(
&self,
family: &str,
weight: u32,
italic: bool,
) -> Option<&[u8]>
pub fn font_data( &self, family: &str, weight: u32, italic: bool, ) -> Option<&[u8]>
Get the raw font data bytes for a custom font.
Returns None for standard fonts or if the font isn’t found.
Sourcepub fn baseline_metrics(
&self,
family: &str,
weight: u32,
italic: bool,
) -> (f64, f64)
pub fn baseline_metrics( &self, family: &str, weight: u32, italic: bool, ) -> (f64, f64)
Typographic ascent and descent for a font, as fractions of an em — the glyph block the CSS line box model centers inside a line (content area = (ascent + descent) * font_size; half-leading is what remains, split evenly; the baseline sits ascent below the content-area top). Custom fonts report their hhea values (already parsed into CustomFontMetrics, previously unused for baselines); standard fonts use the typographic metrics of their metric- compatible faces (Arial for Helvetica, Liberation Serif for Times, Liberation Mono for Courier), which is what browsers use when these families render. Descent is returned POSITIVE.