Skip to main content

OpenTypeFont

Struct OpenTypeFont 

Source
pub struct OpenTypeFont {
Show 16 fields pub units_per_em: u16, pub ascender: i16, pub descender: i16, pub line_gap: i16, pub typo_ascender: i16, pub typo_descender: i16, pub typo_line_gap: i16, pub x_height: Option<i16>, pub cap_height: Option<i16>, pub weight_class: u16, pub is_italic: bool, pub is_monospace: bool, pub num_glyphs: u16, pub number_of_h_metrics: u16, pub gsub_offset: Option<usize>, pub supported_features: Vec<[u8; 4]>, /* private fields */
}
Expand description

Parsed OpenType / TrueType font face.

Fields§

§units_per_em: u16§ascender: i16§descender: i16§line_gap: i16§typo_ascender: i16§typo_descender: i16§typo_line_gap: i16§x_height: Option<i16>§cap_height: Option<i16>§weight_class: u16§is_italic: bool§is_monospace: bool§num_glyphs: u16§number_of_h_metrics: u16§gsub_offset: Option<usize>§supported_features: Vec<[u8; 4]>

Implementations§

Source§

impl OpenTypeFont

Source

pub fn parse(bytes: &[u8]) -> Result<Self, OpenTypeParseError>

Parses an OpenType or TrueType font from memory.

Source

pub fn has_feature(&self, tag: &[u8; 4]) -> bool

Checks whether this font supports a specific OpenType feature tag (e.g. *b"liga", *b"calt", *b"dlig", *b"smcp").

Source

pub fn glyph_id(&self, c: char) -> u16

Resolves character to glyph ID via cmap subtable.

Source

pub fn glyph_advance_units(&self, gid: u16) -> u16

Retrieves glyph advance width in font design units from hmtx.

Source

pub fn glyph_advance_em(&self, gid: u16) -> f32

Advance width in ems (fraction of font size).

Source

pub fn glyph_advance(&self, gid: u16, font_size: f32) -> f32

Advance width in CSS pixels for a given font size.

Source

pub fn char_advance(&self, c: char, font_size: f32) -> f32

Computes advance width in CSS pixels for a character.

Source

pub fn pair_kerning_units(&self, left_gid: u16, right_gid: u16) -> i16

Retrieves pair kerning adjustment between two glyphs in font design units.

Source

pub fn pair_kerning_em(&self, left_gid: u16, right_gid: u16) -> f32

Pair kerning adjustment in ems.

Source

pub fn pair_kerning(&self, left_gid: u16, right_gid: u16, font_size: f32) -> f32

Pair kerning adjustment in CSS pixels for a given font size.

Source

pub fn font_metrics(&self, font_size: f32) -> FontMetrics

Generates exact FontMetrics scaled to CSS pixels.

Trait Implementations§

Source§

impl Clone for OpenTypeFont

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenTypeFont

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.