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]) -> bool
pub fn load_additional_fonts(&mut self, font_files: &[FontFile]) -> bool
Load or replace additional font files (user-provided or extracted from an OOXML package).
An unchanged set is a no-op so a reusable engine retains resolution and shaping state. A changed set rebuilds from the isolated base database, which prevents stale face ids and bounds repeated document edits.
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 set_caller_aliases(&mut self, aliases: &[(String, String)]) -> bool
pub fn set_caller_aliases(&mut self, aliases: &[(String, String)]) -> bool
Replace byte-free caller aliases from requested family to loaded family.
An unchanged slice is a no-op. A changed slice invalidates only name
resolution and coverage state. Loaded faces and shaping entries remain
valid because their FontId values do not change.
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 shape_multilingual_text(
&mut self,
segment: TextSegment,
language: Option<&str>,
base_direction: TextDirection,
no_wrap: bool,
) -> Result<Vec<MultilingualTextSegment>>
pub fn shape_multilingual_text( &mut self, segment: TextSegment, language: Option<&str>, base_direction: TextDirection, no_wrap: bool, ) -> Result<Vec<MultilingualTextSegment>>
Shape one logical text segment into script, font, and bidi-level spans.
The returned spans are in logical order. The rich line breaker applies UAX 9 visual order only after it knows the final line boundaries.
Sourcepub fn shape_multilingual_paragraph(
&mut self,
segments: Vec<(TextSegment, Option<String>)>,
base_direction: TextDirection,
no_wrap: bool,
) -> Result<Vec<MultilingualTextSegment>>
pub fn shape_multilingual_paragraph( &mut self, segments: Vec<(TextSegment, Option<String>)>, base_direction: TextDirection, no_wrap: bool, ) -> Result<Vec<MultilingualTextSegment>>
Shape styled spans with one paragraph-wide bidi resolution.
Sourcepub fn all_font_data(&self) -> Vec<FontData>
pub fn all_font_data(&self) -> Vec<FontData>
Get all used font data.