From 321486d19ea3fe1916e7e13f68853f0da51d2c47 Mon Sep 17 00:00:00 2001 From: kiliman Date: Tue, 12 May 2020 12:05:21 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Add=20init=20function=20to=20onl?= =?UTF-8?q?y=20apply=20the=20hack=20once=20instead=20of=20per=20ligature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gsub.js | 46 +++++++++++++++++++++++++++------------------- index.js | 1 + 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/gsub.js b/gsub.js index d8bfe3e..7fe456e 100644 --- a/gsub.js +++ b/gsub.js @@ -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; diff --git a/index.js b/index.js index bf2bd13..afec6c9 100644 --- a/index.js +++ b/index.js @@ -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