pub struct Font {
pub units_per_em: u16,
pub num_glyphs: u16,
pub ascent: i16,
pub descent: i16,
pub line_gap: i16,
/* private fields */
}Expand description
A parsed font, owning its backing bytes.
Fields§
§units_per_em: u16Font design units per em (the coordinate scale; advances are in these).
num_glyphs: u16Number of glyphs in the font.
ascent: i16Typographic ascender (design units).
descent: i16Typographic descender (design units, usually negative).
line_gap: i16Recommended extra line gap (design units).
Implementations§
Source§impl Font
impl Font
Sourcepub fn glyph_outline(&self, gid: u16) -> Result<GlyphOutline, OutlineError>
pub fn glyph_outline(&self, gid: u16) -> Result<GlyphOutline, OutlineError>
Decode glyph gid to quadratic contours with phantom-point-correct
metrics. Blank glyphs (space) succeed with empty contours.
§Errors
OutlineError::NoGlyfOutlines for CFF-only fonts,
OutlineError::BadGlyphId for out-of-range ids, and
OutlineError::Malformed / OutlineError::BudgetExceeded for
structurally invalid or hostile glyph data.
Source§impl Font
impl Font
Sourcepub fn has_glyf_outlines(&self) -> bool
pub fn has_glyf_outlines(&self) -> bool
True when the font carries TrueType (glyf) outlines we can read/subset.
Sourcepub fn glyph_data(&self, gid: u16) -> Option<&[u8]>
pub fn glyph_data(&self, gid: u16) -> Option<&[u8]>
Raw glyf bytes for glyph gid (for subset embedding), or None.
An empty (zero-length) glyph yields Some(&[]).
Sourcepub fn glyph_bbox(&self, gid: u16) -> Option<[i16; 4]>
pub fn glyph_bbox(&self, gid: u16) -> Option<[i16; 4]>
Glyph bounding box [xMin, yMin, xMax, yMax] (design units), or None
for an empty glyph / no outlines.
Sourcepub fn is_composite(&self, gid: u16) -> bool
pub fn is_composite(&self, gid: u16) -> bool
True when glyph gid is a composite (built from component glyphs).
Sourcepub fn glyph_components(&self, gid: u16) -> Vec<u16>
pub fn glyph_components(&self, gid: u16) -> Vec<u16>
Component glyph ids referenced by a composite glyph (for transitive subsetting). Empty for simple or empty glyphs.
Sourcepub fn advance_width(&self, gid: u16) -> u16
pub fn advance_width(&self, gid: u16) -> u16
The advance width of glyph gid in design units. Glyphs past the
hmtx metric run share the last advance (monospaced trailing run).
Sourcepub fn left_side_bearing(&self, gid: u16) -> i16
pub fn left_side_bearing(&self, gid: u16) -> i16
The left side bearing of glyph gid in design units. Glyphs past the
long-metric run share the last advance but keep their own trailing LSB.
Sourcepub fn glyph_index(&self, ch: char) -> u16
pub fn glyph_index(&self, ch: char) -> u16
The glyph id for a character, or 0 (.notdef) if unmapped.
Sourcepub fn advance_1000(&self, ch: char) -> u32
pub fn advance_1000(&self, ch: char) -> u32
Advance width of ch in 1/1000 em (PDF text-space units). An unmapped
ch resolves to glyph 0 (.notdef) and reserves that glyph’s advance
(so a tofu box still occupies its natural width); only an unparsable face
with units_per_em == 0 yields 0.
Sourcepub fn kerning_between_glyphs(&self, left: u16, right: u16) -> i16
pub fn kerning_between_glyphs(&self, left: u16, right: u16) -> i16
Kerning adjustment between two glyph ids in design units.
Unsupported or absent kerning tables return zero. This currently supports
legacy TrueType/Microsoft kern table version 0, format 0, horizontal
pairs. GPOS pair positioning is tracked separately.
Sourcepub fn kerning(&self, left: char, right: char) -> i16
pub fn kerning(&self, left: char, right: char) -> i16
Kerning adjustment between two characters in design units.
Sourcepub fn kerning_1000(&self, left: char, right: char) -> i32
pub fn kerning_1000(&self, left: char, right: char) -> i32
Kerning adjustment between two characters in 1/1000 em units.
Sourcepub fn subset(&self, keep: &[char]) -> Option<Vec<u8>>
pub fn subset(&self, keep: &[char]) -> Option<Vec<u8>>
Build a new, minimal, valid TrueType (glyf) font containing glyph 0
(.notdef) plus exactly the glyphs needed to render keep (mapped
through the original cmap), transitively closing over composite
components. Returns a fresh sfnt (0x00010000) suitable for a PDF
FontFile2, or None on any failure (missing glyf/loca/required
table, or a malformed read).
Sourcepub fn subset_glyphs(
&self,
glyphs: &[u16],
cmap_chars: &[char],
) -> Option<(Vec<u8>, BTreeMap<u16, u16>)>
pub fn subset_glyphs( &self, glyphs: &[u16], cmap_chars: &[char], ) -> Option<(Vec<u8>, BTreeMap<u16, u16>)>
Subset to an explicit glyph set (the closure still pulls in composite
components), building the cmap from cmap_chars. Returns the font bytes
plus the old->new glyph id remap — for callers that pre-shaped a glyph
sequence (e.g. GSUB ligatures) and must emit the renumbered ids.
§Errors
Returns None for a font without glyf/loca outlines or on a malformed
read (same conditions as Font::subset).