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: ReprImplementations§
Source§impl Font
impl Font
Sourcepub fn new(source: impl Into<Source>, index: u32) -> Option<Font>
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 (
ttcorotc). 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.
Sourcepub fn axes(&self) -> Axes<'_>
pub fn axes(&self) -> Axes<'_>
Returns the font’s variation axes, which are empty if the font is not variable.
Sourcepub fn named_instances(&self) -> NamedInstances<'_>
pub fn named_instances(&self) -> NamedInstances<'_>
Returns the named instances defined by the font.
Sourcepub fn instance_builder(&self) -> InstanceBuilder
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.
Sourcepub fn default_instance(&self) -> Font
pub fn default_instance(&self) -> Font
Returns this font at its default location.
Sourcepub fn normalized_coords(&self) -> &[F2Dot14]
pub fn normalized_coords(&self) -> &[F2Dot14]
Returns the normalized variation coordinates for this font instance.
Sourcepub fn feature_variations(&self) -> SelectedFeatureVariations
pub fn feature_variations(&self) -> SelectedFeatureVariations
Returns the layout feature variations this instance selects.
Sourcepub fn num_glyphs(&self) -> u32
pub fn num_glyphs(&self) -> u32
Returns the number of glyphs in the font.
Fixed for the font: no location varies it.
Sourcepub fn units_per_em(&self) -> u16
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.
Sourcepub fn default_attributes(&self) -> Attributes
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.
Sourcepub fn is_hint_reliant(&self) -> bool
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.
Sourcepub fn glyph_name(&self, glyph: GlyphId) -> Option<GlyphName>
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.
Sourcepub fn glyph_names(&self) -> impl Iterator<Item = (GlyphId, GlyphName)>
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.
Sourcepub fn glyph_by_name(&self, name: &str) -> Option<GlyphId>
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.
Sourcepub fn is_cid_keyed(&self) -> bool
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.
Sourcepub fn max_cid(&self) -> Option<u32>
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.
Sourcepub fn glyph_by_cid(&self, cid: u32) -> Option<GlyphId>
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.
Sourcepub fn metrics(&self) -> &Metrics
pub fn metrics(&self) -> &Metrics
Returns the metrics describing the font as a whole, at this instance’s location.
Sourcepub fn style_metrics(&self) -> &StyleMetrics
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.
Sourcepub fn glyph_metrics(&self) -> GlyphMetrics<'_>
pub fn glyph_metrics(&self) -> GlyphMetrics<'_>
Returns measurements of individual glyphs, at this instance’s location.
Sourcepub fn outline_glyphs(&self) -> OutlineGlyphs<'_>
pub fn outline_glyphs(&self) -> OutlineGlyphs<'_>
Returns the font’s outlines, using the source order in
GlyphSourceOrder::DEFAULT.
Sourcepub fn outline_glyphs_with(&self, order: GlyphSourceOrder) -> OutlineGlyphs<'_>
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.
Sourcepub fn bitmap_strikes(&self) -> BitmapStrikes<'_>
pub fn bitmap_strikes(&self) -> BitmapStrikes<'_>
Returns the font’s bitmaps, from the first of sbix, CBDT and
EBDT that the font has.
Sourcepub fn bitmap_strikes_with(&self, order: GlyphSourceOrder) -> BitmapStrikes<'_>
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.
Sourcepub fn color_glyphs(&self) -> ColorGlyphs<'_>
pub fn color_glyphs(&self) -> ColorGlyphs<'_>
Returns the font’s color glyphs.
Trait Implementations§
Source§impl From<Font> for ScalerSource
impl From<Font> for ScalerSource
Source§impl<'a> OutlineContext<'a> for &'a Font
impl<'a> OutlineContext<'a> for &'a Font
Source§fn glyph(&self, glyph: GlyphId) -> Option<LocaGlyph<'a>>
fn glyph(&self, glyph: GlyphId) -> Option<LocaGlyph<'a>>
None if it is empty.Source§fn glyph_variation_data(
&self,
glyph: GlyphId,
) -> Option<TupleVariationData<'a, GlyphDelta>>
fn glyph_variation_data( &self, glyph: GlyphId, ) -> Option<TupleVariationData<'a, GlyphDelta>>
None if the font does not vary or the
glyph has none.Source§fn has_gvar(&self) -> bool
fn has_gvar(&self) -> bool
gvar table, whatever any one glyph has in it. Read moreSource§fn phantom_point_deltas(&self, glyph: GlyphId) -> Option<[Point<Fixed>; 4]>
fn phantom_point_deltas(&self, glyph: GlyphId) -> Option<[Point<Fixed>; 4]>
Source§fn gvar_scalars(&self) -> &[Fixed]
fn gvar_scalars(&self) -> &[Fixed]
gvar’s shared tuples at Self::coords, as
SelectedGvar::compute_scalars fills them. Read more