Skip to main content

ShaperFont

Struct ShaperFont 

Source
pub struct ShaperFont<'a, 'f> {
    font: &'a Font,
    ot: OtData<'a>,
    aat: AatData<'a>,
    units_per_em: u16,
    apply_trak: bool,
    charmap: Charmap<'a>,
    glyph_metrics: OnceLock<GlyphMetrics<'a>>,
    cmap_cache: Option<&'a CacheCore<KEY_BITS, VALUE_BITS, CACHE_SIZE, <() as SelectAtomic<STORAGE_BITS>>::Type>>,
    symbol_font_page: OnceLock<u16>,
    pub(crate) scale: Scale,
    funcs: Option<&'f dyn FontFuncs>,
}
Expand description

A font configured for shaping and font queries.

Uses the font’s own character map and metrics by default. A scale and custom FontFuncs can be set to change the queries used during shaping. Dereferences to the underlying Font for direct font queries.

Fields§

§font: &'a Font§ot: OtData<'a>§aat: AatData<'a>§units_per_em: u16§apply_trak: bool§charmap: Charmap<'a>§glyph_metrics: OnceLock<GlyphMetrics<'a>>§cmap_cache: Option<&'a CacheCore<KEY_BITS, VALUE_BITS, CACHE_SIZE, <() as SelectAtomic<STORAGE_BITS>>::Type>>§symbol_font_page: OnceLock<u16>§scale: Scale§funcs: Option<&'f dyn FontFuncs>

Implementations§

Source§

impl<'a, 'f> ShaperFont<'a, 'f>

Source

pub fn new(font: &'a Font) -> Self

Prepares a font for shaping, reusing its cached layout data.

Source

pub fn normalized_coords(&self) -> &[NormalizedCoord] ⓘ

Returns the currently active normalized coordinates.

Source

pub fn set_scale(&mut self, scale: i32)

Sets the same scale on both axes.

Source

pub fn with_scale(self, scale: i32) -> Self

Returns a new shaping font with the same scale applied to both axes.

Source

pub fn set_scale_separate(&mut self, x_scale: i32, y_scale: i32)

Sets independent horizontal and vertical scales.

Source

pub fn with_scale_separate(self, x_scale: i32, y_scale: i32) -> Self

Returns a new shaping font with independent horizontal and vertical scales applied.

Source

pub fn set_font_funcs(&mut self, funcs: Option<&'f dyn FontFuncs>)

Replaces the callbacks used for effective font queries.

Source

pub fn with_font_funcs(self, funcs: Option<&'f dyn FontFuncs>) -> Self

Returns a new shaping font with the specified font function callbacks.

Source

pub fn scale(&self) -> Scale

Returns the conversion from font units to the configured scale.

Source

pub fn glyph_name(&self, glyph: GlyphId) -> Option<GlyphName>

Returns the name stored for a glyph in the font, if any.

Source

pub fn nominal_glyph(&self, codepoint: u32) -> Option<GlyphId>

Maps a character through the configured callbacks.

Source

pub fn default_nominal_glyph(&self, codepoint: u32) -> Option<GlyphId>

Maps a character using the font’s own charmap.

Source

pub fn nominal_glyphs(&self, glyphs: NominalGlyphs<'_>) -> usize

Maps a batch of codepoints through the configured callbacks.

Source

pub fn default_nominal_glyphs(&self, glyphs: NominalGlyphs<'_>) -> usize

Maps a batch of codepoints using the font’s own charmap.

Source

pub fn variation_glyph(&self, codepoint: u32, selector: u32) -> Option<GlyphId>

Maps a character and variation selector through the configured callbacks.

Source

pub fn default_variation_glyph( &self, codepoint: u32, selector: u32, ) -> Option<GlyphId>

Maps a variation sequence using the font’s own charmap.

Source

pub fn glyph_h_advance(&self, glyph: GlyphId) -> i32

Returns the effective horizontal advance.

Source

pub fn default_glyph_h_advance(&self, glyph: GlyphId) -> i32

Returns the scaled horizontal advance from the font’s own tables.

Source

pub fn glyph_h_advances(&self, advances: Advances<'_>)

Writes effective horizontal advances for a batch of glyphs.

Source

pub fn default_glyph_h_advances(&self, advances: Advances<'_>)

Writes scaled horizontal advances from the font’s own tables.

Source

pub fn glyph_v_advance(&self, glyph: GlyphId) -> i32

Returns the effective vertical advance.

Source

pub fn default_glyph_v_advance(&self, glyph: GlyphId) -> i32

Returns the scaled vertical advance from the font’s own tables.

Source

pub fn glyph_v_origin(&self, glyph: GlyphId) -> (i32, i32)

Returns the effective vertical origin.

Source

pub fn default_glyph_v_origin(&self, glyph: GlyphId) -> (i32, i32)

Returns the scaled vertical origin from the font’s own tables.

Source

pub fn glyph_extents(&self, glyph: GlyphId) -> Option<GlyphExtents>

Returns the effective glyph extents.

Source

pub fn default_glyph_extents(&self, glyph: GlyphId) -> Option<GlyphExtents>

Returns the scaled glyph extents from the font’s own tables.

Source§

impl<'a> ShaperFont<'a, '_>

Source

pub(crate) fn layout(&self) -> LayoutData<'_>

Source

pub(crate) fn has_glyph(&self, codepoint: u32) -> bool

Source

fn cmap_cache( &self, ) -> Option<&CacheCore<KEY_BITS, VALUE_BITS, CACHE_SIZE, <() as SelectAtomic<STORAGE_BITS>>::Type>>

Source

fn symbol_font_page(&self) -> u16

Source

fn glyph_metrics(&self) -> ScaledGlyphMetrics<'a, 'static, Scale>

Source

fn map_unicode(&self, codepoint: u32) -> Option<GlyphId>

Methods from Deref<Target = Font>§

Source

pub fn axes(&self) -> Axes<'_>

Returns the font’s variation axes, which are empty if the font is not variable.

Source

pub fn named_instances(&self) -> NamedInstances<'_>

Returns the named instances defined by the font.

Source

pub fn instance_builder(&self) -> InstanceBuilder

Returns a builder for another instance of the same font.

The two share everything the location does not change, so deriving one instance from another costs no more than reading the tables once.

Source

pub fn default_instance(&self) -> Font

Returns this font at its default location.

Source

pub fn normalized_coords(&self) -> &[F2Dot14]

Returns the normalized variation coordinates for this font instance.

Source

pub fn feature_variations(&self) -> SelectedFeatureVariations

Returns the layout feature variations this instance selects.

Source

pub fn num_glyphs(&self) -> u32

Returns the number of glyphs in the font.

Fixed for the font: no location varies it.

Source

pub fn units_per_em(&self) -> u16

Returns the size of the em square, in font units.

Fixed for the font: no location varies it.

Source

pub fn default_attributes(&self) -> Attributes

Returns the width, style and weight of the default instance.

For an SFNT font, these come from the OS/2 table, with the post italic angle for an oblique style. If there is no OS/2 table, they come from head. These tables do not vary, so every instance of a variable font returns the same values. To get the attributes at a location, use Attributes::from_variations.

For a Type 1 or standalone CFF font, these come from the Weight name and ItalicAngle.

Source

pub fn is_hint_reliant(&self) -> bool

Returns true if the font needs its TrueType instructions to draw correct contours.

Such fonts are often called “tricky”. They are recognized by family name or by the checksums of the cvt, fpgm and prep tables, and only fonts with glyf outlines qualify. The result is computed once and cached. See is_hint_reliant.

Source

pub fn names(&self) -> Names<'_>

Returns the font’s names and other localized strings.

Source

pub fn glyph_name(&self, glyph: GlyphId) -> Option<GlyphName>

Returns the name of a glyph, synthesizing gidNNN if none is stored.

Returns None for a glyph outside the font.

Source

pub fn glyph_names(&self) -> impl Iterator<Item = (GlyphId, GlyphName)>

Returns the identifier and name of every glyph in the font.

Names come from post, then CFF, or from Type 1 charstrings. A missing name is synthesized as gidNNN.

Source

pub fn glyph_by_name(&self, name: &str) -> Option<GlyphId>

Returns the glyph named name.

Names come from the same sources as glyph_names, but a synthesized gidNNN name matches nothing. Where several glyphs share a name, the first is returned.

The first call sorts the font’s names, and later calls search them.

Source

pub fn is_cid_keyed(&self) -> bool

Returns true if the font is a standalone CID-keyed CFF font, whose glyphs are identified by CID.

A CFF table in an SFNT font may be CID-keyed too, but its glyphs are identified by glyph index, as in any SFNT font.

Source

pub fn max_cid(&self) -> Option<u32>

Returns the largest CID that a CID-keyed font maps to a glyph.

Glyphs in a CID-keyed font can be addressed by CID, so one more than this value is the number of addressable glyph IDs. Returns None if the font is not CID-keyed.

Source

pub fn glyph_by_cid(&self, cid: u32) -> Option<GlyphId>

Returns the glyph for cid in a CID-keyed font.

Where several glyphs have the same CID, the first is returned. Returns None if the font is not CID-keyed or no glyph has cid.

The first call builds a table from each CID to its glyph.

Source

pub fn charmap(&self) -> Charmap<'_>

Returns the font’s character mappings.

Source

pub fn metrics(&self) -> &Metrics

Returns the metrics describing the font as a whole, at this instance’s location.

Source

pub fn style_metrics(&self) -> &StyleMetrics

Returns the font’s style measurements at this instance’s location.

This reads post when requested; metrics does not.

Source

pub fn glyph_metrics(&self) -> GlyphMetrics<'_>

Returns measurements of individual glyphs, at this instance’s location.

Source

pub fn outline_glyphs(&self) -> OutlineGlyphs<'_>

Returns the font’s outlines, using the source order in GlyphSourceOrder::DEFAULT.

Source

pub fn outline_glyphs_with(&self, order: GlyphSourceOrder) -> OutlineGlyphs<'_>

Returns the font’s outlines, using the source order in order.

The first of Glyf, Cff2, Cff and Type1 that the font has becomes the base source for every glyph. If Varc comes before the base source, it applies to the glyphs it covers, and their components are drawn from the base source. Sources that are not outlines are ignored.

Source

pub fn bitmap_strikes(&self) -> BitmapStrikes<'_>

Returns the font’s bitmaps, from the first of sbix, CBDT and EBDT that the font has.

Source

pub fn bitmap_strikes_with(&self, order: GlyphSourceOrder) -> BitmapStrikes<'_>

Returns the font’s bitmaps, using the source order in order.

The bitmaps come from the first of Sbix, Cbdt and Ebdt in order that the font has. Sources that are not bitmaps are ignored.

Source

pub fn color_glyphs(&self) -> ColorGlyphs<'_>

Returns the font’s color glyphs.

Source

pub fn palettes(&self) -> Palettes<'_>

Returns the font’s color palettes.

Source

pub fn source(&self) -> &Source

Returns the underlying source of font data.

Source

pub fn kind(&self) -> Kind<'_>

Returns the underlying kind of the font.

Source

pub fn tables(&self) -> &Tables

Returns an object that provides access to individual font tables.

For non-SFNT fonts, this will return an empty set of tables.

Trait Implementations§

Source§

impl<'a, 'f> Clone for ShaperFont<'a, 'f>

Source§

fn clone(&self) -> ShaperFont<'a, 'f>

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 Deref for ShaperFont<'_, '_>

Source§

type Target = Font

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'a, 'f> !Freeze for ShaperFont<'a, 'f>

§

impl<'a, 'f> !RefUnwindSafe for ShaperFont<'a, 'f>

§

impl<'a, 'f> !Send for ShaperFont<'a, 'f>

§

impl<'a, 'f> !Sync for ShaperFont<'a, 'f>

§

impl<'a, 'f> !UnwindSafe for ShaperFont<'a, 'f>

§

impl<'a, 'f> Unpin for ShaperFont<'a, 'f>

§

impl<'a, 'f> UnsafeUnpin for ShaperFont<'a, 'f>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.