pub struct ScaledGlyphMetrics<'a, 'extents, S: Scale> {
metrics: GlyphMetrics<'a>,
scale: S,
line: Option<LineExtents<S::Value>>,
extents: Option<&'extents dyn Fn(GlyphId) -> Option<GlyphExtents<S::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::Value>>§extents: Option<&'extents dyn Fn(GlyphId) -> Option<GlyphExtents<S::Value>>>Implementations§
Source§impl<'a, 'extents, S: Scale> ScaledGlyphMetrics<'a, 'extents, S>
impl<'a, 'extents, S: Scale> ScaledGlyphMetrics<'a, 'extents, S>
pub(crate) fn new(metrics: GlyphMetrics<'a>, scale: S) -> Self
Sourcepub fn with_line_extents(self, line: Option<LineExtents<S::Value>>) -> Self
pub fn with_line_extents(self, line: Option<LineExtents<S::Value>>) -> Self
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) -> Self
pub fn with_extents_source_order(self, order: GlyphSourceOrder) -> Self
Measures ink using the sources in order.
Sourcepub fn with_glyph_extents<'new>(
self,
extents: Option<&'new dyn Fn(GlyphId) -> Option<GlyphExtents<S::Value>>>,
) -> ScaledGlyphMetrics<'a, 'new, S>
pub fn with_glyph_extents<'new>( self, extents: Option<&'new dyn Fn(GlyphId) -> Option<GlyphExtents<S::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_batched<'o, V: 'o>(
&self,
convert: impl Fn(S::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
pub fn h_advance_batched<'o, V: 'o>( &self, convert: impl Fn(S::Value) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
Writes the advance width of each glyph to its slot, in order.
Sourcepub fn v_advance(&self, glyph: GlyphId) -> S::Value
pub fn v_advance(&self, glyph: GlyphId) -> S::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: 'o>(
&self,
convert: impl Fn(S::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
pub fn v_advance_batched<'o, V: 'o>( &self, convert: impl Fn(S::Value) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
Writes the advance height of each glyph to its slot, in order.
Sourcepub fn v_origin_y(&self, glyph: GlyphId) -> S::Value
pub fn v_origin_y(&self, glyph: GlyphId) -> S::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: 'o>(
&self,
convert: impl Fn(S::Value) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
pub fn v_origin_y_batched<'o, V: 'o>( &self, convert: impl Fn(S::Value) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
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::Value>>
pub fn extents(&self, glyph: GlyphId) -> Option<GlyphExtents<S::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: 'o>(
&self,
convert: impl Fn(Option<GlyphExtents<S::Value>>) -> V,
glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>,
)
pub fn extents_batched<'o, V: 'o>( &self, convert: impl Fn(Option<GlyphExtents<S::Value>>) -> V, glyphs: impl Iterator<Item = (GlyphId, &'o mut V)>, )
Writes where each glyph’s ink sits to its slot, in order.
Sourcefn line_height_fallback(&self) -> Option<S::Value>
fn line_height_fallback(&self) -> Option<S::Value>
The height a glyph takes from the line, where it takes one.
None for two reasons that mean the same thing here: the font has
vertical metrics of its own, so the line is not what its glyphs stack
by; or it has no line either, which the unscaled metrics answer with
an em. A supplied line applies only in the first case, so supplying
one never overrides what a font says about itself.
Each end is scaled before the two are subtracted, so a scale that rounds rounds them as a caller supplying its own line would, and the answer does not turn on whether one was supplied.
Sourcefn origin_line(&self) -> LineExtents<S::Value>
fn origin_line(&self) -> LineExtents<S::Value>
The line a glyph stacks by, in the units this type reports.
The supplied line if there is one, and the font’s otherwise. A font with no line metrics gets one proportioned to its em.
Sourcefn origin_against_ink(
&self,
glyph: GlyphId,
line: LineExtents<S::Value>,
) -> S::Value
fn origin_against_ink( &self, glyph: GlyphId, line: LineExtents<S::Value>, ) -> S::Value
The last two rungs of v_origin_y, which measure
against the ink.
fn origin_from_extents( &self, extents: Option<GlyphExtents<S::Value>>, line: LineExtents<S::Value>, ) -> S::Value
Trait Implementations§
Source§impl<'a, 'extents, S: Clone + Scale> Clone for ScaledGlyphMetrics<'a, 'extents, S>
impl<'a, 'extents, S: Clone + Scale> 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