pub struct Font { /* private fields */ }Expand description
Font is one parsed font face or named variable-font instance.
It retains immutable source bytes and exposes the names, attributes, coverage, and metrics needed for shaping and rendering.
Implementations§
Source§impl Font
impl Font
Sourcepub fn data(&self) -> &[u8] ⓘ
pub fn data(&self) -> &[u8] ⓘ
data returns the source font-file bytes.
For a font collection file, use Self::face_index to select this face.
Sourcepub fn face_index(&self) -> u32
pub fn face_index(&self) -> u32
face_index returns this face’s index within Self::data.
Sourcepub fn variation_coordinates(&self) -> &[([u8; 4], f32)]
pub fn variation_coordinates(&self) -> &[([u8; 4], f32)]
variation_coordinates returns user-space axis tags and values.
It is empty for static fonts and default variable-font instances.
Sourcepub fn aliases(&self) -> &[String]
pub fn aliases(&self) -> &[String]
aliases returns additional family names recognized for this font.
Sourcepub fn matches(&self, name: &str) -> bool
pub fn matches(&self, name: &str) -> bool
matches reports whether name matches the family or an alias.
Matching is ASCII case-insensitive.
Sourcepub fn add_alias(&mut self, name: &str)
pub fn add_alias(&mut self, name: &str)
add_alias registers another family name if it is not already recognized.
Sourcepub fn ascent_px(&self, size: f32) -> f32
pub fn ascent_px(&self, size: f32) -> f32
ascent_px returns the positive distance above the baseline at size.
Sourcepub fn descent_px(&self, size: f32) -> f32
pub fn descent_px(&self, size: f32) -> f32
descent_px returns the positive distance below the baseline at size.
Sourcepub fn line_height_px(&self, size: f32) -> f32
pub fn line_height_px(&self, size: f32) -> f32
line_height_px returns the font’s default line height at size.
Sourcepub fn units_per_em(&self) -> f32
pub fn units_per_em(&self) -> f32
units_per_em returns the font’s design-space units per em.
Sourcepub fn ink_box_px(&self, size: f32) -> Option<(f32, f32, f32, f32)>
pub fn ink_box_px(&self, size: f32) -> Option<(f32, f32, f32, f32)>
ink_box_px returns the font-wide ink bounds at size.
The tuple is (x_min, y_min, x_max, y_max) in y-up coordinates around
the glyph origin. It returns None when the font provides no bounds.
Sourcepub fn covers(&self, ch: char) -> bool
pub fn covers(&self, ch: char) -> bool
covers reports whether the font maps a character to a glyph.
Sourcepub fn glyph_for(&self, ch: char) -> Option<u32>
pub fn glyph_for(&self, ch: char) -> Option<u32>
glyph_for returns the glyph identifier mapped from a character.
Sourcepub fn underline_px(&self, size: f32) -> (f32, f32)
pub fn underline_px(&self, size: f32) -> (f32, f32)
underline_px returns underline offset and thickness at size.
The offset is positive below the baseline. Conventional values are used when the font omits underline metrics.
Sourcepub fn strikeout_px(&self, size: f32) -> (f32, f32)
pub fn strikeout_px(&self, size: f32) -> (f32, f32)
strikeout_px returns strikeout offset and thickness at size.
The offset is positive above the baseline. Conventional values are used when the font omits strikeout metrics.
Source§impl Font
impl Font
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Option<Font>
pub fn from_bytes(bytes: Vec<u8>) -> Option<Font>
from_bytes parses face zero from owned font-file bytes.
Family names and attributes come from the font. Localized family names
become aliases. It returns None when the bytes cannot be parsed.