mirror of
https://github.com/kiliman/operator-mono-lig.git
synced 2026-08-12 02:10:52 +02:00
🐛 Add init function to only apply the hack once instead of per ligature
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user