vidstige / NRasterizer

OpenType parser in pure c#
Apache License 2.0
38 stars 11 forks source link

fixed cmap glyphIdArrayLength #20

Closed prepare closed 7 years ago

prepare commented 7 years ago

I found a bug in cmap's calculation of glyphIdArrayLength I test with tahoma font, on Windows

with character unicode3652 => ไ

"IndexOutOfRange exception"

cmap_err

I reviewed what size of the glyphIdArray should be, according to //https://www.microsoft.com/typography/otspec/cmap.htm

This obscure indexing trick works because glyphIdArray immediately follows idRangeOffset in the font file. The C expression that yields the glyph index is:

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

so, I fixed it as describe in picture below.

cmap_glyphidarray


I also send you a pull request, but you can just copy-n-paste.

vidstige commented 7 years ago

Fixed in #21. Thank you!