Font

Struct Font 

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

A parsed font

Implementations§

Source§

impl Font

Source

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

Source

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

Source

pub fn family(&self) -> &String

The font family name

Returns "unknown" if the font does not specify a family name

Source

pub fn name(&self) -> &String

The font’s full name

Returns "unknown" if the font does not specify a full name

Source

pub fn em_size(&self) -> f64

The number font units per EM

Source

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

Source

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

Source

pub fn ascender(&self) -> f64

The font’s ascender in font units

Source

pub fn descender(&self) -> f64

The font’s descender in font units

Source

pub fn line_gap(&self) -> f64

The font’s line gap in font units

Source

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()

Source

pub fn slope(&self) -> Option<f64>

The font’s slope angle in clockwise degrees if specified

Source

pub fn num_glyphs(&self) -> usize

The number of glyph outlines in the font

Source

pub fn glyph(&self, char: char) -> Option<Glyph>

Returns the flyph for a given character if present in the font

Source

pub fn glyph_or_default(&self, char: char) -> Glyph

Returns the glyph for a given character, or the default replacement character if not present

Source

pub fn notdef(&self) -> Glyph

Returns the font’s default replacement glyph, .notdef, or a builtin default if not present

Source

pub fn kerning(&self, left: char, right: char) -> f64

Returns the kerning between two characters’ glyphs, or 0 if no kerning is specified in the font

Trait Implementations§

Source§

impl Clone for Font

Source§

fn clone(&self) -> Font

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Font

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Font

Source§

fn default() -> Self

Returns the “default value” for a type. 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 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.