Skip to main content

ScalerFont

Struct ScalerFont 

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

The 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: State

Implementations§

Source§

impl ScalerFont

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn font(&self) -> &Font

Returns the font, set to its variation location.

Source

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.

Source

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.

Source

pub fn ppem(&self) -> Option<f32>

Returns the size in pixels per em, or None for font units.

Source

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.

Source

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.

Source

pub fn hint_options(&self) -> Option<HintOptions>

Returns the hinting configuration, if any.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn configure(&mut self)

Sets the state up for the font, size and hinting.

Source

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.

Trait Implementations§

Source§

impl Debug for ScalerFont

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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, 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.