foliojs / fontkit

An advanced font engine for Node and the browser
1.49k stars 219 forks source link

Unknown version 32464 #161

Open jackytwh opened 6 years ago

jackytwh commented 6 years ago

Here is the code:

var fontkit = require('fontkit');
var font = fontkit.openSync('TravelingTypewriter.otf');
var run = font.layout('hello world!');

Here is the output:

/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/VersionedStruct.js:42
        throw new Error("Unknown version " + res.version);
        ^

Error: Unknown version 32464
    at VersionedStruct.decode (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/VersionedStruct.js:42:15)
    at /Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Pointer.js:69:30
    at Pointer.decode (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Pointer.js:79:16)
    at VersionedStruct.Struct._parseFields (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Struct.js:53:22)
    at VersionedStruct.decode (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/VersionedStruct.js:47:12)
    at /Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Pointer.js:69:30
    at Pointer.decode (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Pointer.js:79:16)
    at VersionedStruct.Struct._parseFields (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Struct.js:53:22)
    at VersionedStruct.decode (/Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/VersionedStruct.js:47:12)
    at /Users/Jackytwh/Desktop/logomaster/common-helper/node_modules/restructure/src/Pointer.js:69:30

The font is attached. Fontkit version is 1.7.7.

andika-regular.otf.zip

Pomax commented 6 years ago

This font appears to be incredibly broken. Fontval shows about a million GPOS errors, and running the otf through TTX yields:

Dumping "..\andika-regular.otf" to "..\andika-regular.ttx"...
Dumping 'GlyphOrder' table...
Dumping 'head' table...
Dumping 'hhea' table...
Dumping 'maxp' table...
Dumping 'OS/2' table...
Dumping 'name' table...
Dumping 'cmap' table...
Dumping 'post' table...
Dumping 'CFF ' table...
Dumping 'FFTM' table...
Dumping 'GDEF' table...
WARNING: Unknown Coverage format: 32464
WARNING: Unknown Coverage format: 29464
WARNING: Unknown Coverage format: 32072
WARNING: Unknown Coverage format: 29594
ERROR: An exception occurred during the decompilation of the 'GPOS' table
Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\ttFont.py", line 366, in __getitem__
    return self.tables[tag]
KeyError: 'GPOS'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\ttFont.py", line 385, in __getitem__
    table.decompile(data, self)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 42, in decompile
    self.table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 626, in decompile
    table[conv.name] = conv.read(reader, font, table)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 507, in read
    table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 622, in decompile
    table[conv.name] = conv.readArray(reader, font, table, countValue)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 145, in readArray
    l.append(self.read(reader, font, tableDict))
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 507, in read
    table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 622, in decompile
    table[conv.name] = conv.readArray(reader, font, table, countValue)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 145, in readArray
    l.append(self.read(reader, font, tableDict))
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 507, in read
    table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 626, in decompile
    table[conv.name] = conv.read(reader, font, table)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 507, in read
    table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 626, in decompile
    table[conv.name] = conv.read(reader, font, table)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 507, in read
    table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 622, in decompile
    table[conv.name] = conv.readArray(reader, font, table, countValue)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 145, in readArray
    l.append(self.read(reader, font, tableDict))
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 390, in read
    table.decompile(reader, font)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 626, in decompile
    table[conv.name] = conv.read(reader, font, table)
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otConverters.py", line 223, in read
    return reader.readUShort()
  File "c:\program files\python36\lib\site-packages\fontTools\ttLib\tables\otBase.py", line 134, in readUShort
    value, = struct.unpack(">H", self.data[pos:newpos])
struct.error: unpack requires a buffer of 2 bytes
Dumping 'GPOS' table...
Dumping 'GSUB' table...
Dumping 'hmtx' table...

That might look like TTX is succeeding where Fontkit isn't, but what really happens is that there is byte corruption in the GPOS table, and TTX just happens to try to keep reading even though what it thinks it's reading is completely nonsense after the first error.

The solution here is probably to get a new copy of the font and verify that this new copy is not broken, or if it is letting the foundry that makes it know they have released a broken font and using a different font in your codebase instead.

On the fontkit side, it would probably also be useful if the error wasn't just "Unknown version 32464" but also indicated which structure hierarchy that error occurred in /cc @devongovett