From e61366b37fdb930a7283b59036e8e50afc150bb5 Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Sat, 16 Aug 2014 11:50:52 +0300 Subject: [PATCH] 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). --- lib/font/tables/cmap.coffee | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/font/tables/cmap.coffee b/lib/font/tables/cmap.coffee index 00b8a53..7a66f72 100644 --- a/lib/font/tables/cmap.coffee +++ b/lib/font/tables/cmap.coffee @@ -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 \ No newline at end of file +module.exports = CmapTable