pub struct Font { /* private fields */ }Expand description
A loaded font, ready for shaping and rasterization.
Constructed from raw TTF/OTF bytes via Font::from_bytes. The data is
reference-counted so fonts can be cheaply shared and saved across frames.
An optional fallback font can be chained via Font::with_fallback; when
a glyph is missing from the primary font (glyph_id == 0 after shaping),
the fallback is consulted for both the glyph outline and advance width.
Implementations§
Source§impl Font
impl Font
Sourcepub fn from_bytes(data: Vec<u8>) -> Result<Self, &'static str>
pub fn from_bytes(data: Vec<u8>) -> Result<Self, &'static str>
Parse a font from raw TTF/OTF bytes.
Returns Err if the data is not a valid font.
Sourcepub fn from_slice(data: &[u8]) -> Result<Self, &'static str>
pub fn from_slice(data: &[u8]) -> Result<Self, &'static str>
Parse a font from a borrowed byte slice (data is copied).
Sourcepub fn with_fallback(self, fallback: Arc<Font>) -> Self
pub fn with_fallback(self, fallback: Arc<Font>) -> Self
Chain a fallback font consulted when this font lacks a glyph.
Returns self so it can be used as a builder method:
let font = Font::from_slice(MAIN_BYTES)?.with_fallback(Arc::new(emoji_font));pub fn units_per_em(&self) -> u16
Sourcepub fn ascender_px(&self, size: f64) -> f64
pub fn ascender_px(&self, size: f64) -> f64
Ascender height in pixels at the given font size.
Sourcepub fn descender_px(&self, size: f64) -> f64
pub fn descender_px(&self, size: f64) -> f64
Descender depth in pixels at the given font size (positive value).
Sourcepub fn line_height_px(&self, size: f64) -> f64
pub fn line_height_px(&self, size: f64) -> f64
Recommended line height in pixels at the given font size.