From ff94e3adad7baef5d9e21886f7b119606bffc129 Mon Sep 17 00:00:00 2001 From: Thierry Charbonnel Date: Tue, 8 Aug 2023 07:40:01 -0400 Subject: [PATCH 1/2] Fix: Handle Undefined Axis Property Error --- src/TTFFont.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TTFFont.js b/src/TTFFont.js index 6aa0937a..45d438d2 100644 --- a/src/TTFFont.js +++ b/src/TTFFont.js @@ -449,8 +449,9 @@ export default class TTFFont { } for (let axis of this.fvar.axis) { + const name = axis.name && axis.name.en ? axis.name.en : axis.axisTag.trim(); res[axis.axisTag.trim()] = { - name: axis.name.en, + name, min: axis.minValue, default: axis.defaultValue, max: axis.maxValue From c51d73842a2f0e360a5dc0a093e439057a76255b Mon Sep 17 00:00:00 2001 From: Thierry Charbonnel Date: Tue, 8 Aug 2023 13:40:14 -0400 Subject: [PATCH 2/2] use instance.postscriptNameID as fallback name: use instance.postscriptNameID as fallback name for namedVariations when the instance.name.en is not available --- src/TTFFont.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/TTFFont.js b/src/TTFFont.js index 45d438d2..3813358f 100644 --- a/src/TTFFont.js +++ b/src/TTFFont.js @@ -78,7 +78,7 @@ export default class TTFFont { } _decodeDirectory() { - return this.directory = Directory.decode(this.stream, {_startOffset: 0}); + return this.directory = Directory.decode(this.stream, { _startOffset: 0 }); } _decodeTable(table) { @@ -101,12 +101,12 @@ export default class TTFFont { if (record) { // Attempt to retrieve the entry, depending on which translation is available: return ( - record[lang] - || record[this.defaultLanguage] - || record[fontkit.defaultLanguage] - || record['en'] - || record[Object.keys(record)[0]] // Seriously, ANY language would be fine - || null + record[lang] + || record[this.defaultLanguage] + || record[fontkit.defaultLanguage] + || record['en'] + || record[Object.keys(record)[0]] // Seriously, ANY language would be fine + || null ); } @@ -482,7 +482,9 @@ export default class TTFFont { settings[axis.axisTag.trim()] = instance.coord[i]; } - res[instance.name.en] = settings; + // use instance.postscriptNameID as fallback name for namedVariations when the name is not available + const name = instance.name && instance.name.en ? instance.name.en : `PS${instance.postscriptNameID}`; + res[name] = settings; } return res;