pub struct Charmap<'a> {
font: &'a SharedFont,
}Expand description
Character mappings for a font.
Obtain this facade with Font::charmap. It offers two ways to map
characters, depending on what the caller knows about its input.
§Unicode lookup
map_unicode accepts a Unicode codepoint (or char).
For an SFNT font, it uses one selected cmap subtable, with a preference
for a Microsoft symbol subtable, then full Unicode, then BMP Unicode, and
finally Mac Roman. A symbol subtable retries codes in U+0000..U+00FF at
U+F000..U+F0FF when the direct lookup fails; unicodes
lists only the codes the subtable holds. A Mac Roman subtable converts
Unicode codepoints to Mac Roman character codes before lookup. For Type 1 and standalone CFF
fonts, the Unicode map is derived from glyph names when the agl feature is
enabled. Glyph ID 0 is treated as unmapped.
An optional DMAP table takes precedence, with missing mappings falling
back to cmap (ISO/IEC 14496-22:2026, 5.6.15).
map_unicode_batched writes several results
while reusing the selected subtable and, for formats 4 and 12, the preceding
segment or group when possible.
map_unicode_variant uses the last SFNT
cmap variation sequences subtable, preferring format 15 to format 14. A non-default variation sequence names its glyph
directly; a default sequence resolves through the selected Unicode map.
Type 1 and standalone CFF fonts have no variation-sequence map.
The corresponding iterators are unicodes and
unicode_variants.
§Individual encodings
encodings lists each supported SFNT cmap encoding
record separately, including multiple records with the same
EncodingKind. It also lists native and glyph-name-derived Unicode
encodings for Type 1 and standalone CFF fonts when available. Keep the complete
Encoding value to select that specific mapping with
map_code or codes.
These methods use character codes in the selected encoding as stored in
the font. They do not convert Mac Roman codes from Unicode or apply the
Microsoft symbol fallback. A mapping to glyph ID 0 is treated as unmapped.
DMAP overrides are applied to matching encodings, and encodings supplied
only by DMAP are also available.
The selected Unicode subtable and the individual encoding records are parsed and cached separately, only when their respective methods need them.
Fields§
§font: &'a SharedFontImplementations§
Source§impl<'a> Charmap<'a>
impl<'a> Charmap<'a>
Sourcepub fn has_unicode(&self) -> bool
pub fn has_unicode(&self) -> bool
Returns whether this font has a selected Unicode mapping.
For Type 1 fonts, this requires a nonempty glyph-name-derived map.
Sourcepub fn unicode_is_symbol(&self) -> bool
pub fn unicode_is_symbol(&self) -> bool
Returns whether Unicode lookup uses a Microsoft symbol subtable.
Sourcepub fn unicode_is_mac_roman(&self) -> bool
pub fn unicode_is_mac_roman(&self) -> bool
Returns whether Unicode lookup uses a Mac Roman subtable.
Sourcepub fn map_unicode(&self, codepoint: impl Into<u32>) -> Option<GlyphId>
pub fn map_unicode(&self, codepoint: impl Into<u32>) -> Option<GlyphId>
Maps a Unicode codepoint to a glyph.
Type 1 and standalone CFF fonts use a glyph-name-based map when the
agl feature is enabled.
A mapping to glyph 0 is treated as unmapped.
Sourcepub fn map_unicode_batched<'o>(
&self,
codepoints: impl Iterator<Item = (u32, &'o mut GlyphId)>,
) -> usize
pub fn map_unicode_batched<'o>( &self, codepoints: impl Iterator<Item = (u32, &'o mut GlyphId)>, ) -> usize
Writes the Unicode mapping of each codepoint to its slot, in order.
Unmapped codepoints, including mappings to glyph 0, receive
GlyphId::NOTDEF. Returns the number of initial consecutive nonzero
mappings, while still writing every output. This uses
the same selected mapping, Mac Roman conversion, and Microsoft symbol
fallback as map_unicode.
Sourcepub fn unicodes(&self) -> impl Iterator<Item = (u32, GlyphId)> + 'a
pub fn unicodes(&self) -> impl Iterator<Item = (u32, GlyphId)> + 'a
Iterates over Unicode codepoints and their resolved glyph IDs.
A Microsoft symbol subtable yields only the codes it contains.
map_unicode also maps U+0000..U+00FF through
U+F000..U+F0FF, but those codes are not included.
Type 1 and standalone CFF mappings are derived from glyph names when
agl is enabled.
Sourcepub fn has_unicode_variants(&self) -> bool
pub fn has_unicode_variants(&self) -> bool
Returns whether this font has a Unicode variation-sequence subtable.
Sourcepub fn map_unicode_variant(
&self,
codepoint: impl Into<u32>,
selector: impl Into<u32>,
) -> Option<GlyphId>
pub fn map_unicode_variant( &self, codepoint: impl Into<u32>, selector: impl Into<u32>, ) -> Option<GlyphId>
Maps a Unicode codepoint and variation selector to a glyph.
A default UVS entry resolves through map_unicode.
A mapping to glyph 0 is treated as unmapped.
Sourcepub fn unicode_variants(&self) -> impl Iterator<Item = (u32, u32, GlyphId)> + 'a
pub fn unicode_variants(&self) -> impl Iterator<Item = (u32, u32, GlyphId)> + 'a
Iterates over Unicode variation sequences and their resolved glyph IDs.
Default variation entries use the selected Unicode mapping, just as
map_unicode_variant does.
Yields (codepoint, selector, glyph) tuples, where glyph is the
resolved glyph ID.
Sourcepub fn map_code(&self, encoding: Encoding, code: u32) -> Option<GlyphId>
pub fn map_code(&self, encoding: Encoding, code: u32) -> Option<GlyphId>
Maps a character code through a mapping returned by encodings.
The code is interpreted in the selected encoding, without Unicode conversion. The encoding must come from this font. A mapping to glyph 0 is treated as unmapped.
Sourcepub fn codes(
&self,
encoding: Encoding,
) -> impl Iterator<Item = (u32, GlyphId)> + 'a
pub fn codes( &self, encoding: Encoding, ) -> impl Iterator<Item = (u32, GlyphId)> + 'a
Iterates over character codes and glyph IDs in the selected encoding.
The encoding must come from this font’s encodings.
Codes are returned as stored in the encoding; Mac Roman conversion and
symbol fallback are only used by the Unicode methods. Mappings to glyph
0 are omitted.