From 995ec63445f22abf476a21cbe3a8453c1ab3e403 Mon Sep 17 00:00:00 2001 From: Alexandre Rivet Date: Mon, 4 Oct 2021 14:17:22 +0200 Subject: [PATCH] parseLookup9 support + getKerningTables enhancement --- src/position.js | 10 +++++++++- src/tables/gpos.js | 5 ++++- test/tables/gpos.js | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/position.js b/src/position.js index 90c83410..96553c67 100644 --- a/src/position.js +++ b/src/position.js @@ -36,6 +36,8 @@ Position.prototype.getKerningValue = function(kerningLookups, leftIndex, rightIn const subtables = kerningLookups[i].subtables; for (let j = 0; j < subtables.length; j++) { const subtable = subtables[j]; + // Subtables not supported come with an error + if (subtable.error) continue; const covIndex = this.getCoverageIndex(subtable.coverage, leftIndex); if (covIndex < 0) continue; switch (subtable.posFormat) { @@ -72,7 +74,13 @@ Position.prototype.getKerningValue = function(kerningLookups, leftIndex, rightIn */ Position.prototype.getKerningTables = function(script, language) { if (this.font.tables.gpos) { - return this.getLookupTables(script, language, 'kern', 2); + const featureTable = this.getFeatureTable(script, language, 'kern'); + return this.getLookupTables( + script, + language, + 'kern', + featureTable && featureTable.lookupListIndexes.length ? this.font.tables.gpos.lookups[featureTable.lookupListIndexes[0]].lookupType : 2 + ); } }; diff --git a/src/tables/gpos.js b/src/tables/gpos.js index 32a7aceb..fdcdb478 100644 --- a/src/tables/gpos.js +++ b/src/tables/gpos.js @@ -82,7 +82,10 @@ subtableParsers[5] = function parseLookup5() { return { error: 'GPOS Lookup 5 no subtableParsers[6] = function parseLookup6() { return { error: 'GPOS Lookup 6 not supported' }; }; subtableParsers[7] = function parseLookup7() { return { error: 'GPOS Lookup 7 not supported' }; }; subtableParsers[8] = function parseLookup8() { return { error: 'GPOS Lookup 8 not supported' }; }; -subtableParsers[9] = function parseLookup9() { return { error: 'GPOS Lookup 9 not supported' }; }; +subtableParsers[9] = function parseLookup9() { + check.argument(this.parseUShort() === 1, 'GPOS lookup type 9 format must be 1.'); + return this.parsePointer32(subtableParsers[this.parseUShort()]); +}; // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos function parseGposTable(data, start) { diff --git a/test/tables/gpos.js b/test/tables/gpos.js index a2cde3c2..49edda67 100644 --- a/test/tables/gpos.js +++ b/test/tables/gpos.js @@ -138,4 +138,23 @@ describe('tables/gpos.js', function() { ] }); }); + + //// Lookup type 9 //////////////////////////////////////////////////////// + it('can parse lookup9 extensionLookupType2 PairPosFormat1', function() { + // https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookuptype-9-extension-positioning + const data = '0001 0002 00000008 0001 001E 0004 0001 0002 000E 0016 0001 0059 FFE2 FFEC 0001 0059 FFD8 FFE7 0001 0002 002D 0031'; + assert.deepEqual(parseLookup(9, data), { + posFormat: 1, + coverage: { + format: 1, + glyphs: [0x2d, 0x31] + }, + valueFormat1: 4, + valueFormat2: 1, + pairSets: [ + [{ secondGlyph: 0x59, value1: { xAdvance: -30 }, value2: { xPlacement: -20 } }], + [{ secondGlyph: 0x59, value1: { xAdvance: -40 }, value2: { xPlacement: -25 } }] + ] + }); + }); });