Font::TTF::Cmap - Character map table


Font::TTF::Cmap - Character map table


Looks after the character map. For ease of use, the actual cmap is held in a hash against codepoint. Thus for a given table:

    $gid = $font->{'cmap'}{'Tables'}[0]{'val'}{$code};

Note that $code should be a true value (0x1234) rather than a string representation.


The instance variables listed here are not preceeded by a space due to their emulating structural information in the font.

Number of subtables in this table

An array of subtables ([0..Num-1])

Each subtables also has its own instance variables which are, again, not preceeded by a space.

The platform number for this subtable

The encoding number for this subtable

Gives the stored format of this subtable

Gives the version (or language) information for this subtable

A hash keyed by the codepoint value (not a string) storing the glyph id



Reads the cmap into memory. Format 4 subtables read the whole subtable and fill in the segmented array accordingly.

Format 2 subtables are not read at all.


Finds a Unicode table, giving preference to the MS one, and looks up the given Unicode codepoint in it to find the glyph id.


Finds the a Unicode table, giving preference to the Microsoft one, and sets the mstable instance variable to it if found. Returns the table it finds.


Returns the encoding of the microsoft table (0 => symbol, etc.). Returns undef if there is no Microsoft cmap.


Writes out a cmap table to a filehandle. If it has not been read, then just copies from input file to output

$t->XML_element($context, $depth, $name, $val)

Outputs the elements of the cmap in XML. We only need to process val here

@map = $t->reverse([$num])

Returns a reverse map of the table of given number or the Unicode cmap. I.e. given a glyph gives the Unicode value for it.


Returns whether the table of a given index is known to be a unicode table (as specified in the specifications)



Martin Hosken See the Font::TTF::Font manpage for copyright and licensing.

 Font::TTF::Cmap - Character map table