pub struct ScalerFont {
outlines: Yoke<OutlineGlyphs<'static>, Box<Font>>,
order: GlyphSourceOrder,
ppem: Option<f32>,
hint_options: Option<HintOptions>,
state: State,
}Expand description
Draws glyphs from a Font at a size, with optional hinting.
Drawing takes &self, so a scaler is cheap to draw from and safe to
share. Working memory comes from the caller or from short lived scratch.
reconfigure sets up a scaler for another font,
size, or hinting and reuses the existing memory. This lets a cache of
scalers reuse its entries.
Fields§
§outlines: Yoke<OutlineGlyphs<'static>, Box<Font>>The font, with its outlines resolved once rather than for every draw.
order: GlyphSourceOrderThe order the outline sources were resolved in, which glyph extents follow too.
ppem: Option<f32>Pixels per em, or None for font units.
hint_options: Option<HintOptions>§state: StateImplementations§
Source§impl ScalerFont
impl ScalerFont
Sourcepub fn unhinted(font: impl Into<ScalerSource>, ppem: Option<f32>) -> Self
pub fn unhinted(font: impl Into<ScalerSource>, ppem: Option<f32>) -> Self
Creates a scaler that draws font unhinted.
ppem is the size in pixels per em, or None for font units.
A TrueType font that needs its instructions to draw correct contours is
hinted anyway when there is a size. It is hinted with
HintOptions::interpreter, which hint_options
then returns. Use force_unhinted to draw
such a font unhinted.
Sourcepub fn force_unhinted(font: impl Into<ScalerSource>, ppem: Option<f32>) -> Self
pub fn force_unhinted(font: impl Into<ScalerSource>, ppem: Option<f32>) -> Self
Creates a scaler that draws font unhinted, even a font that needs
its instructions to draw correct contours.
ppem is the size in pixels per em, or None for font units.
Sourcepub fn hinted(
font: impl Into<ScalerSource>,
ppem: f32,
hint_options: HintOptions,
) -> Self
pub fn hinted( font: impl Into<ScalerSource>, ppem: f32, hint_options: HintOptions, ) -> Self
Creates a scaler that draws font at ppem pixels per em, hinted as
hint_options asks.
Hinting fits an outline to a pixel grid, so it always requires a size.
Sourcepub fn reconfigure(
&mut self,
font: impl Into<ScalerSource>,
ppem: f32,
hint_options: HintOptions,
)
pub fn reconfigure( &mut self, font: impl Into<ScalerSource>, ppem: f32, hint_options: HintOptions, )
Reconfigures the scaler to draw font at ppem pixels per em, hinted
as hint_options asks.
The memory from the previous setup is reused. This lets an entry in a cache of hinted scalers change its font, size, and hinting without creating a new scaler. Setup reruns the font’s programs, so avoid calling this on a hot path. An unhinted scaler is cheap to create, so there is nothing to gain from reconfiguring one; this always leaves the scaler hinted.
Sourcepub fn outline_source(&self) -> Option<OutlineSource>
pub fn outline_source(&self) -> Option<OutlineSource>
Returns the table that provides the outlines.
This is OutlineSource::Varc if VARC composites are drawn. The
composites cover only some glyphs, and the rest come from the
underlying_outline_source.
Returns None if the font has no outlines from the scaler’s sources.
Sourcepub fn underlying_outline_source(&self) -> Option<OutlineSource>
pub fn underlying_outline_source(&self) -> Option<OutlineSource>
Returns the table that draws the glyphs VARC does not cover and the
components of those it does.
This is the same as outline_source unless
VARC composites are drawn, and is never OutlineSource::Varc.
Returns None if the font has no outlines from the scaler’s sources.
Sourcepub fn hinted_ppem(&self) -> Option<f32>
pub fn hinted_ppem(&self) -> Option<f32>
Returns the size glyphs are hinted at, in pixels per em.
This is ppem, except for a TrueType font whose head
table asks for whole pixel sizes. The interpreter then hints at the
size rounded to a whole pixel, and draws at it too when the font turns
hinting off.
Sourcepub fn hint_engine(&self) -> Option<HintEngine>
pub fn hint_engine(&self) -> Option<HintEngine>
Returns the hinting engine the scaler runs, or None if it does not
hint.
A scaler does not hint without hinting options or a size, or where
setup failed, which hinting_error reports. A
TrueType font can turn its hinting off at some sizes, so the engine
can be selected where is_hinted is false.
Sourcepub fn hint_options(&self) -> Option<HintOptions>
pub fn hint_options(&self) -> Option<HintOptions>
Returns the hinting configuration, if any.
Sourcepub fn is_hinted(&self) -> bool
pub fn is_hinted(&self) -> bool
Returns true if glyphs are hinted at this size.
Returns false if no hinting is configured, if the size is in font
units, or if the font has nothing to hint with. Also returns false if
the font disables hinting at this size through its control value
program or gasp table.
A VARC composite is drawn unhinted unless the automatic hinter is
in use, even where this returns true.
Sourcepub fn hinting_error(&self) -> Option<&ScaleError>
pub fn hinting_error(&self) -> Option<&ScaleError>
Returns the error that prevented hinting setup, if any.
Every draw fails with this error until the size or hinting changes.
Sourcepub fn raster_policy(&self) -> Option<RasterPolicy>
pub fn raster_policy(&self) -> Option<RasterPolicy>
Returns the smoothing and grid fitting the font requests at this size.
Returns None unless the TrueType interpreter hints the font. With
classic ClearType, this is the
default policy rather than the font’s.
Sourcepub fn metrics(&self) -> ScaledMetrics<'_, ScaleF32>
pub fn metrics(&self) -> ScaledMetrics<'_, ScaleF32>
Returns the metrics describing the font as a whole, in pixels at
ppem, or in font units without a size.
These are scaled linearly; hinting does not change them.
Sourcepub fn style_metrics(&self) -> ScaledStyleMetrics<'_, ScaleF32>
pub fn style_metrics(&self) -> ScaledStyleMetrics<'_, ScaleF32>
Returns the font-wide style measurements, in pixels at
ppem, or in font units without a size.
These are scaled linearly; hinting does not change them.
Sourcepub fn linear_glyph_metrics(&self) -> ScaledGlyphMetrics<'_, 'static, ScaleF32>
pub fn linear_glyph_metrics(&self) -> ScaledGlyphMetrics<'_, 'static, ScaleF32>
Returns the glyph metrics, in pixels at ppem, or in
font units without a size.
These are scaled linearly; hinting does not change them. For a hinted
glyph’s advance, draw its outline: ScalerOutline::draw returns it
in DrawnMetrics::h_advance.
Glyph extents are measured from the sources the scaler draws from, in the same order.
Sourcepub fn outline(&self, glyph: GlyphId) -> Option<ScalerOutline<'_>>
pub fn outline(&self, glyph: GlyphId) -> Option<ScalerOutline<'_>>
Returns the outline of glyph, resolved for drawing.
Returns None if the font has no outline for the glyph.
Sourcefn draw_unhinted(
&self,
outline: &OutlineGlyph<'_>,
ppem: Option<f32>,
memory: Option<&mut [u8]>,
sink: &mut dyn PathSink,
) -> Result<DrawnMetrics, ScaleError>
fn draw_unhinted( &self, outline: &OutlineGlyph<'_>, ppem: Option<f32>, memory: Option<&mut [u8]>, sink: &mut dyn PathSink, ) -> Result<DrawnMetrics, ScaleError>
Draws outline unhinted at ppem.
This is the scaler’s size, except when the TrueType interpreter runs at a rounded size.