Skip to main content

FontContext

Struct FontContext 

Source
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

Source

pub fn new() -> Self

Source

pub fn sentinel_digit_count(&self) -> u32

Get the current sentinel digit count.

Source

pub fn set_sentinel_digit_count(&mut self, count: u32)

Set the number of digits used to measure page number sentinel width.

Source

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.

Source

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.

Source

pub fn resolve(&self, family: &str, weight: u32, italic: bool) -> &FontData

Resolve a font key to its font data.

Source

pub fn registry(&self) -> &FontRegistry

Access the underlying font registry.

Source

pub fn registry_mut(&mut self) -> &mut FontRegistry

Access the underlying font registry mutably.

Source

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.

Source

pub fn units_per_em(&self, family: &str, weight: u32, italic: bool) -> u16

Get the units-per-em for a font. Returns 1000 for standard fonts.

Trait Implementations§

Source§

impl Default for FontContext

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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