pub struct Font { /* private fields */ }Expand description
A parsed font
Implementations§
Source§impl Font
impl Font
Sourcepub fn default_ref() -> &'static Self
pub fn default_ref() -> &'static Self
Returns a static reference to the default font
This is equivalent to calling Default::default but returns a reference and avoids
cloning any internal data
Sourcepub fn from_ttf(data: Vec<u8>) -> Result<Self>
pub fn from_ttf(data: Vec<u8>) -> Result<Self>
Parse a font from TrueType or OpenType format font data
§Errors
If there is an error parsing the font data
Sourcepub fn family(&self) -> &String
pub fn family(&self) -> &String
The font family name
Returns "unknown" if the font does not specify a family name
Sourcepub fn name(&self) -> &String
pub fn name(&self) -> &String
The font’s full name
Returns "unknown" if the font does not specify a full name
Sourcepub fn cap_height(&self) -> f64
pub fn cap_height(&self) -> f64
The capital height in font units
Measures the height of the uppercase 'M' if it is not set. In case the font does not contain
an uppercase 'M', a default value is returned
Sourcepub fn x_height(&self) -> f64
pub fn x_height(&self) -> f64
The x-height in font units
Measures the height of the lowercase 'x' if it is not set. In case the font does not contain
a lowercase 'x', a default value is returned
Sourcepub fn line_height(&self) -> f64
pub fn line_height(&self) -> f64
The font’s line height in font units
This is equal to self.ascender() + self.descender() + self.line_gap()
Sourcepub fn num_glyphs(&self) -> usize
pub fn num_glyphs(&self) -> usize
The number of glyph outlines in the font
Sourcepub fn glyph(&self, char: char) -> Option<Glyph>
pub fn glyph(&self, char: char) -> Option<Glyph>
Returns the flyph for a given character if present in the font
Sourcepub fn glyph_or_default(&self, char: char) -> Glyph
pub fn glyph_or_default(&self, char: char) -> Glyph
Returns the glyph for a given character, or the default replacement character if not present