pub struct FontManager { /* private fields */ }Expand description
Manages font discovery, loading, shaping, and metrics.
Implementations§
Source§impl FontManager
impl FontManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new FontManager and load system fonts.
Bundled fonts (Carlito, Caladea, Liberation) are loaded as fallbacks.
System fonts are discovered when the system-fonts feature is enabled.
Sourcepub fn new_deterministic() -> Result<Self>
pub fn new_deterministic() -> Result<Self>
Create a font manager that loads bundled fonts without discovering system fonts.
This mode makes font resolution reproducible across machines.
Sourcepub fn load_additional_fonts(&mut self, font_files: &[FontFile])
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).
Sourcepub fn new_with_fonts(fonts: Vec<(String, Vec<u8>)>) -> Self
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.
Sourcepub fn resolve_font_for_text(
&mut self,
family: Option<&str>,
bold: bool,
italic: bool,
text: &str,
) -> Result<FontId>
pub fn resolve_font_for_text( &mut self, family: Option<&str>, bold: bool, italic: bool, text: &str, ) -> Result<FontId>
Resolve a font for text, falling back on glyph coverage.
resolve_font picks by family name alone. That is enough for Latin
text, but a run asking for a Chinese family on a machine without it
falls down the name chain and lands on a Latin font, which has no CJK
glyphs, so every character renders as a missing-glyph box. Name
matching cannot detect that, because the font it chose exists and is
perfectly valid, it simply cannot draw this text.
So the resolved font is checked against the text, and when a character is missing another font that can draw it is looked for.
This is per run rather than per character: the font that covers the first missing character is used for the whole run. Text that mixes scripts inside one run is therefore still imperfect, but it is a large improvement on drawing boxes.
Sourcepub fn resolve_font(
&mut self,
family: Option<&str>,
bold: bool,
italic: bool,
) -> Result<FontId>
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.
Sourcepub fn metrics(&self, font_id: FontId, size_pt: f64) -> Result<FontMetrics>
pub fn metrics(&self, font_id: FontId, size_pt: f64) -> Result<FontMetrics>
Get font metrics at a given size in points.
Sourcepub fn shape_text(
&self,
font_id: FontId,
text: &str,
size_pt: f64,
) -> Result<ShapedText>
pub fn shape_text( &self, font_id: FontId, text: &str, size_pt: f64, ) -> Result<ShapedText>
Shape a text string using HarfRust. Returns glyph IDs and advances.
Sourcepub fn all_font_data(&self) -> Vec<FontData>
pub fn all_font_data(&self) -> Vec<FontData>
Get all used font data.