Skip to content

Commit 995ec63

Browse files
AlexandreRivetConnum
authored andcommitted
parseLookup9 support + getKerningTables enhancement
1 parent 9a024d2 commit 995ec63

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/position.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Position.prototype.getKerningValue = function(kerningLookups, leftIndex, rightIn
3636
const subtables = kerningLookups[i].subtables;
3737
for (let j = 0; j < subtables.length; j++) {
3838
const subtable = subtables[j];
39+
// Subtables not supported come with an error
40+
if (subtable.error) continue;
3941
const covIndex = this.getCoverageIndex(subtable.coverage, leftIndex);
4042
if (covIndex < 0) continue;
4143
switch (subtable.posFormat) {
@@ -72,7 +74,13 @@ Position.prototype.getKerningValue = function(kerningLookups, leftIndex, rightIn
7274
*/
7375
Position.prototype.getKerningTables = function(script, language) {
7476
if (this.font.tables.gpos) {
75-
return this.getLookupTables(script, language, 'kern', 2);
77+
const featureTable = this.getFeatureTable(script, language, 'kern');
78+
return this.getLookupTables(
79+
script,
80+
language,
81+
'kern',
82+
featureTable && featureTable.lookupListIndexes.length ? this.font.tables.gpos.lookups[featureTable.lookupListIndexes[0]].lookupType : 2
83+
);
7684
}
7785
};
7886

src/tables/gpos.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ subtableParsers[5] = function parseLookup5() { return { error: 'GPOS Lookup 5 no
8282
subtableParsers[6] = function parseLookup6() { return { error: 'GPOS Lookup 6 not supported' }; };
8383
subtableParsers[7] = function parseLookup7() { return { error: 'GPOS Lookup 7 not supported' }; };
8484
subtableParsers[8] = function parseLookup8() { return { error: 'GPOS Lookup 8 not supported' }; };
85-
subtableParsers[9] = function parseLookup9() { return { error: 'GPOS Lookup 9 not supported' }; };
85+
subtableParsers[9] = function parseLookup9() {
86+
check.argument(this.parseUShort() === 1, 'GPOS lookup type 9 format must be 1.');
87+
return this.parsePointer32(subtableParsers[this.parseUShort()]);
88+
};
8689

8790
// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos
8891
function parseGposTable(data, start) {

test/tables/gpos.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,23 @@ describe('tables/gpos.js', function() {
138138
]
139139
});
140140
});
141+
142+
//// Lookup type 9 ////////////////////////////////////////////////////////
143+
it('can parse lookup9 extensionLookupType2 PairPosFormat1', function() {
144+
// https://docs.microsoft.com/en-us/typography/opentype/spec/gpos#lookuptype-9-extension-positioning
145+
const data = '0001 0002 00000008 0001 001E 0004 0001 0002 000E 0016 0001 0059 FFE2 FFEC 0001 0059 FFD8 FFE7 0001 0002 002D 0031';
146+
assert.deepEqual(parseLookup(9, data), {
147+
posFormat: 1,
148+
coverage: {
149+
format: 1,
150+
glyphs: [0x2d, 0x31]
151+
},
152+
valueFormat1: 4,
153+
valueFormat2: 1,
154+
pairSets: [
155+
[{ secondGlyph: 0x59, value1: { xAdvance: -30 }, value2: { xPlacement: -20 } }],
156+
[{ secondGlyph: 0x59, value1: { xAdvance: -40 }, value2: { xPlacement: -25 } }]
157+
]
158+
});
159+
});
141160
});

0 commit comments

Comments
 (0)