Skip to main content

Metrics

Struct Metrics 

Source
pub struct Metrics {
Show 14 fields pub units_per_em: u16, pub raw_units_per_em: u16, pub num_glyphs: u32, pub bounds: BoundingBox<F48Dot16>, pub hhea_line: Option<LineBox>, pub max_h_advance: Option<F48Dot16>, pub vhea_line: Option<LineBox>, pub max_v_advance: Option<F48Dot16>, pub typo_line: Option<LineBox>, pub use_typo_metrics: bool, pub win_line: Option<LineExtents<F48Dot16>>, pub x_height: Option<F48Dot16>, pub cap_height: Option<F48Dot16>, pub average_char_width: Option<F48Dot16>,
}
Expand description

Font-wide metrics.

Read from head, maxp, hhea, vhea and OS/2, which together are a few hundred bytes.

A font has three sets of line metrics, and they often differ. hhea_line is what macOS reads, win_line is what Windows reads, and typo_line is what the font asks for when use_typo_metrics is set. Choosing between them is left to the caller.

A field missing from the font is None, which is distinct from a zero value.

MVAR varies most of these, so a set belongs to the location it was read at. The units per em, the counts, the bounding box, the widest and tallest advance and the average width cannot vary.

§Units

Measurements are in font units. They are F48Dot16 because a location can move them off a whole unit, and rounding here would decide for every caller how that fraction is spent.

The two axes do not scale alike: vhea_line is measured across the vertical baseline rather than along it, so it scales on x where the horizontal sets scale on y.

Fields§

§units_per_em: u16

Design units per em, which every measurement of the font uses.

Always between 16 and 16384. A font with a value outside that range, or with no head, uses 1000.

§raw_units_per_em: u16

Design units per em as written in head, or zero if the font has no head.

Differs from units_per_em only for a font with an unusable value, which a caller may choose to reject.

§num_glyphs: u32

Number of glyphs in the font.

§bounds: BoundingBox<F48Dot16>

Box enclosing every glyph in the font.

§hhea_line: Option<LineBox>

Line metrics from hhea.

§max_h_advance: Option<F48Dot16>

Widest advance of any glyph.

§vhea_line: Option<LineBox>

Line metrics from vhea, measured across the vertical baseline.

§max_v_advance: Option<F48Dot16>

Tallest advance of any glyph.

§typo_line: Option<LineBox>

Typographic line metrics, from OS/2.

§use_typo_metrics: bool

Whether the font asks for typo_line to be used in preference to hhea_line.

§win_line: Option<LineExtents<F48Dot16>>

The line outside which the font asks not to be clipped.

OS/2 gives the descent as a positive number below the baseline. This negates it, so the pair describes a line like every other pair here.

§x_height: Option<F48Dot16>

Height of a lowercase x.

§cap_height: Option<F48Dot16>

Height of a capital letter.

§average_char_width: Option<F48Dot16>

Average glyph width, as the font reports it.

Implementations§

Source§

impl Metrics

Source

pub fn from_sfnt<'a>( tables: &impl TableProvider<'a>, normalized_coords: &[F2Dot14], ) -> Metrics

Reads the metrics from tables at normalized_coords.

A missing or unreadable table leaves the metrics that come from it unset rather than failing.

Pass an empty location for the font’s defaults. At any other location MVAR is read and its deltas applied.

Source

pub fn h_line(&self) -> Option<LineBox>

Returns the ascender, descender and gap for horizontal text.

The line is the first of these that applies:

  1. The typographic line, if OS/2 sets USE_TYPO_METRICS.
  2. The hhea line, if either end is nonzero.
  3. The typographic line, if either end is nonzero.
  4. The OS/2 clipping line, with no gap.

Returns None if the font has no line metrics.

Source

pub fn from_type1(font: &Type1Font) -> Metrics

Reads the metrics from a Type 1 font.

Such a font has only a bounding box, a glyph count and a matrix. The ascender and descender are the top and bottom of that box. Everything else is unset.

Source

pub fn from_cff(font: &CffFontRef<'_>) -> Metrics

Reads the metrics from a standalone CFF font.

Source§

impl Metrics

Source

pub fn scaled<S>(&self, scale: S) -> ScaledMetrics<'_, S>
where S: Scale,

Returns these metrics in the units scale describes.

Source

pub fn scaled_f32(&self, ppem: f32) -> ScaledMetrics<'_, ScaleF32>

Returns these metrics in pixels at ppem, as f32.

Source

pub fn scaled_26dot6(&self, ppem: f32) -> ScaledMetrics<'_, Scale26Dot6>

Returns these metrics in pixels at ppem, in 26.6 fixed point.

Trait Implementations§

Source§

impl Clone for Metrics

Source§

fn clone(&self) -> Metrics

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 Copy for Metrics

Source§

impl Debug for Metrics

Source§

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

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

impl Default for Metrics

Source§

fn default() -> Metrics

Returns the “default value” for a type. Read more
Source§

impl Eq for Metrics

Source§

impl PartialEq for Metrics

Source§

fn eq(&self, other: &Metrics) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Metrics

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> ErasedDestructor for T
where T: 'static,

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.