Skip to main content

Font

Struct Font 

Source
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

Source

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.

Source

pub fn face_index(&self) -> u32

face_index returns this face’s index within Self::data.

Source

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.

Source

pub fn uid(&self) -> FontUid

uid returns the process-unique identity of this font instance.

Source

pub fn family(&self) -> &str

family returns the font’s primary family name.

Source

pub fn aliases(&self) -> &[String]

aliases returns additional family names recognized for this font.

Source

pub fn matches(&self, name: &str) -> bool

matches reports whether name matches the family or an alias.

Matching is ASCII case-insensitive.

Source

pub fn add_alias(&mut self, name: &str)

add_alias registers another family name if it is not already recognized.

Source

pub fn attrs(&self) -> FontAttrs

attrs returns the face-selection attributes of this font.

Source

pub fn ascent_px(&self, size: f32) -> f32

ascent_px returns the positive distance above the baseline at size.

Source

pub fn descent_px(&self, size: f32) -> f32

descent_px returns the positive distance below the baseline at size.

Source

pub fn line_height_px(&self, size: f32) -> f32

line_height_px returns the font’s default line height at size.

Source

pub fn units_per_em(&self) -> f32

units_per_em returns the font’s design-space units per em.

Source

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.

Source

pub fn covers(&self, ch: char) -> bool

covers reports whether the font maps a character to a glyph.

Source

pub fn glyph_for(&self, ch: char) -> Option<u32>

glyph_for returns the glyph identifier mapped from a character.

Examples found in repository?
examples/raster_bench.rs (line 62)
60fn glyphs(fonts: &FaceSet, id: FontId, text: &str) -> Vec<u32> {
61    let font = fonts.get(id);
62    text.chars().filter_map(|ch| font.glyph_for(ch)).collect()
63}
Source

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.

Source

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

Source

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.

Source

pub fn from_data(data: FontData, face_index: u32) -> Option<Font>

from_data parses one face from shared font-file storage.

Use face index zero for a single-face file. It returns None when the index or font data is invalid.

Source

pub fn instances_from_data(data: FontData, face_index: u32) -> Vec<Font>

instances_from_data parses the registrable instances of one face.

Static fonts produce one item. Variable fonts with named instances produce one Font per instance. Invalid data returns an empty vector.

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 !RefUnwindSafe for Font

§

impl !UnwindSafe for Font

§

impl Freeze for Font

§

impl Send for Font

§

impl Sync for Font

§

impl Unpin for Font

§

impl UnsafeUnpin 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.