Wondering what the "character codes" are for the cmap table in TrueType fonts. Microsoft talks about the Character to Glyph Index Mapping Table, but I don't see what the character or glyph index mean.
Wondering if somewhere in the font file you specify the encoding, such as Unicode 11.0, and then the character codes are equal to the Unicode code points such as U+0061
for a
. Or if the character codes are instead the "browser" character codes (decimal codes I guess), such as 97
for a
.
Basically wondering how you map keyboard characters to font glyphs, and what that really means. I think you not so much want to map keyboard codes to the font glyphs, but unicode codes like U+0061
to the font glyphs, so if in JavaScript (for example) you can do \u03A9
and it will give you Ω
if your font supports that.
Trying to understand the anatomy of a font file in terms of how it maps the mathematical glyphs as vectors/paths, to characters or codes of some sort.
The short, but perhaps not desired, answer is of course "read the OpenType spec. It takes a while", so a slightly longer, but easier and less detailed answer would be http://pomax.github.io/CFF-glyphlet-fonts, although that skips over TTF so let's look at that here:
Your input code gets run through whatever is the applicable CMAP given the context you're applying the font to, which maps the computer's code (ascii code, unicode code point, ISO-2022-jp, what have you) to a glyph id. For TTF specifically, that id is then used as array offset in the "loca" table, which is the "glyph index to data location" table and specifies the byte offset in the "glyf" table for each glyph that the font contains. You then consult the glyf table at that byte offset, and start parsing the bytes as specified by https://learn.microsoft.com/en-us/typography/opentype/spec/glyf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With