From 9cef42b1fbfd564ccbbd0d20fe925270b2733d33 Mon Sep 17 00:00:00 2001 From: Kiliman Date: Tue, 23 Jul 2019 15:47:27 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20errors=20if=20glyphs=20don?= =?UTF-8?q?'t=20exist=20for=20other=20font=20weights?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index bca04cf..311be22 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,8 @@ const buildFont = profile => { ) .filter(name => !/\d+\.liga$/.test(name)) // skip alternates (ends with .#) .filter(name => filterLigatures(name, profile.ligatures)) - .map(name => mapLigatures(name, profile.ligatures)); + .map(name => mapLigatures(name, profile.ligatures)) + .filter(entry => filterGlyphsExists(entry)); const ligaturesWithLIG = ligatures; //[...ligatures, { name: 'LIG', glyph: 'LIG' }]; @@ -130,6 +131,11 @@ const mapLigatures = (name, ligatures) => { return entry; }; +const filterGlyphsExists = ({ glyph }) => { + const exists = fs.existsSync(`./ligature/${ligFontName}/glyphs/${glyph}.xml`); + return exists; +}; + const sortLigatures = ligatures => { // sort by most glyphs then alphabetically const sorted = ligatures @@ -256,6 +262,9 @@ const patchGlyphs = (dom, ligatures) => { }; const patchGsub = (dom, ligatures) => { + // don't patch if no ligatures other than LIG + if (ligatures.length <= 1) return; + ligatures .filter(ligature => /_/.test(ligature.glyph)) .forEach(ligature => {