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',