From 235943a0fc731d8b0a4a3c5d881005d65742b0ea Mon Sep 17 00:00:00 2001 From: Balearica Date: Mon, 8 Jul 2024 00:01:43 -0700 Subject: [PATCH 1/3] Fixed gasp support bugs per #738 --- src/opentype.mjs | 9 +++++++-- src/tables/gasp.mjs | 6 +++--- 2 files changed, 10 insertions(+), 5 deletions(-) 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; From 5e91e9cf0e4cd44ea1ffc3dd9343e225113db506 Mon Sep 17 00:00:00 2001 From: Balearica Date: Tue, 9 Jul 2024 01:15:10 -0700 Subject: [PATCH 2/3] Added test for gasp table writing --- test/tables/gasp.spec.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/tables/gasp.spec.mjs b/test/tables/gasp.spec.mjs index f22ce280..65c5a967 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.strictEqual(JSON.stringify(font.tables.gasp), JSON.stringify(font2.tables.gasp)); + }); + }); From c436359bdfb121256c0ba56cea91567461459af7 Mon Sep 17 00:00:00 2001 From: Balearica Date: Thu, 11 Jul 2024 22:07:17 -0700 Subject: [PATCH 3/3] Minor update to test --- test/tables/gasp.spec.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tables/gasp.spec.mjs b/test/tables/gasp.spec.mjs index 65c5a967..2ea91245 100644 --- a/test/tables/gasp.spec.mjs +++ b/test/tables/gasp.spec.mjs @@ -31,7 +31,7 @@ describe('tables/gasp.mjs', function () { it('can write tables that are read as identical to the original', function() { const font2 = parse(font.toArrayBuffer()); - assert.strictEqual(JSON.stringify(font.tables.gasp), JSON.stringify(font2.tables.gasp)); + assert.deepStrictEqual(font.tables.gasp, font2.tables.gasp); }); });