pub struct ScaledGlyphMetrics<'a, 'extents, S>where
S: Scale,{
metrics: GlyphMetrics<'a>,
scale: S,
line: Option<LineExtents<<S as Scale>::Value>>,
extents: Option<&'extents dyn Fn(GlyphId) -> Option<GlyphExtents<<S as Scale>::Value>>>,
}Expand description
Measurements of individual glyphs, in a caller’s own units.
Holds borrows and a scale, so it is as cheap to make as the metrics it scales and can be taken per query. It remembers nothing between calls: a caller wanting measurements kept holds them itself.
Fields§
§metrics: GlyphMetrics<'a>§scale: S§line: Option<LineExtents<<S as Scale>::Value>>§extents: Option<&'extents dyn Fn(GlyphId) -> Option<GlyphExtents<<S as Scale>::Value>>>Implementations§
Source§impl<'a, 'extents, S> ScaledGlyphMetrics<'a, 'extents, S>where
S: Scale,
impl<'a, 'extents, S> ScaledGlyphMetrics<'a, 'extents, S>where
S: Scale,
Sourcepub fn with_line_extents(
self,
line: Option<LineExtents<<S as Scale>::Value>>,
) -> ScaledGlyphMetrics<'a, 'extents, S>
pub fn with_line_extents( self, line: Option<LineExtents<<S as Scale>::Value>>, ) -> ScaledGlyphMetrics<'a, 'extents, S>
Measures against a line the caller supplies rather than the font’s own.
A caller that reads its line from elsewhere supplies it here, so the metrics built on it agree with the rest of its layout. The line is in the same units as everything else this type reports, so nothing is converted back into font units.
None leaves the font’s own line in place, so a caller can pass
whatever it happens to have without first checking.
Sourcepub fn with_extents_source_order(
self,
order: GlyphSourceOrder,
) -> ScaledGlyphMetrics<'a, 'extents, S>
pub fn with_extents_source_order( self, order: GlyphSourceOrder, ) -> ScaledGlyphMetrics<'a, 'extents, S>
Measures ink using the sources in order.
Sourcepub fn with_glyph_extents<'new>(
self,
extents: Option<&'new dyn Fn(GlyphId) -> Option<GlyphExtents<<S as Scale>::Value>>>,
) -> ScaledGlyphMetrics<'a, 'new, S>
pub fn with_glyph_extents<'new>( self, extents: Option<&'new dyn Fn(GlyphId) -> Option<GlyphExtents<<S as Scale>::Value>>>, ) -> ScaledGlyphMetrics<'a, 'new, S>
Measures ink by a function the caller supplies rather than the font.
A caller that measures glyphs elsewhere supplies that here, so the
metrics built on ink agree with the rest of what it reports. The
function answers in the same units as everything else this type
reports, so nothing is converted back into font units. None from
the function means extents are unavailable; return
Some(GlyphExtents::default()) for a present glyph with no ink.
None leaves the font’s own measurement in place, so a caller can
pass whatever it happens to have without first checking.
The function is borrowed only for the lifetime of the returned view.
Sourcepub fn h_advance(&self, glyph: GlyphId) -> <S as Scale>::Value
pub fn h_advance(&self, glyph: GlyphId) -> <S as Scale>::Value
Returns the advance width of glyph.
Sourcepub fn h_advance_batched<'o, V>(
&self,
convert: impl Fn(<S as Scale>::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
pub fn h_advance_batched<'o, V>(
&self,
convert: impl Fn(<S as Scale>::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
Writes the advance width of each glyph to its slot, in order.
Sourcepub fn v_advance(&self, glyph: GlyphId) -> <S as Scale>::Value
pub fn v_advance(&self, glyph: GlyphId) -> <S as Scale>::Value
Returns the advance height of glyph.
A font with no vertical metrics stacks its glyphs by the line, the only measurement here a caller can supply. One that has them is measured by what it says, and a supplied line changes nothing.
Sourcepub fn v_advance_batched<'o, V>(
&self,
convert: impl Fn(<S as Scale>::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
pub fn v_advance_batched<'o, V>(
&self,
convert: impl Fn(<S as Scale>::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
Writes the advance height of each glyph to its slot, in order.
Sourcepub fn v_origin_y(&self, glyph: GlyphId) -> <S as Scale>::Value
pub fn v_origin_y(&self, glyph: GlyphId) -> <S as Scale>::Value
Returns the y coordinate of glyph’s vertical origin.
This places the glyph relative to the pen in vertical text. The x coordinate is half the advance width, so only y is returned.
The origin comes from the first available of: VORG, the glyf top
phantom point when the font has vertical metrics, the ink centered in
the line, and the ascender. The last two use the supplied ink
measurement.
Sourcepub fn v_origin_y_batched<'o, V>(
&self,
convert: impl Fn(<S as Scale>::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
pub fn v_origin_y_batched<'o, V>(
&self,
convert: impl Fn(<S as Scale>::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
Writes the vertical origin of each glyph to its slot, in order.
The line is measured only if a glyph reaches the extents fallback, and then reused for the rest of the run.
Sourcepub fn extents(
&self,
glyph: GlyphId,
) -> Option<GlyphExtents<<S as Scale>::Value>>
pub fn extents( &self, glyph: GlyphId, ) -> Option<GlyphExtents<<S as Scale>::Value>>
Returns where glyph’s ink sits.
An empty glyph has zero extents. None means the glyph is unavailable
or its extents could not be read. A supplied extents function may use
None for any glyph it does not measure.
Sourcepub fn extents_batched<'o, V>(
&self,
convert: impl Fn(Option<GlyphExtents<<S as Scale>::Value>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
pub fn extents_batched<'o, V>(
&self,
convert: impl Fn(Option<GlyphExtents<<S as Scale>::Value>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)where
V: 'o,
Writes where each glyph’s ink sits to its slot, in order.
Trait Implementations§
Source§impl<'a, 'extents, S> Clone for ScaledGlyphMetrics<'a, 'extents, S>
impl<'a, 'extents, S> Clone for ScaledGlyphMetrics<'a, 'extents, S>
Source§fn clone(&self) -> ScaledGlyphMetrics<'a, 'extents, S>
fn clone(&self) -> ScaledGlyphMetrics<'a, 'extents, S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more