Skip to content

Commit

Permalink
parseLookup9 support + getKerningTables enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreRivet authored and Connum committed Nov 15, 2023
1 parent 9a024d2 commit 995ec63
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
);
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/tables/gpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions test/tables/gpos.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }]
]
});
});
});

0 comments on commit 995ec63

Please sign in to comment.