Skip to content

Commit e2a1d83

Browse files
committed
catch another error that can occur with subset font files
1 parent 240c3a7 commit e2a1d83

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/encoding.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ function addGlyphNamesAll(font) {
252252
const c = charCodes[i];
253253
const glyphIndex = glyphIndexMap[c];
254254
glyph = font.glyphs.get(glyphIndex);
255-
glyph.addUnicode(parseInt(c));
255+
if(glyph) {
256+
glyph.addUnicode(parseInt(c));
257+
}
256258
}
257259

258260
for (let i = 0; i < font.glyphs.length; i += 1) {

src/glyphset.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// The GlyphSet object
22

33
import Glyph from './glyph.js';
4+
import { logger } from './logger.js';
45

56
// Define a property on the glyph that depends on the path being loaded.
67
function defineDependentProperty(glyph, externalName, internalName) {
@@ -63,7 +64,12 @@ if(typeof Symbol !== 'undefined' && Symbol.iterator) {
6364
GlyphSet.prototype.get = function(index) {
6465
// this.glyphs[index] is 'undefined' when low memory mode is on. glyph is pushed on request only.
6566
if (this.glyphs[index] === undefined) {
66-
if (typeof this.font._push !== 'function') return;
67+
if (typeof this.font._push !== 'function') {
68+
if (index !== null) {
69+
logger.add(`Trying to access unknown glyph at index ${index}`, logger.ErrorTypes.WARNING);
70+
}
71+
return;
72+
}
6773

6874
this.font._push(index);
6975
if (typeof this.glyphs[index] === 'function') {

0 commit comments

Comments
 (0)