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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.