pub struct Font { /* private fields */ }Expand description
The resolved, owned, editable font model.
use font_model::{Font, Glyph, GlyphId, Outline, Path};
// The smallest valid font: `.notdef` alone.
let font = Font::builder()
.units_per_em(1000)
.glyph(Glyph::new(GlyphId::NOTDEF, 500, 0, Outline::new()))
.build()
.expect("valid");
assert_eq!(font.glyph_count(), 1);
assert!(font.cmap().codepoints().is_empty());
assert!(font.glyph(GlyphId::new(9)).is_none());Implementations§
Source§impl Font
impl Font
Sourcepub fn builder() -> FontBuilder
pub fn builder() -> FontBuilder
Start building a font.
Sourcepub const fn units_per_em(&self) -> u16
pub const fn units_per_em(&self) -> u16
unitsPerEm in font units.
Sourcepub fn set_units_per_em(&mut self, units_per_em: u16)
pub fn set_units_per_em(&mut self, units_per_em: u16)
Set unitsPerEm.
Sourcepub const fn metrics(&self) -> &FontMetrics
pub const fn metrics(&self) -> &FontMetrics
The font-wide metrics header.
Sourcepub fn metrics_mut(&mut self) -> &mut FontMetrics
pub fn metrics_mut(&mut self) -> &mut FontMetrics
The font-wide metrics header, mutably.
Sourcepub fn glyph_count(&self) -> usize
pub fn glyph_count(&self) -> usize
Number of glyphs.
Sourcepub fn glyphs_mut(&mut self) -> &mut Vec<Glyph>
pub fn glyphs_mut(&mut self) -> &mut Vec<Glyph>
The glyph store, mutably — the editor’s entry point.
Sourcepub fn glyph_mut(&mut self, id: GlyphId) -> Option<&mut Glyph>
pub fn glyph_mut(&mut self, id: GlyphId) -> Option<&mut Glyph>
One glyph by id, mutably, None beyond the store.
Sourcepub fn codepoints(&self) -> CodePointSet
pub fn codepoints(&self) -> CodePointSet
The mapped codepoints, ascending.
Sourcepub fn names(&self) -> &[NameRecord]
pub fn names(&self) -> &[NameRecord]
The naming records.
Sourcepub fn names_mut(&mut self) -> &mut Vec<NameRecord>
pub fn names_mut(&mut self) -> &mut Vec<NameRecord>
The naming records, mutably.
Sourcepub const fn os2(&self) -> Option<&Os2Metrics>
pub const fn os2(&self) -> Option<&Os2Metrics>
The OS/2 metrics, when present.
Sourcepub fn os2_mut(&mut self) -> &mut Option<Os2Metrics>
pub fn os2_mut(&mut self) -> &mut Option<Os2Metrics>
The OS/2 metrics, mutably.
Sourcepub fn kerning_mut(&mut self) -> &mut Kerning
pub fn kerning_mut(&mut self) -> &mut Kerning
The kerning pairs, mutably.
Sourcepub fn kern(&self, left: GlyphId, right: GlyphId) -> i16
pub fn kern(&self, left: GlyphId, right: GlyphId) -> i16
The kerning adjustment between two glyphs, in font units.
Sourcepub fn tables(&self) -> &[(TableTag, Vec<u8>)]
pub fn tables(&self) -> &[(TableTag, Vec<u8>)]
The opaque tables carried through unchanged: (tag, bytes).
Sourcepub fn table(&self, tag: TableTag) -> Option<&[u8]>
pub fn table(&self, tag: TableTag) -> Option<&[u8]>
One opaque table’s bytes by tag, None when absent.
Sourcepub fn set_table(&mut self, tag: TableTag, data: Vec<u8>)
pub fn set_table(&mut self, tag: TableTag, data: Vec<u8>)
Store an opaque table, replacing any existing entry with that tag.
Sourcepub fn remove_table(&mut self, tag: TableTag) -> bool
pub fn remove_table(&mut self, tag: TableTag) -> bool
Drop an opaque table, returning whether it was present.
Sourcepub fn bbox(&self) -> Option<Bbox>
pub fn bbox(&self) -> Option<Bbox>
The union of every glyph’s bounding box, None for a font with no
ink at all.
Sourcepub fn encoding_subtables(&self) -> Vec<CmapSubtable>
pub fn encoding_subtables(&self) -> Vec<CmapSubtable>
A cmap subtable holding exactly the font’s codepoint set.
What a writer emits: format 4 below the BMP, format 12 above it.
Sourcepub fn validate(&self) -> Result<(), ModelError>
pub fn validate(&self) -> Result<(), ModelError>
Validate every invariant, naming the offending glyph and field.
§Errors
The first violation found, in this order: unitsPerEm, glyph store
density, per-glyph outline and advance, cmap monotonicity, cmap
references, then kerning references.
Sourcepub fn subset(&self, cps: &CodePointSet) -> Result<Font, ModelError>
pub fn subset(&self, cps: &CodePointSet) -> Result<Font, ModelError>
Subset the font to cps.
The result keeps .notdef, every glyph a requested codepoint maps to,
and nothing else. Glyph ids are reassigned densely and in ascending
original order, so the original id is preserved where it can be and
the store is always valid. Kerning pairs whose endpoints survive are
kept, remapped.
§Errors
ModelError::UnknownGlyph when a requested codepoint maps to a
glyph the font does not hold; plus whatever Font::validate reports
on the result, so a subset can never come back invalid.
Sourcepub fn recompute_metrics(&mut self)
pub fn recompute_metrics(&mut self)
Derive the metrics header from the current glyph store.
Sourcepub fn recompute_glyph_metrics(&mut self) -> Result<(), ModelError>
pub fn recompute_glyph_metrics(&mut self) -> Result<(), ModelError>
Recompute every glyph’s metrics from its outline.
§Errors
ModelError::AdvanceOverflow for a glyph too wide for hmtx.