class HexaPDF::Font::CMap


Represents a CMap, a mapping from character codes to CIDs (character IDs) or to their Unicode value.

See: PDF2.0 s9.7.5, s9.10.3; Adobe Technical Notes #5014 and #5411



The name of the CMap.


The ordering part of the CMap version.


The registry part of the CMap version.


The supplement part of the CMap version.


The writing mode of the CMap: 0 for horizontal, 1 for vertical writing.

Public Class Methods


Returns a string containing a ToUnicode CMap that represents the given code to Unicode codepoint mapping.

See: Writer#create_to_unicode_cmap


Creates a new CMap object by parsing a predefined CMap with the given name.

Raises an error if the given CMap is not found.


Creates a new CMap object.


Creates a new CMap object from the given string which needs to contain a valid CMap file.


Returns true if the given name specifies a predefined CMap.

Public Instance Methods

add_cid_mapping(code, cid)

Adds an individual mapping from character code to CID.

add_cid_range(start_code, end_code, start_cid)

Adds a CID range, mapping characters codes from start_code to end_code to CIDs starting with start_cid.

add_codespace_range(first, *rest)

Add a codespace range using an array of ranges for the individual bytes.

This means that the first range is checked against the first byte, the second range against the second byte and so on.

add_unicode_mapping(code, string)

Adds a mapping from character code to Unicode string in UTF-8 encoding.

add_unicode_range_mapping(start_code, end_code, start_values)

Adds a mapping from a range of character codes to strings starting with the given 16-bit integer values (representing the raw UTF-16BE characters).


Parses the string and returns all character codes.

An error is raised if the string contains invalid bytes.


Returns the CID for the given character code, or 0 if no mapping was found.


Returns the Unicode string in UTF-8 encoding for the given character code, or nil if no mapping was found.


Add all mappings from the given CMap to this CMap.