Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/opentype.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/tables/gasp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions test/tables/gasp.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

});
Loading