Fix reading cmap table

The data offset must be saved before parsing one entry and restored
thereafter.  Otherwise only the first table is parsed properly, and garbage
is returned for the rest.  Fails on i.e. georgiai.ttf.

When reading the glyphIds, divide count by 2 (we read 16-bit words).
This commit is contained in:
Mihai Bazon 2014-08-16 11:50:52 +03:00
parent 26a0753d6c
commit e61366b37f

View File

@ -32,6 +32,8 @@ class CmapEntry
@platformID = data.readUInt16()
@encodingID = data.readShort()
@offset = offset + data.readInt()
saveOffset = data.pos
data.pos = @offset
@format = data.readUInt16()
@ -58,7 +60,7 @@ class CmapEntry
idDelta = (data.readUInt16() for i in [0...segCount])
idRangeOffset = (data.readUInt16() for i in [0...segCount])
count = @length - data.pos + @offset
count = (@length - data.pos + @offset) / 2
glyphIds = (data.readUInt16() for i in [0...count])
for tail, i in endCode
@ -72,6 +74,8 @@ class CmapEntry
glyphId += idDelta[i] if glyphId isnt 0
@codeMap[code] = glyphId & 0xFFFF
data.pos = saveOffset
@encode: (charmap, encoding) ->
subtable = new Data
@ -186,4 +190,4 @@ class CmapEntry
subtable: subtable.data
maxGlyphID: nextID + 1
module.exports = CmapTable
module.exports = CmapTable