Skip to content

Commit

Permalink
Fixed gasp support bugs per #738 (#739)
Browse files Browse the repository at this point in the history
* Fixed gasp support bugs per #738

* Added test for gasp table writing

* Minor update to test
  • Loading branch information
Balearica authored Sep 9, 2024
1 parent b4c4b96 commit aa8ad76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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);
});

});

0 comments on commit aa8ad76

Please sign in to comment.