🐛 Add init function to only apply the hack once instead of per ligature

This commit is contained in:
kiliman
2020-05-12 12:05:21 -04:00
parent 6f3d00ae6d
commit 321486d19e
2 changed files with 28 additions and 19 deletions
+27 -19
View File
@@ -12,6 +12,32 @@ let lookupIndex = 0;
let chainIndex = 0;
const substLookupMap = {};
const initGsubTables = (_dom, options) => {
dom = _dom;
gsubDom = xpath.select('ttFont/GSUB', dom, true);
// look for 'calt' feature
featureListDom = xpath.select('FeatureList', gsubDom, true);
lookupListDom = xpath.select('LookupList', gsubDom, true);
if (options.italicsHack) {
// remove all features from FeatureList
Array.from(featureListDom.childNodes).forEach((c) => {
featureListDom.removeChild(c);
});
Array.from(xpath.select('ttFont/GSUB//FeatureIndex', dom)).forEach((c) => {
c.parentNode.removeChild(c);
});
// remove all lookups from LookupList
Array.from(lookupListDom.childNodes).forEach((c) =>
lookupListDom.removeChild(c)
);
}
};
const buildGsubTables = (_dom, ligature, options) => {
dom = _dom;
@@ -35,17 +61,6 @@ const buildGsubTables = (_dom, ligature, options) => {
// look for 'calt' feature
featureListDom = xpath.select('FeatureList', gsubDom, true);
if (options.italicsHack) {
// remove all features from FeatureList
Array.from(featureListDom.childNodes).forEach((c) =>
featureListDom.removeChild(c)
);
Array.from(xpath.select('ttFont/GSUB//FeatureIndex', dom)).forEach((c) =>
c.parentNode.removeChild(c);
);
}
let featureRecord;
const featureTag = xpath.select(
'FeatureRecord/FeatureTag[@value="calt"]',
@@ -77,14 +92,6 @@ const buildGsubTables = (_dom, ligature, options) => {
addFeatureToScriptList('DFLT', featureIndex);
addFeatureToScriptList('latn', featureIndex);
lookupListDom = xpath.select('LookupList', gsubDom, true);
if (options.italicsHack) {
// remove all lookups from LookupList
Array.from(lookupListDom.childNodes).forEach((c) =>
lookupListDom.removeChild(c)
);
}
lookupIndex = xpath.select('count(Lookup)', lookupListDom, true);
const lookupDom = createElementWithAttributes('Lookup', {
@@ -301,5 +308,6 @@ const appendChildren = (node, ...children) => {
//const serialize = dom => new XMLSerializer().serializeToString(dom);
exports.initGsubTables = initGsubTables;
exports.buildGsubTables = buildGsubTables;
exports.finalizeGsubTables = finalizeGsubTables;
+1
View File
@@ -269,6 +269,7 @@ const patchGlyphs = (dom, ligatures) => {
const patchGsub = (dom, ligatures, options) => {
// don't patch if no ligatures other than LIG
if (ligatures.length <= 1) return;
gsub.initGsubTables(dom, options);
ligatures.forEach((ligature) => {
// build gsub tables