pub struct Font { /* private fields */ }Expand description
A loaded, shapeable font face.
Implementations§
Source§impl Font
impl Font
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Result<Font, FontError>
pub fn from_bytes(bytes: Vec<u8>) -> Result<Font, FontError>
Load a font from sfnt bytes (TrueType, OpenType/CFF, or TrueType
Collection — the first face of a collection is used).
Sourcepub fn system_default() -> Option<Font>
pub fn system_default() -> Option<Font>
Probe common operating-system font directories and load the first
usable sans-serif face. Returns None if none is found.
Intended for examples and tests; shipping apps should bundle or
explicitly locate their fonts and use Font::from_bytes.
Sourcepub fn ascent(&self, size_px: f64) -> f64
pub fn ascent(&self, size_px: f64) -> f64
Distance from the top of the text box to the baseline, in logical
pixels, at size_px.
Sourcepub fn line_height(&self, size_px: f64) -> f64
pub fn line_height(&self, size_px: f64) -> f64
Full line height (ascent + descent + line gap) at size_px.
Sourcepub fn measure(&self, text: &str, size_px: f64) -> Size
pub fn measure(&self, text: &str, size_px: f64) -> Size
Measure the rendered size of text at size_px: the widest line’s
advance width × the number of newline-separated lines times line height.
A trailing newline counts as an extra (empty) line.
Sourcepub fn wrap(&self, text: &str, size_px: f64, max_width: f64) -> Vec<String>
pub fn wrap(&self, text: &str, size_px: f64, max_width: f64) -> Vec<String>
Greedily wrap text to lines no wider than max_width logical pixels at
size_px, breaking at spaces. Existing \n are hard breaks. A single
word wider than max_width is kept on its own (over-long) line rather
than split mid-word. Returns at least one line.