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>
impl<'a> GlyphMetrics<'a>
Sourcepub(crate) fn new(
font: &'a Font,
global: &'a Metrics,
coords: &'a [F2Dot14],
) -> Self
pub(crate) fn new( font: &'a Font, global: &'a Metrics, coords: &'a [F2Dot14], ) -> Self
Creates metrics for font at the location in coords.
Sourcepub fn scaled<S: Scale>(self, scale: S) -> ScaledGlyphMetrics<'a, 'static, S>
pub fn scaled<S: Scale>(self, scale: S) -> ScaledGlyphMetrics<'a, 'static, S>
Returns these metrics in the units scale describes.
Sourcepub fn scaled_f32(self, ppem: f32) -> ScaledGlyphMetrics<'a, 'static, ScaleF32>
pub fn scaled_f32(self, ppem: f32) -> ScaledGlyphMetrics<'a, 'static, ScaleF32>
Returns these metrics in pixels at ppem, as f32.
Sourcepub fn scaled_26dot6(
self,
ppem: f32,
) -> ScaledGlyphMetrics<'a, 'static, Scale26Dot6>
pub fn scaled_26dot6( self, ppem: f32, ) -> ScaledGlyphMetrics<'a, 'static, Scale26Dot6>
Returns these metrics in pixels at ppem, in 26.6 fixed point.
Sourcepub fn with_extents_source_order(self, order: GlyphSourceOrder) -> Self
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.
Sourcepub(crate) fn with_bitmap_ppem(self, ppem: Option<f32>) -> Self
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.
Sourcepub fn extents_source_order(&self) -> GlyphSourceOrder
pub fn extents_source_order(&self) -> GlyphSourceOrder
Returns the order used to measure ink.
Sourcepub fn h_advance(&self, glyph: GlyphId) -> f32
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.
Sourcepub fn h_advance_exact(&self, glyph: GlyphId) -> F48Dot16
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.
Sourcepub fn h_advance_batched<'o, V: 'o>(
&self,
convert: impl Fn(F48Dot16) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcepub fn v_advance(&self, glyph: GlyphId) -> f32
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.
Sourcepub fn v_advance_exact(&self, glyph: GlyphId) -> F48Dot16
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.
Sourcepub fn v_advance_batched<'o, V: 'o>(
&self,
convert: impl Fn(F48Dot16) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcepub fn v_origin_y(&self, glyph: GlyphId) -> f32
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.
Sourcepub fn v_origin_y_exact(&self, glyph: GlyphId) -> F48Dot16
pub fn v_origin_y_exact(&self, glyph: GlyphId) -> F48Dot16
Returns the exact y coordinate of glyph’s vertical origin.
Sourcepub fn v_origin_y_batched<'o, V: 'o>(
&self,
convert: impl Fn(F48Dot16) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcepub fn extents(&self, glyph: GlyphId) -> Option<GlyphExtents<f32>>
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.
Sourcepub fn extents_exact(&self, glyph: GlyphId) -> Option<GlyphExtents<F48Dot16>>
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.
Sourcepub fn extents_batched<'o, V: 'o>(
&self,
convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcefn only_base_source(&self) -> Option<ExtentsSource<'a>>
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.
Sourcefn extents_batched_one<'o, V: 'o>(
&self,
source: ExtentsSource<'_>,
convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcefn stated_glyf_extents(
&self,
glyf: &Glyf<'_>,
loca: &Loca<'_>,
glyph: GlyphId,
) -> Option<GlyphExtents<F48Dot16>>
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.
Sourcefn cff_extents(
&self,
cff: &CffFontRef<'_>,
source: OutlineSource,
glyph: GlyphId,
) -> Option<GlyphExtents<F48Dot16>>
fn cff_extents( &self, cff: &CffFontRef<'_>, source: OutlineSource, glyph: GlyphId, ) -> Option<GlyphExtents<F48Dot16>>
Returns the bounding box of a charstring.
Sourcefn type1_extents(
&self,
font: Type1Instance<'_>,
glyph: GlyphId,
) -> Option<GlyphExtents<F48Dot16>>
fn type1_extents( &self, font: Type1Instance<'_>, glyph: GlyphId, ) -> Option<GlyphExtents<F48Dot16>>
Returns the bounding box of a Type 1 charstring.
Sourcefn extents_from_source(
&self,
source: &ExtentsSource<'_>,
glyph: GlyphId,
) -> Option<GlyphExtents<F48Dot16>>
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.
Sourcefn extents_batched_mixed<'o, V: 'o>(
&self,
sources: &ExtentsSources<'_>,
convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcepub(crate) fn line_extents(&self) -> Option<LineExtents<F48Dot16>>
pub(crate) fn line_extents(&self) -> Option<LineExtents<F48Dot16>>
Returns the line this font’s glyphs stack by, where it provides one.
Sourcepub(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,
)
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, )
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.
Sourcepub(crate) fn states_vertical_advances(&self) -> bool
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.
pub(crate) fn origin_line(&self) -> LineExtents<F48Dot16>
fn origin_against_ink( &self, glyph: GlyphId, line: LineExtents<F48Dot16>, ) -> F48Dot16
fn origin_from_extents( extents: Option<GlyphExtents<F48Dot16>>, line: LineExtents<F48Dot16>, ) -> F48Dot16
Sourcefn extents_batched_glyf_varied<'o, V: 'o>(
&self,
convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcefn 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)>,
)
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.
Sourcefn extents_batched_type1<'o, V: 'o>(
&self,
font: Type1Instance<'_>,
convert: impl Fn(Option<GlyphExtents<F48Dot16>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcefn line_height(&self) -> F48Dot16
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.
Sourcefn 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)>,
)
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.
Sourcefn 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)>,
)
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.
Sourcefn h_advance_batched_standalone_cff<'o, V: 'o>(
&self,
cff: &CffFontRef<'_>,
convert: impl Fn(F48Dot16) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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.
Sourcefn h_advance_batched_type1<'o, V: 'o>(
&self,
font: Type1Instance<'_>,
convert: impl Fn(F48Dot16) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
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>
impl<'a> Clone for GlyphMetrics<'a>
Source§fn clone(&self) -> GlyphMetrics<'a>
fn clone(&self) -> GlyphMetrics<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more