Skip to main content

FontManager

Struct FontManager 

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

Manages font discovery, loading, shaping, and metrics.

Implementations§

Source§

impl FontManager

Source

pub fn new() -> Self

Create a new FontManager and load system fonts.

When the bundled-fonts feature is enabled, bundled fonts (Carlito, Caladea, Liberation) are loaded as fallbacks.

Source

pub fn load_additional_fonts(&mut self, font_files: &[FontFile])

Load additional font files (user-provided or extracted from DOCX).

These fonts are loaded AFTER system fonts, so they take the highest priority in font resolution (fontdb returns the last-loaded match).

Source

pub fn new_with_fonts(fonts: Vec<(String, Vec<u8>)>) -> Self

Create a FontManager with user-provided fonts (no system font loading).

Each entry is (family_name, font_bytes). This is useful in environments where system fonts are not available, such as WASM.

Source

pub fn resolve_font( &mut self, family: Option<&str>, bold: bool, italic: bool, ) -> Result<FontId>

Resolve a font by family name, bold, and italic flags. Returns a FontId. Uses fallback chain if the requested font is not found.

Source

pub fn metrics(&self, font_id: FontId, size_pt: f64) -> Result<FontMetrics>

Get font metrics at a given size in points.

Source

pub fn shape_text( &self, font_id: FontId, text: &str, size_pt: f64, ) -> Result<ShapedText>

Shape a text string using rustybuzz. Returns glyph IDs and advances.

Source

pub fn font_data(&self, font_id: FontId) -> Result<FontData>

Get font data for PDF embedding.

Source

pub fn all_font_data(&self) -> Vec<FontData>

Get all used font data.

Trait Implementations§

Source§

impl Default for FontManager

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, 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.