Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft OpenType specification for cmap

Tags:

truetype

The cmap table in OpenType files translates a character code into a glyph ID.

Could any one help me to understand the C expression:

*(idRangeOffset[i]/2 + (c - startCount[i]) + &idRangeOffset[i])

Here is the Format 4 cmap subtable.

like image 928
Ayrosa Avatar asked Apr 21 '11 12:04

Ayrosa


2 Answers

So, in that expression i = segment index and c = character code. idRangeOffset gets the offset of the segment into a glyphIdArray inside the cmap. The value you're actually looking for in this case is glyphIdArray[something]. Since glyphIdArray immediately follows idRangeOffset in the font file, you use idRangeOffset as the base pointer.

To get to the start of the glyphIdArray you need to add the idRangeOffset, but since that value is in bytes and the idRangeOffset table is 16bit, you need to divide by 2 to get the word count. You then get the offset of segment i inside the glyphIdArray.

Your character's offset however inside this segment is at c - startCount[i] so you need to add that as well.

The final expression is a pointer so you need to dereference it to actually get the glyph's index.

This index is then used for the LOCA table.

like image 76
Dan Filimon Avatar answered Dec 29 '22 13:12

Dan Filimon


Not sure if you still need it, but I share my findings for someone looking around.

&idRangeOffset[i] refers to the address of idRangeOffset[i], or in the document's speech, the offset from beginning of the file.

*(x) is the content of the address of x.

So, find the address of idRangeOffset[i], add it to idRangeOffset[i]/2 + (c - startCount[i]), the result will be another address. The content of that address is the glyph id you want.

like image 21
Bong Avatar answered Dec 29 '22 13:12

Bong