Skip to content

Commit aa8ad76

Browse files
authored
Fixed gasp support bugs per #738 (#739)
* Fixed gasp support bugs per #738 * Added test for gasp table writing * Minor update to test
1 parent b4c4b96 commit aa8ad76

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

src/opentype.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,13 @@ function parseBuffer(buffer, opt={}) {
310310
metaTableEntry = tableEntry;
311311
break;
312312
case 'gasp':
313-
table = uncompressTable(data, tableEntry);
314-
font.tables.gasp = gasp.parse(table.data, table.offset);
313+
try {
314+
table = uncompressTable(data, tableEntry);
315+
font.tables.gasp = gasp.parse(table.data, table.offset);
316+
} catch (e) {
317+
console.warn('Failed to parse gasp table, skipping.');
318+
console.warn(e);
319+
}
315320
break;
316321
case 'SVG ':
317322
table = uncompressTable(data, tableEntry);

src/tables/gasp.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ function makeGaspTable(gasp) {
3434
{name: 'numRanges', type: 'USHORT', value: gasp.numRanges},
3535
]);
3636

37-
for (let i in gasp.numRanges) {
38-
result.fields.push({name: 'rangeMaxPPEM', type: 'USHORT', value: gasp.numRanges[i].rangeMaxPPEM});
39-
result.fields.push({name: 'rangeGaspBehavior', type: 'USHORT', value: gasp.numRanges[i].rangeGaspBehavior});
37+
for (let i in gasp.gaspRanges) {
38+
result.fields.push({name: 'rangeMaxPPEM', type: 'USHORT', value: gasp.gaspRanges[i].rangeMaxPPEM});
39+
result.fields.push({name: 'rangeGaspBehavior', type: 'USHORT', value: gasp.gaspRanges[i].rangeGaspBehavior});
4040
}
4141

4242
return result;

test/tables/gasp.spec.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ describe('tables/gasp.mjs', function () {
2929
assert.equal(font.tables.gasp.gaspRanges[1].rangeGaspBehavior, 0x0001 + 0x0002 + 0x0004 + 0x0008); // all flags set = 15
3030
});
3131

32+
it('can write tables that are read as identical to the original', function() {
33+
const font2 = parse(font.toArrayBuffer());
34+
assert.deepStrictEqual(font.tables.gasp, font2.tables.gasp);
35+
});
36+
3237
});

0 commit comments

Comments
 (0)