Skip to main content

Font

Struct Font 

Source
pub struct Font { /* private fields */ }
Expand description

A loaded, shapeable font face.

Implementations§

Source§

impl Font

Source

pub fn from_bytes(bytes: Vec<u8>) -> Result<Self, FontError>

Load a font from sfnt bytes (TrueType, OpenType/CFF, or TrueType Collection — the first face of a collection is used).

Source

pub fn system_default() -> Option<Self>

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.

Source

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.

Source

pub fn line_height(&self, size_px: f64) -> f64

Full line height (ascent + descent + line gap) at size_px.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Font

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Font

§

impl RefUnwindSafe for Font

§

impl Send for Font

§

impl Sync for Font

§

impl Unpin for Font

§

impl UnsafeUnpin for Font

§

impl UnwindSafe for Font

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.