Skip to content

Commit

Permalink
Fixed error looking up undefined glyphs per opentypejs#735; added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Jul 7, 2024
1 parent e9c090e commit 43bff37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/glyphset.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]();
Expand Down
17 changes: 17 additions & 0 deletions test/opentype.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 43bff37

Please sign in to comment.