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<Font>

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) -> &[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 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 From<Font> for ScalerSource

Source§

fn from(font: Font) -> Self

Converts to this type from the input type.
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<TupleVariationData<'a, GlyphDelta>>

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.