foliojs / fontkit

An advanced font engine for Node and the browser
1.45k stars 213 forks source link

Error when encoding a subsetted font with CFF #258

Open dreignier opened 3 years ago

dreignier commented 3 years ago

I have a font with a CFF table and I create a subset of it. Everything works fine until I try to encode it with the encodeStream method. I got the following error:

NodeError RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 255. Received -1
    at writeU_Int8 (internal/buffer.js:729:11)
    at Buffer.writeUInt8 (internal/buffer.js:739:10)
    at EncodeStream.<computed> [as writeUInt8] (/home/foo/sources/foo/node_modules/restructure/src/EncodeStream.js:37:29)
    at NumberT.encode (/home/foo/sources/foo/node_modules/restructure/src/Number.js:28:39)
    at Struct.encode (/home/foo/sources/foo/node_modules/restructure/src/Struct.js:110:16)
    at RangeArray.ArrayT.encode (/home/foo/sources/foo/node_modules/restructure/src/Array.js:88:19)
    at VersionedStruct.encode (/home/foo/sources/foo/node_modules/restructure/src/VersionedStruct.js:120:16)
    at VersionedStruct.encode (/home/foo/sources/foo/node_modules/restructure/src/VersionedStruct.js:126:18)
    at CFFSubset.encode (/home/foo/sources/foo/node_modules/fontkit/src/subset/CFFSubset.js:167:12)
    at /home/foo/sources/foo/node_modules/fontkit/src/subset/Subset.js:32:12

Am I doing anything wrong ?