Skip to content

GPOS lookupType 9 support #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make it log the error when it comes across one?

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 } }]
]
});
});
});