pub trait Scale {
type Value: Copy;
// Required methods
fn add(a: Self::Value, b: Self::Value) -> Self::Value;
fn sub(a: Self::Value, b: Self::Value) -> Self::Value;
fn half(value: Self::Value) -> Self::Value;
fn scale_x(&self, value: F48Dot16) -> Self::Value;
fn scale_y(&self, value: F48Dot16) -> Self::Value;
fn scale_glyph_extents(
&self,
extents: GlyphExtents<F48Dot16>,
) -> GlyphExtents<Self::Value>;
fn scale_rect(
&self,
bounds: BoundingBox<F48Dot16>,
) -> BoundingBox<Self::Value>;
// Provided method
fn ppem(&self) -> Option<f32> { ... }
}Expand description
Converts a measurement in font units into a caller’s own units.
Written by whatever owns scaling in a text stack: a shaper, or the bridge
between one and this crate. Callers that want font units read them from
GlyphMetrics, Metrics and StyleMetrics and never implement this.
An implementation chooses the number format, the rounding, and the order of operations for each axis. This crate defines how measurements combine into a metric.
The arithmetic is part of the trait for the same reason: an implementation decides what an overflowing sum does and which way a halved odd number rounds.
Required Associated Types§
Required Methods§
Sourcefn add(a: Self::Value, b: Self::Value) -> Self::Value
fn add(a: Self::Value, b: Self::Value) -> Self::Value
Returns a plus b.
This and the two below take no scale. They describe
Value itself, so every scale of that type answers
them alike.
Sourcefn scale_y(&self, value: F48Dot16) -> Self::Value
fn scale_y(&self, value: F48Dot16) -> Self::Value
Scales a measurement along the y axis.
Separate from scale_x because the two axes need
not agree, and because a caller whose y runs down the page says so
here.
Sourcefn scale_glyph_extents(
&self,
extents: GlyphExtents<F48Dot16>,
) -> GlyphExtents<Self::Value>
fn scale_glyph_extents( &self, extents: GlyphExtents<F48Dot16>, ) -> GlyphExtents<Self::Value>
Scales where a glyph’s ink sits.
One call rather than four, so that a scale running the other way up settles in one place what that means for a bearing and a size. The scale also decides whether to round the box’s corners before scaling.
Sourcefn scale_rect(&self, bounds: BoundingBox<F48Dot16>) -> BoundingBox<Self::Value>
fn scale_rect(&self, bounds: BoundingBox<F48Dot16>) -> BoundingBox<Self::Value>
Scales a region given by its corners.
One call for the same reason as scale_glyph_extents:
a scale running the other way up decides here which corner ends up
least.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".