pub struct Cmap { /* private fields */ }Expand description
A font’s character map: one or more modelled subtables.
Lookup tries the subtables in order and returns the first hit, mirroring the parser’s spec-preference scan while staying in the owned model.
Implementations§
Source§impl Cmap
impl Cmap
Sourcepub fn format4() -> Self
pub fn format4() -> Self
A cmap with one empty format-4 subtable — the minimum every font
carries.
Sourcepub fn subtables(&self) -> &[CmapSubtable]
pub fn subtables(&self) -> &[CmapSubtable]
The subtables, in lookup order.
Sourcepub fn subtables_mut(&mut self) -> &mut Vec<CmapSubtable>
pub fn subtables_mut(&mut self) -> &mut Vec<CmapSubtable>
The subtables, mutably.
Sourcepub fn preferred(&self) -> Option<&CmapSubtable>
pub fn preferred(&self) -> Option<&CmapSubtable>
The subtable a writer should emit first: format 12 when the font has
one (it covers every codepoint), otherwise the first format-4 subtable.
None for an empty cmap.
Sourcepub fn lookup(&self, cp: u32) -> Option<GlyphId>
pub fn lookup(&self, cp: u32) -> Option<GlyphId>
Map a codepoint to a glyph across every subtable.
Sourcepub fn codepoints(&self) -> CodePointSet
pub fn codepoints(&self) -> CodePointSet
The union of every subtable’s mapped codepoints.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encode the whole cmap table (header + encoding records + subtables),
writing one encoding record per subtable: (3, 1) for format 4 and
(3, 10) for format 12.
Sourcepub fn decode(data: &[u8]) -> Result<Self, ModelError>
pub fn decode(data: &[u8]) -> Result<Self, ModelError>
Decode a whole cmap table: header, encoding records, and every
subtable they point at.
§Errors
ModelError::Parse when the header or records are inconsistent, or
ModelError::UnsupportedCmapFormat for a subtable format outside the
modelled set.
Sourcepub fn decode_subtable(data: &[u8]) -> Result<CmapSubtable, ModelError>
pub fn decode_subtable(data: &[u8]) -> Result<CmapSubtable, ModelError>
Decode a standalone subtable (no cmap header) — what
CmapSubtable::encode produced.
§Errors
See CmapSubtable::decode.
Sourcepub fn subtable_format4() -> CmapSubtable
pub fn subtable_format4() -> CmapSubtable
An empty format-4 subtable, for building.
Sourcepub fn subtable_format12() -> CmapSubtable
pub fn subtable_format12() -> CmapSubtable
An empty format-12 subtable, for building.
Sourcepub fn validate(&self) -> Result<(), ModelError>
pub fn validate(&self) -> Result<(), ModelError>
Check the monotonicity invariant across every subtable.
§Errors
ModelError::NonMonotonicCmap naming the subtable index and the two
codepoints that broke the ordering.