Skip to main content

ScaledGlyphMetrics

Struct ScaledGlyphMetrics 

Source
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>

Source

pub(crate) fn new(metrics: GlyphMetrics<'a>, scale: S) -> Self

Source

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.

Source

pub fn with_extents_source_order(self, order: GlyphSourceOrder) -> Self

Measures ink using the sources in order.

See GlyphMetrics::with_extents_source_order.

Source

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.

Source

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

Returns the advance width of glyph.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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>
where S::Value: Clone,

Source§

fn clone(&self) -> ScaledGlyphMetrics<'a, 'extents, S>

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, 'extents, S: Copy + Scale> Copy for ScaledGlyphMetrics<'a, 'extents, S>
where S::Value: Copy,

Auto Trait Implementations§

§

impl<'a, 'extents, S> !RefUnwindSafe for ScaledGlyphMetrics<'a, 'extents, S>

§

impl<'a, 'extents, S> !Send for ScaledGlyphMetrics<'a, 'extents, S>

§

impl<'a, 'extents, S> !Sync for ScaledGlyphMetrics<'a, 'extents, S>

§

impl<'a, 'extents, S> !UnwindSafe for ScaledGlyphMetrics<'a, 'extents, S>

§

impl<'a, 'extents, S> Freeze for ScaledGlyphMetrics<'a, 'extents, S>
where S: Freeze, <S as Scale>::Value: Freeze,

§

impl<'a, 'extents, S> Unpin for ScaledGlyphMetrics<'a, 'extents, S>
where S: Unpin, <S as Scale>::Value: Unpin,

§

impl<'a, 'extents, S> UnsafeUnpin for ScaledGlyphMetrics<'a, 'extents, S>
where S: UnsafeUnpin, <S as Scale>::Value: UnsafeUnpin,

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.