charToGlyphIndex() in encoding.js never returns null
So the hasChar() always returns true if this.encoding is an object of CmapEncoding.
// font.js
Font.prototype.hasChar = function(c) {
return this.encoding.charToGlyphIndex(c) !== null;
};
Below code, this.cmap.glyphIndexMap[c.charCodeAt(0)] never returns null. Maybe the caller of charToGlyphIndex() except hasChar() want to receive 0(zero) for using it as index value if there were no mapping glyph.
// encoding.js
CmapEncoding.prototype.charToGlyphIndex = function(c) {
return this.cmap.glyphIndexMap[c.charCodeAt(0)] || 0;
};
Hi,
0 is the standard code for the .notdefglyph, to be displayed as a fallback.
Regardless of the encoding scheme, character codes that do not correspond to any glyph in the font should be mapped to glyph index 0. The glyph at this location must be a special glyph representing a missing character, commonly known as .notdef.
( https://docs.microsoft.com/en-us/typography/opentype/spec/cmap )
@fpirsch you are definitely right. Because charToGlypnIndex() do not return null in any case, hasChar() will return true always.
// font.js
Font.prototype.hasChar = function(c) {
return this.encoding.charToGlyphIndex(c) !== 0; // instead of !== null
};
suggestion:
// font.js
Font.prototype.hasChar = function(c) {
return this.encoding.charToGlyphIndex(c) > 0; // checks, 0, null, undefined, false...
};
@debussy2k Indeed...! @fpirsch Your solution looks good, should we add this in a next patch or minor version?
Are there still plans to implement this fix? This bug caused a lot of confusion until I found out about this issue.
Are there still plans to implement this fix? This bug caused a lot of confusion until I found out about this issue.
It took only 5 years, but I just opened PR #632 😉