Skip to main content

GlyphMetrics

Struct GlyphMetrics 

Source
pub struct GlyphMetrics<'a> {
    h_metrics: &'a GlyphMetricRecords<'a>,
    font: &'a Font,
    global: &'a Metrics,
    coords: &'a [F2Dot14],
    num_glyphs: u32,
    units_per_em: u16,
    order: GlyphSourceOrder,
    bitmap_ppem: Option<f32>,
}
Expand description

Measurements of individual glyphs at one location.

Cheap to obtain, so it can be taken per query rather than held.

Fields§

§h_metrics: &'a GlyphMetricRecords<'a>§font: &'a Font§global: &'a Metrics§coords: &'a [F2Dot14]§num_glyphs: u32§units_per_em: u16§order: GlyphSourceOrder§bitmap_ppem: Option<f32>

Implementations§

Source§

impl<'a> GlyphMetrics<'a>

Source

pub fn scaled<S>(self, scale: S) -> ScaledGlyphMetrics<'a, 'static, S>
where S: Scale,

Returns these metrics in the units scale describes.

Source

pub fn scaled_f32(self, ppem: f32) -> ScaledGlyphMetrics<'a, 'static, ScaleF32>

Returns these metrics in pixels at ppem, as f32.

Source

pub fn scaled_26dot6( self, ppem: f32, ) -> ScaledGlyphMetrics<'a, 'static, Scale26Dot6>

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

Source

pub fn with_extents_source_order( self, order: GlyphSourceOrder, ) -> GlyphMetrics<'a>

Measures ink using the sources in order.

Each source in the font is tried in turn until one provides extents for the glyph. GlyphSourceOrder::DEFAULT tries bitmaps, then color, then outlines.

Source

pub fn extents_source_order(&self) -> GlyphSourceOrder

Returns the order used to measure ink.

Source

pub fn h_advance(&self, glyph: GlyphId) -> f32

Returns the advance width of glyph, in font units.

See h_advance_exact for the width before it is narrowed to f32.

Source

pub fn h_advance_exact(&self, glyph: GlyphId) -> F48Dot16

Returns the exact advance width of glyph, in font units.

hmtx contains whole units and variations can add a fraction, so the result may not be a whole number. A varied advance below zero is clamped to zero before scaling. The caller decides how to round it.

Source

pub fn h_advance_batched<'o, V>( &self, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
where V: 'o,

Writes the advance width of each glyph to its slot, in order.

Each width passes through convert, so a caller working in another number type writes into that type directly.

Source

pub fn v_advance(&self, glyph: GlyphId) -> f32

Returns the advance height of glyph, in font units.

See v_advance_exact for the height before it is narrowed to f32.

Source

pub fn v_advance_exact(&self, glyph: GlyphId) -> F48Dot16

Returns the exact advance height of glyph, in font units.

The height is non-negative, as stored in the font. A varied advance below zero is clamped to zero before scaling. A caller whose y axis points down must negate it.

Source

pub fn v_advance_batched<'o, V>( &self, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
where V: 'o,

Writes the advance height of each glyph to its slot, in order.

Each height passes through convert, so a caller working in another number type writes into that type directly.

Source

pub fn v_origin_y(&self, glyph: GlyphId) -> f32

Returns the y coordinate of glyph’s vertical origin, in font units.

The x coordinate is half its advance width. See v_origin_y_exact for the value before it is narrowed to f32.

Source

pub fn v_origin_y_exact(&self, glyph: GlyphId) -> F48Dot16

Returns the exact y coordinate of glyph’s vertical origin.

Source

pub fn v_origin_y_batched<'o, V>( &self, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
where V: 'o,

Writes the vertical origin of each glyph in font units to its slot.

VORG answers first, followed by the glyf top phantom point. Other glyphs are centered in the horizontal line by their extents, or placed on the ascender when extents are unavailable.

Source

pub fn extents(&self, glyph: GlyphId) -> Option<GlyphExtents<f32>>

Returns where glyph’s ink sits, in font units.

An empty glyph has zero extents. None means the glyph is unavailable or its extents could not be read. A bitmap is measured from the font’s largest strike; scaled metrics use the strike for the scale’s size.

See extents_exact for the values before they are narrowed to f32.

Source

pub fn extents_exact(&self, glyph: GlyphId) -> Option<GlyphExtents<F48Dot16>>

Returns the exact extents of glyph in font units.

See extents_batched to compute several glyphs’ extents with one choice of source for the batch.

Source

pub fn extents_batched<'o, V>( &self, convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
where V: 'o,

Writes where each glyph’s ink sits to its slot, in order.

Each measurement passes through convert, so a caller working in another number type writes into that type directly.

The sources are resolved once for the batch, because the available tables depend on the font rather than on the glyph. Each glyph then tries them in order until one provides extents.

Trait Implementations§

Source§

impl<'a> Clone for GlyphMetrics<'a>

Source§

fn clone(&self) -> GlyphMetrics<'a>

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<'a> Copy for GlyphMetrics<'a>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for GlyphMetrics<'a>

§

impl<'a> !UnwindSafe for GlyphMetrics<'a>

§

impl<'a> Freeze for GlyphMetrics<'a>

§

impl<'a> Send for GlyphMetrics<'a>

§

impl<'a> Sync for GlyphMetrics<'a>

§

impl<'a> Unpin for GlyphMetrics<'a>

§

impl<'a> UnsafeUnpin for GlyphMetrics<'a>

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.