class HexaPDF::Font::TrueType::Table::CmapSubtable


Generic base class for all cmap subtables.

cmap format 8.0 is currently not implemented because use of the format is discouraged in the specification and no font with a format 8.0 cmap subtable was available for testing.

The preferred cmap format is 12.0 because it supports all of Unicode and allows for fast and memory efficient code-to-gid as well as gid-to-code mappings.




The platform identifier for Microsoft.


The platform identifier for Unicode.



The complete code map.

Is only fully initialized for existing fonts when a mapping is first accessed via [].


The platform-specific encoding identifier.


The cmap format or nil if the subtable wasn’t read from a file.


The complete gid map.

Is only fully initialized for existing fonts when a mapping is first accessed via gid_to_code.


The language code.


The platform identifier.

Public Class Methods

new(platform_id, encoding_id)

Creates a new subtable.

Public Instance Methods


Returns the glyph index for the given character code or nil if the character code is not mapped.


Returns a character code for the given glyph index or nil if the given glyph index does not exist or is not mapped to a character code.

Note that some fonts map multiple character codes to the same glyph (e.g. hyphen and minus), i.e. the code-to-glyph mapping is surjective but not injective! In such a case one of the available character codes is returned.

parse!(io, offset) → true or false

Parses the cmap subtable from the IO at the given offset.

If the subtable format is supported, the information is used to populate this object and true is returned. Otherwise nothing is done and false is returned.


Returns true if this subtable contains a Unicode cmap.