From 43bff37eb24efa10a500f5aa81e1b9c32eeb88ad Mon Sep 17 00:00:00 2001 From: Balearica Date: Sun, 7 Jul 2024 12:01:16 -0700 Subject: [PATCH] Fixed error looking up undefined glyphs per #735; added test --- src/glyphset.mjs | 2 +- test/opentype.spec.mjs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/glyphset.mjs b/src/glyphset.mjs index 3e5dab58..1d7ac43c 100644 --- a/src/glyphset.mjs +++ b/src/glyphset.mjs @@ -66,7 +66,7 @@ if(typeof Symbol !== 'undefined' && Symbol.iterator) { */ GlyphSet.prototype.get = function(index) { // this.glyphs[index] is 'undefined' when low memory mode is on. glyph is pushed on request only. - if (this.glyphs[index] === undefined) { + if (this.glyphs[index] === undefined && typeof index === 'number') { this.font._push(index); if (typeof this.glyphs[index] === 'function') { this.glyphs[index] = this.glyphs[index](); diff --git a/test/opentype.spec.mjs b/test/opentype.spec.mjs index 26c2b211..e75dd6e8 100644 --- a/test/opentype.spec.mjs +++ b/test/opentype.spec.mjs @@ -174,6 +174,23 @@ describe('opentype.js on low memory mode', function() { assert.equal(ndGlyph.unicode, undefined); }); + it('should return .notdef when looking up non-existent glyph in user-created font', function() { + const nullGlyph = new Glyph({ + name: '.notdef', + path: new Path() + }); + const font = new Font({ + familyName: 'TestFont', + styleName: 'Medium', + unitsPerEm: 1000, + ascender: 800, + descender: -200, + glyphs: [nullGlyph] + }); + const ndGlyph = font.charToGlyph('B'); + assert.equal(ndGlyph.name, '.notdef'); + }); + it('should correctly set unicode 0 for .null glyph', function() { const nullGlyph = new Glyph({ name: '.null',