Skip to main content

Charmap

Struct Charmap 

Source
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 SharedFont

Implementations§

Source§

impl<'a> Charmap<'a>

Source

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.

Source

pub fn unicode_is_symbol(&self) -> bool

Returns whether Unicode lookup uses a Microsoft symbol subtable.

Source

pub fn unicode_is_mac_roman(&self) -> bool

Returns whether Unicode lookup uses a Mac Roman subtable.

Source

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.

Source

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.

Source

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.

Source

pub fn has_unicode_variants(&self) -> bool

Returns whether this font has a Unicode variation-sequence subtable.

Source

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.

Source

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.

Source

pub fn encodings(&self) -> impl Iterator<Item = Encoding> + 'a

Returns the selectable character mappings of this font.

More than one mapping can have the same kind. Keep the full Encoding value to select a mapping with map_code.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Clone for Charmap<'a>

Source§

fn clone(&self) -> Charmap<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Charmap<'a>

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Charmap<'a>

§

impl<'a> !UnwindSafe for Charmap<'a>

§

impl<'a> Freeze for Charmap<'a>

§

impl<'a> Send for Charmap<'a>

§

impl<'a> Sync for Charmap<'a>

§

impl<'a> Unpin for Charmap<'a>

§

impl<'a> UnsafeUnpin for Charmap<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.