Font::TTF::Cmap(3)
π NAME π
Font::TTF::Cmap β the character map table, aka the girl who knows which codepoint goes with which glyph π
Like, hi bestie! Welcome to the manpage for Font::TTF::Cmap, a Perl module. Yes it's a real manual page, yes we're doing this, and yes you're gonna understand it. Slay. β¨
π¦ DESCRIPTION π¦
Okay so this module looks after the character map. That's its whole job and it ate, no cap.
And because it wants your life to be easy, the actual cmap is held in a hash against codepoint. So for a given table you just do:
$gid = $font->{'cmap'}{'Tables'}[0]{'val'}{$code};
One thing though, real talk: $code should be a true value (0x1234) rather than a string representation. Not me warning you twice, but likeβ¦ I am. π
πΈ INSTANCE VARIABLES πΈ
So the instance variables listed down here are not preceded by a space, and that's on purpose β it's because they're emulating structural information in the font. Iconic behaviour honestly.
Numβ the number of subtables in this tableTablesβ an array of subtables ([0..Num-1])
And each subtable also has its own instance variables, which are, again, not preceded by a space:
Platformβ the platform number for this subtableEncodingβ the encoding number for this subtableFormatβ gives the stored format of this subtableVerβ gives the version (or language) information for this subtablevalβ a hash keyed by the codepoint value (not a string) storing the glyph id
Then there are the following cmap options, and these ones are controlled by instance variables that do start with a space:
allowholesβ by default, when generating format 4 cmap subtables, character codes that point to glyph zero (normally called.notdef) are not included in the subtable. But sometimes including some of these character codes can result in a smaller format 4 subtable, which is lowkey a glow-up. To enable this behavior, setallowholesto non-zero. π«Ά
π METHODS π
$t->read
Reads the cmap into memory. Format 4 subtables read the whole subtable and fill in the segmented array accordingly. She's thorough, we love that for her. π
$t->ms_lookup($uni)
Finds a Unicode table β giving preference to the MS one β and looks up the given Unicode codepoint in it to find the glyph id. Main character energy: it goes straight for the Microsoft table first. π
$t->find_ms
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. (Yes, the original says "the a Unicode table" β I'm not fixing it, that's just her vibe.) π
$t->ms_enc
Returns the encoding of the microsoft table (0 => symbol, etc.). Returns undef if there is no Microsoft cmap. Sad but fair. π
$t->out($fh)
Writes out a cmap table to a filehandle. And if it has not been read yet? It just copies from input file to output. Effortless. β
$t->XML_element($context, $depth, $name, $val)
Outputs the elements of the cmap in XML. We only need to process val here β that's it, that's the whole assignment. π
$t->minsize()
Returns the minimum size this table can be in bytes. And if it's smaller than this, then the table must be bad and should be deleted or whatever. Not me being dramatic, that's literally what it says. π
$t->update
Tidies the cmap table. Spring cleaning, cmap edition π§Ήβ¨
- Removes MS Fmt12 cmap if it is no longer needed.
- Removes from all cmaps any codepoint that map to GID=0. And heads up: such entries will be re-introduced as necessary depending on the cmap format. So like, they come back. It's giving resurrection. π¦
@map = $t->reverse(%opt)
Returns a reverse map of the Unicode cmap. I.e. given a glyph gives the Unicode value for it. Flip it and reverse it π Options are:
tnum
Table number to use rather than the default Unicode table
array
Returns each element of reverse as an array since a glyph may be mapped by more than one Unicode value. The arrays are unsorted. Otherwise store any one unicode value for a glyph. Pick your fighter. π
is_unicode($index)
Returns whether the table of a given index is known to be a unicode table (as specified in the specifications). She said trust the specs, bestie. π
π BUGS π
- Format 14 (Unicode Variation Sequences) cmaps are not supported. Ngl, she simply does not do those. π
π AUTHOR π
Martin Hosken <http://scripts.sil.org/FontUtils>.
π LICENSING π
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
This module is released under the terms of the Artistic License 2.0. For details, see the full text of the license in the file LICENSE. Read it, bestie, it's giving responsible. π
Okay that's the whole page, ily, go map some characters π β¨
perl v5.42.0 π¦ 2016-08-28 π¦ Font::TTF::Cmap(3) β mwah, that's the sign-off, bye bestie! π«ΆπΈ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Font-TTF 1.06-bp160.1.12 Β· Artistic-2.0 and OFL-1.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms