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(crate) fn new( font: &'a Font, global: &'a Metrics, coords: &'a [F2Dot14], ) -> Self

Creates metrics for font at the location in coords.

Source

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

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) -> Self

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(crate) fn with_bitmap_ppem(self, ppem: Option<f32>) -> Self

Measures bitmaps using the strike for ppem.

This selects the smallest strike that is at least ppem, or the largest strike if none is that large. None (the default) or a size that is not positive selects the largest strike. A glyph missing from that strike is measured by the next source in the order, even if another strike contains it. No other metric depends on the size.

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: 'o>( &self, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

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: 'o>( &self, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

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: 'o>( &self, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

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: 'o>( &self, convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

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.

Source

fn only_base_source(&self) -> Option<ExtentsSource<'a>>

Returns the base outline source, where it is the only source in the order that the font has.

This needs no list of sources: the font’s answers about its bitmap, color and composite tables are kept, and the base is chosen as OutlineGlyphs chooses it.

Source

fn extents_batched_one<'o, V: 'o>( &self, source: ExtentsSource<'_>, convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

Measures every glyph from the one source that answers for them all.

Source

fn stated_glyf_extents( &self, glyf: &Glyf<'_>, loca: &Loca<'_>, glyph: GlyphId, ) -> Option<GlyphExtents<F48Dot16>>

Returns the bounding box in a glyf glyph’s header, with its bearing from hmtx.

The glyph is not loaded. The header contains the box at the default location, so this is used only at that location.

Source

fn cff_extents( &self, cff: &CffFontRef<'_>, source: OutlineSource, glyph: GlyphId, ) -> Option<GlyphExtents<F48Dot16>>

Returns the bounding box of a charstring.

Source

fn type1_extents( &self, font: Type1Instance<'_>, glyph: GlyphId, ) -> Option<GlyphExtents<F48Dot16>>

Returns the bounding box of a Type 1 charstring.

Source

fn extents_from_source( &self, source: &ExtentsSource<'_>, glyph: GlyphId, ) -> Option<GlyphExtents<F48Dot16>>

Returns the box that source measures for glyph, or None if the source does not contain the glyph.

Source

fn extents_batched_mixed<'o, V: 'o>( &self, sources: &ExtentsSources<'_>, convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

Runs extents_batched over more than one source.

Marked #[inline(never)] because fonts with bitmaps or color are uncommon, and the loop over outlines alone should not include this code.

Source

pub(crate) fn line_extents(&self) -> Option<LineExtents<F48Dot16>>

Returns the line this font’s glyphs stack by, where it provides one.

Source

pub(crate) fn v_origin_y_batched_with<'o, V: 'o, I>( &self, convert: impl FnMut(GlyphId, Option<F48Dot16>) -> V, fallback: impl FnOnce(I), glyphs: I, )
where I: Iterator<Item = (GlyphId, &'o mut V)>,

Selects the source of vertical origins once for the whole run.

fallback receives the whole run when neither table answers. A malformed glyf glyph can still reach convert with None.

Source

pub(crate) fn states_vertical_advances(&self) -> bool

Returns true where the font provides vertical metrics of its own.

One that does not stacks its glyphs by the line, which is the only part of a vertical advance a caller can supply.

Source

pub(crate) fn origin_line(&self) -> LineExtents<F48Dot16>

Source

fn origin_against_ink( &self, glyph: GlyphId, line: LineExtents<F48Dot16>, ) -> F48Dot16

Source

fn origin_from_extents( extents: Option<GlyphExtents<F48Dot16>>, line: LineExtents<F48Dot16>, ) -> F48Dot16

Source

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

The varied half of extents_batched.

A location moves the points, and the box a glyph states is the one it has at the default location, so the answer comes from loading the outline. Floating-point deltas are kept until the four bounds are measured; the scale decides how to round them. #[inline(never)] because that pulls in the loader, whose size no unvaried measurement should pay for.

Source

fn extents_batched_cff<'o, V: 'o>( &self, cff: &CffFontRef<'_>, source: OutlineSource, convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

The charstring half of extents_batched.

A charstring states no box, so reading one means running it. #[inline(never)] for the same reason as the varied arm.

Source

fn extents_batched_type1<'o, V: 'o>( &self, font: Type1Instance<'_>, convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

The Type 1 half of extents_batched.

#[inline(never)] for the same reason as h_advance_batched_type1.

Source

fn line_height(&self) -> F48Dot16

The height a glyph advances where the font has no vmtx.

The extent of the line, without the gap after it, as HarfBuzz and FreeType both take it. A font that states no line at all measures one em.

Source

fn v_advance_batched_varied<'o, V: 'o>( &self, raw: &GlyphMetricRecords<'_>, coords: &[F2Dot14], convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

The varied half of v_advance_batched.

#[inline(never)] for the same reason as the horizontal one.

Source

fn h_advance_batched_varied<'o, V: 'o>( &self, raw: &GlyphMetricRecords<'_>, coords: &[F2Dot14], convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

The varied half of h_advance_batched.

#[inline(never)] because reading gvar pulls in a large amount of code, whose size would otherwise be charged to every unvaried measurement.

Source

fn h_advance_batched_standalone_cff<'o, V: 'o>( &self, cff: &CffFontRef<'_>, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

Reads widths from standalone CFF charstrings.

Source

fn h_advance_batched_type1<'o, V: 'o>( &self, font: Type1Instance<'_>, convert: impl Fn(F48Dot16) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )

The Type 1 half of h_advance_batched.

A Type 1 charstring states its own width, so reading one means running it. #[inline(never)] because that has nothing in common with reading a table, and no sfnt should pay for its presence.

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.