Skip to content

Add UI names for Stylistic Set / Character Variants features #452

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 11 commits into
base: master
Choose a base branch
from
43 changes: 37 additions & 6 deletions dist/opentype.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/opentype.js.map

Large diffs are not rendered by default.

43 changes: 37 additions & 6 deletions dist/opentype.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/opentype.module.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/opentype.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ function parseBuffer(buffer, opt) {
if (gsubTableEntry) {
const gsubTable = uncompressTable(data, gsubTableEntry);
font.tables.gsub = gsub.parse(gsubTable.data, gsubTable.offset);
font.tables.gsub.features.forEach(f => {
if (f.tag.match(/ss(?:0[1-9]|1\d|20)/)) {
const { uiNameId } = f.feature.featureParamsTable;
f.feature.uiName = font.tables.name[uiNameId];
}
});
}

if (fvarTableEntry) {
Expand Down
22 changes: 17 additions & 5 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,16 @@ Parser.prototype.parseValueRecordList = function() {
return values;
};

Parser.prototype.parsePointer = function(description) {
Parser.prototype.parsePointer = function(description, storeOffset = false) {
const structOffset = this.parseOffset16();
if (structOffset > 0) {
// NULL offset => return undefined
return new Parser(this.data, this.offset + structOffset).parseStruct(description);
const offset = this.offset + structOffset;
const struct = new Parser(this.data, offset).parseStruct(description);
if (storeOffset) {
struct.tableOffset = offset;
}
return struct;
}
return undefined;
};
Expand Down Expand Up @@ -528,9 +533,9 @@ Parser.recordList32 = function(count, recordDescription) {
};
};

Parser.pointer = function(description) {
Parser.pointer = function(description, storeOffset = false) {
return function() {
return this.parsePointer(description);
return this.parsePointer(description, storeOffset);
};
};

Expand Down Expand Up @@ -578,10 +583,17 @@ Parser.prototype.parseFeatureList = function() {
feature: Parser.pointer({
featureParams: Parser.offset16,
lookupListIndexes: Parser.uShortList
})
}, true)
})) || [];
};

Parser.prototype.parseFeatureParams = function() {
return this.parsePointer({
version: Parser.uShort,
uiNameId: Parser.uShort
}) || [];
};

Parser.prototype.parseLookupList = function(lookupTableParsers) {
return this.parsePointer(Parser.list(Parser.pointer(function() {
const lookupType = this.parseUShort();
Expand Down
10 changes: 9 additions & 1 deletion src/tables/gsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,20 @@ function parseGsubTable(data, start) {
const tableVersion = p.parseVersion(1);
check.argument(tableVersion === 1 || tableVersion === 1.1, 'Unsupported GSUB table version.');
if (tableVersion === 1) {
return {
const table = {
version: tableVersion,
scripts: p.parseScriptList(),
features: p.parseFeatureList(),
lookups: p.parseLookupList(subtableParsers)
};
table.features.forEach(f => {
if (f.tag.match(/ss(?:0[1-9]|1\d|20)/)) {
const p = new Parser(data, f.feature.tableOffset);
f.feature.featureParamsTable = p.parseFeatureParams();
}
delete f.feature.tableOffset;
});
return table;
} else {
return {
version: tableVersion,
Expand Down
6 changes: 3 additions & 3 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ describe('parse.js', function() {
'0000 0001 0000 0000 0002 0000 0001 0000 0003 0000 0001 0002';
const p = new Parser(unhex(data), 0);
assert.deepEqual(p.parseFeatureList(), [
{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0] } },
{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0, 1] } },
{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0, 1, 2] } }
{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0], tableOffset: 24 } },
{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0, 1], tableOffset: 30 } },
{ tag: 'liga', feature: { featureParams: 0, lookupListIndexes: [0, 1, 2], tableOffset: 38 } }
]);
assert.equal(p.relativeOffset, 2);
});
Expand Down