Skip to main content

Font

Struct Font 

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

Implementations§

Source§

impl Font

Source

pub fn data(&self) -> &[u8]

The raw file bytes — possibly a whole .ttc collection; pair every face view with Self::face_index.

Source

pub fn face_index(&self) -> u32

Which face of Self::data this font is.

Source

pub fn variation_coordinates(&self) -> &[([u8; 4], f32)]

User-space variation coordinates ((axis tag, value)); empty for the default instance and for static fonts.

Source

pub fn uid(&self) -> FontUid

The instance’s stable raster identity.

Source

pub fn family(&self) -> &str

Source

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

Source

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

Does this face answer to name? (its family or any alias — ASCII-case-insensitively, the CSS and platform-manager behavior)

Source

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

Register one more name for this face (no-op if already answered).

Source

pub fn attrs(&self) -> FontAttrs

Source

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

Ascent in px at size (positive, above the baseline).

Source

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

Descent in px at size (positive, below the baseline).

Source

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

Default line height in px at size.

Source

pub fn units_per_em(&self) -> f32

Source

pub fn ink_box_px(&self, size: f32) -> Option<(f32, f32, f32, f32)>

The font-wide ink box at size, y-UP around the glyph origin: (x_min, y_min, x_max, y_max). Any glyph’s ink fits inside — the cheap way to bound italic overhang and mark excursions per run.

Source

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

Source

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

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 (offset below baseline, thickness) in px at size, with conventional fallbacks when the font omits the post-table values.

Source

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

Strikeout (offset ABOVE baseline, thickness) in px at size.

Source§

impl Font

Source

pub fn from_bytes(bytes: Vec<u8>) -> Option<Font>

Parse a font file into a queryable object: family and weight/style come from the file’s own tables (Skia’s SkTypeface::MakeFromData shape — parse once, inspect, then FontCollection::add). Every localized family name becomes an alias (fontdb keeps them all — documents reference 优设标题黑 as readily as YouSheBiaoTiHei).

Source

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

Self::from_bytes for shared or memory-mapped bytes and for collection files: face_index picks the face inside a .ttc (0 for single-face files).

Source

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

Every face a file offers for registration: a static font is itself; a variable font is its NAMED INSTANCES (fvar), each a Font with the instance’s attrs and coordinates — nearest-variant matching then picks weights exactly like a static multi-weight family.

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.