pub enum CmapSubtable {
Format4 {
segments: Vec<Segment>,
glyph_ids: Vec<Vec<u16>>,
},
Format12 {
segments: Vec<Segment>,
},
}Expand description
The decoded, owned form of one cmap subtable.
Both modelled formats are segmented coverage: an ascending list of
[start, end] ranges whose glyph ids either run consecutively
(first_glyph + (cp − start), format 12 and format 4’s idDelta path) or
come from an explicit array (format 4’s glyphIndexArray).
Format 4’s glyph-index array is normalised away on decode: a segment that used the array becomes a segment whose glyphs are consecutive only if they genuinely are; otherwise the array values are kept as a per-codepoint table. Both encode back to a spec-valid subtable.
Variants§
Format4
Format 4: the BMP segment/delta form.
Fields
Format12
Format 12: segmented coverage, u32 codepoints.
Implementations§
Source§impl CmapSubtable
impl CmapSubtable
Sourcepub fn empty_format4() -> Self
pub fn empty_format4() -> Self
An empty format-4 subtable.
Sourcepub fn empty_format12() -> Self
pub fn empty_format12() -> Self
An empty format-12 subtable.
Sourcepub fn lookup(&self, cp: u32) -> Option<GlyphId>
pub fn lookup(&self, cp: u32) -> Option<GlyphId>
Map a codepoint to a glyph. None for “not mapped”: outside the
subtable’s plane, in a hole of an explicit glyph array, mapped to
glyph 0, or resolving to a glyph id beyond the u16 glyph space.
Sourcepub fn codepoints(&self) -> CodePointSet
pub fn codepoints(&self) -> CodePointSet
The mapped codepoints, ascending.
Sourcepub fn entries(&self) -> Vec<(u32, GlyphId)>
pub fn entries(&self) -> Vec<(u32, GlyphId)>
Every (codepoint, glyph) pair, ascending by codepoint. The inverse of
the encode path and what a writer iterates.
Sourcepub fn segments(&self) -> &[Segment]
pub fn segments(&self) -> &[Segment]
The segments, ascending. Empty for a subtable that maps nothing.
Sourcepub fn glyph_arrays(&self) -> &[Vec<u16>]
pub fn glyph_arrays(&self) -> &[Vec<u16>]
The explicit glyph-id arrays, one per format-4 segment; an empty inner
Vec means the segment is a delta (consecutive-glyph) segment.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Encode to cmap subtable bytes (no table header, just the subtable).
The output is spec-valid: format 4 ends with the mandatory
0xFFFF terminator segment, and every segment is ascending.
Sourcepub fn encode_format4(&self) -> Vec<u8> ⓘ
pub fn encode_format4(&self) -> Vec<u8> ⓘ
Encode as a format-4 subtable.
Sourcepub fn encode_format12(&self) -> Vec<u8> ⓘ
pub fn encode_format12(&self) -> Vec<u8> ⓘ
Encode as a format-12 subtable.
Sourcepub fn decode(data: &[u8]) -> Result<Self, ModelError>
pub fn decode(data: &[u8]) -> Result<Self, ModelError>
Decode a subtable from its bytes.
§Errors
ModelError::UnsupportedCmapFormat for anything other than formats 4
and 12; ModelError::Parse when the byte layout is inconsistent.
Sourcepub fn decode_format4(data: &[u8]) -> Result<Self, ModelError>
pub fn decode_format4(data: &[u8]) -> Result<Self, ModelError>
Sourcepub fn decode_format12(data: &[u8]) -> Result<Self, ModelError>
pub fn decode_format12(data: &[u8]) -> Result<Self, ModelError>
Sourcepub fn bmp_entries(&self) -> Vec<(u32, u32)>
pub fn bmp_entries(&self) -> Vec<(u32, u32)>
The BMP-only entries, ascending — the working set for a format-4 encode, and what a caller checks to decide whether a subtable needs a format-12 companion.
use font_model::{from_entries, GlyphId};
let sub = from_entries(&[(0x41, GlyphId::new(1)), (0x1F600, GlyphId::new(2))], 12);
assert_eq!(sub.bmp_entries(), vec![(0x41, 1)]);