diff --git a/src/opentype.mjs b/src/opentype.mjs index 7a3101e4..60e8eae2 100644 --- a/src/opentype.mjs +++ b/src/opentype.mjs @@ -310,8 +310,13 @@ function parseBuffer(buffer, opt={}) { metaTableEntry = tableEntry; break; case 'gasp': - table = uncompressTable(data, tableEntry); - font.tables.gasp = gasp.parse(table.data, table.offset); + try { + table = uncompressTable(data, tableEntry); + font.tables.gasp = gasp.parse(table.data, table.offset); + } catch (e) { + console.warn('Failed to parse gasp table, skipping.'); + console.warn(e); + } break; case 'SVG ': table = uncompressTable(data, tableEntry); diff --git a/src/tables/gasp.mjs b/src/tables/gasp.mjs index 068b348d..d31db8f6 100644 --- a/src/tables/gasp.mjs +++ b/src/tables/gasp.mjs @@ -34,9 +34,9 @@ function makeGaspTable(gasp) { {name: 'numRanges', type: 'USHORT', value: gasp.numRanges}, ]); - for (let i in gasp.numRanges) { - result.fields.push({name: 'rangeMaxPPEM', type: 'USHORT', value: gasp.numRanges[i].rangeMaxPPEM}); - result.fields.push({name: 'rangeGaspBehavior', type: 'USHORT', value: gasp.numRanges[i].rangeGaspBehavior}); + for (let i in gasp.gaspRanges) { + result.fields.push({name: 'rangeMaxPPEM', type: 'USHORT', value: gasp.gaspRanges[i].rangeMaxPPEM}); + result.fields.push({name: 'rangeGaspBehavior', type: 'USHORT', value: gasp.gaspRanges[i].rangeGaspBehavior}); } return result; diff --git a/test/tables/gasp.spec.mjs b/test/tables/gasp.spec.mjs index f22ce280..2ea91245 100644 --- a/test/tables/gasp.spec.mjs +++ b/test/tables/gasp.spec.mjs @@ -29,4 +29,9 @@ describe('tables/gasp.mjs', function () { assert.equal(font.tables.gasp.gaspRanges[1].rangeGaspBehavior, 0x0001 + 0x0002 + 0x0004 + 0x0008); // all flags set = 15 }); + it('can write tables that are read as identical to the original', function() { + const font2 = parse(font.toArrayBuffer()); + assert.deepStrictEqual(font.tables.gasp, font2.tables.gasp); + }); + });