Skip to main content

Font

Struct Font 

Source
pub struct Font(Repr);
Expand description

A font at one location in its design space.

Cloning is cheap: clones share one instance rather than copying it.

Tuple Fields§

§0: Repr

Implementations§

Source§

impl Font

Source

pub fn new(source: impl Into<Source>, index: u32) -> Option<Self>

Creates a font from source, at its default location.

index selects a font within the data:

  • SFNT: the font in a collection (ttc or otc). Data holding a single font accepts only zero.
  • Standalone CFF: the font in the CFF font set.
  • Type 1: ignored, since the data holds one font.
  • TableFunction: ignored, since the function supplies the tables of one font.

Returns None if the source holds no font in a supported format, or none at index.

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) -> &[NormalizedCoord] ⓘ

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.

Source§

impl Font

Source

pub(super) fn scaling_data(&self) -> &OnceLock<Box<dyn Any + Send + Sync>>

Returns the slot for data that Skrifa derives from the font at this location.

At the default location, the slot belongs to the shared font. Elsewhere, it belongs to the instance.

Source

fn location_caches(&self) -> &LocationCaches

Returns the caches for this instance’s location.

At the default location, the caches belong to the shared font. Elsewhere, they belong to the instance.

Source

fn sfnt_location(&self) -> Option<&SfntLocation>

Returns the SFNT caches for this instance’s location, or None if the font is not an SFNT font.

Source

pub(super) fn shared(&self) -> &SharedFont

The state every instance of this font shares.

Source

pub(crate) fn type1_axes(&self) -> Option<&[VariationAxisRecord]>

Returns the axes of a Type 1 multiple master font, or None for any other font.

Source

pub(crate) fn type1_instance(&self) -> Option<Type1Instance<'_>>

Returns a Type 1 font drawn at this instance’s location.

Source

pub(crate) fn h_metric_records(&self) -> &GlyphMetricRecords<'_>

Returns the horizontal glyph metrics, from HMTX or hmtx.

Source

pub(crate) fn v_metric_records(&self) -> &GlyphMetricRecords<'_>

Returns the vertical glyph metrics, from VMTX or vmtx.

Source

pub(crate) fn selected_glyf_loca(&self) -> Option<&(Glyf<'_>, Loca<'_>)>

Returns the outline tables.

Source

pub(crate) fn hvar(&self) -> Option<&Hvar<'_>>

Returns HVAR.

Source

pub(crate) fn vvar(&self) -> Option<&Vvar<'_>>

Returns VVAR.

Source

pub(crate) fn selected_gvar(&self) -> Option<&SelectedGvar<'_>>

Returns GVAR, or gvar without it.

Source

pub(crate) fn gvar_scalars(&self) -> &[Fixed]

Returns the gvar shared tuple scalars at this location, computed once.

Source

pub(crate) fn hvar_scalars(&self) -> &[Fixed]

Returns the HVAR region scalars at this location, computed once.

Source

pub(crate) fn vvar_scalars(&self) -> &[Fixed]

Returns the VVAR region scalars at this location, computed once.

Source

pub(crate) fn colr_scalars(&self) -> &[Fixed]

Returns the COLR region scalars at this location, computed once.

Source

fn location_scalars( &self, cache: fn(&VariedSfnt) -> &OnceLock<Box<[Fixed]>>, compute: impl FnOnce(&VariedInstance) -> Box<[Fixed]>, ) -> &[Fixed]

Returns the scalars cache selects for this location, filling it with compute the first time. The default location needs none.

Source

pub(crate) fn cff(&self) -> Option<&CffFontRef<'_>>

Returns the CFF charstring outlines from SFNT tables.

Source

pub(crate) fn charstrings( &self, source: OutlineSource, ) -> Option<&CffFontRef<'_>>

Returns the charstrings for source.

For an SFNT font, these come from the CFF2 or CFF table. A standalone CFF font provides its own charstrings as CFF.

Source

pub(crate) fn cff_subfont( &self, source: OutlineSource, index: u16, ) -> Option<Subfont>

Returns subfont index of the charstrings for source, parsed at this instance’s location.

The first CACHED_SUBFONTS subfonts are parsed once and kept, since nearly every glyph in a font shares one of them. A standalone CFF font parses them when the font is read. An SFNT font parses each once per location, when a glyph first needs it. A subfont past them is parsed each time it is asked for, so a font with thousands of subfonts costs no more memory than one with eight.

Source

pub(crate) fn has_layered_source(&self, source: GlyphSource) -> bool

Returns true if the font has glyphs from source, one of the bitmap tables, COLR or VARC.

Each source is probed the first time it is asked about and the answer kept, so asking loads no table that measuring with it would not.

Source

pub(crate) fn has_layered_source_in(&self, order: GlyphSourceOrder) -> bool

Returns true if the font has glyphs from any bitmap table, COLR or VARC that order lists.

Reads the cached results once and probes only the sources not yet checked.

Source

pub(crate) fn varc_outlines(&self) -> Option<&Outlines<'_>>

Returns the variable composites, read once for the font.

Source

pub(crate) fn colr_tables(&self) -> Option<&ColrTables<'_>>

Returns COLR with its variation tables, read once for the font.

Source

pub(crate) fn cpal(&self) -> Option<&Cpal<'_>>

Returns CPAL, read once for the font.

Source

pub(crate) fn sbix(&self) -> Option<&Sbix<'_>>

Returns sbix, read once for the font.

Source

pub(crate) fn cbdt(&self) -> Option<&(Cblc<'_>, Cbdt<'_>)>

Returns CBLC and CBDT, read once for the font.

Source

pub(crate) fn ebdt(&self) -> Option<&(Eblc<'_>, Ebdt<'_>)>

Returns EBLC and EBDT, read once for the font.

Source

pub(crate) fn vorg(&self) -> Option<&Vorg<'_>>

Returns VORG.

Trait Implementations§

Source§

impl Clone for Font

Source§

fn clone(&self) -> Font

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> OutlineContext<'a> for &'a Font

Source§

fn glyph(&self, glyph: GlyphId) -> Option<LocaGlyph<'a>>

Returns the glyph with the given identifier, or None if it is empty.
Source§

fn glyph_variation_data(&self, glyph: GlyphId) -> Option<GlyphVariationData<'a>>

Variation data for a glyph, or None if the font does not vary or the glyph has none.
Source§

fn has_gvar(&self) -> bool

True if the font has a gvar table, whatever any one glyph has in it. Read more
Source§

fn phantom_point_deltas(&self, glyph: GlyphId) -> Option<[Point<Fixed>; 4]>

Variation deltas for a glyph’s four phantom points. Read more
Source§

fn gvar_scalars(&self) -> &[Fixed]

Scalars for gvar’s shared tuples at Self::coords, as SelectedGvar::compute_scalars fills them. Read more
Source§

fn coords(&self) -> &[F2Dot14]

Normalized variation coordinates, empty for the default instance. Read more
Source§

fn units_per_em(&self) -> u16

Design units per em.
Source§

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

Left side bearing and advance width, in font units. Read more
Source§

fn v_metrics(&self, glyph: GlyphId) -> Option<(i32, i32)>

Top side bearing and vertical advance for a glyph, in font units. Read more
Source§

fn h_line_metrics(&self) -> (i32, i32)

The ascender and descender of the line horizontal text sits on, in font units. Read more
Source§

fn has_hvar(&self) -> bool

True if the font has an HVAR table. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Font

§

impl !UnwindSafe for Font

§

impl Freeze for Font

§

impl Send for Font

§

impl Sync for Font

§

impl Unpin for Font

§

impl UnsafeUnpin for Font

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.