Fixed error running get
with null
index to resolve charToGlyph
bug per #735
#736
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change prevents an error when the
GlyphSet
get
method is called with anindex
ofnull
/undefined
. This resolves a bug withcharToGlyph
described in #735. A test is also added to prevent the bug from re-occurring in the future.Motivation and Context
See #735. In short, when using
charToGlyph
with (1) aFont
object created by opentype.js and (2) a character that has no glyph in the file, an error is thrown. This occurs because opentype.js runsthis.glyphs.get(glyphIndex)
whereglyphIndex
isnull
.This simple change fixes this bug, and makes
get
returnundefined
if the glyph does not exist. Looking at the code incharToGlyph
(linked below), this is the behavior that is expected by that function.opentype.js/src/font.mjs
Lines 201 to 210 in e9c090e
After the change, running
charToGlyph
with aFont
object created by opentype.js defaults to returning.notdef
, which is consistent with the behavior when using an imported font.How Has This Been Tested?
This fixed the issue described in #735 in my project. The existing automated tests pass, and I added a new automated test for the bug this solves.
Screenshots (if appropriate):
Types of changes
Checklist:
npm run test
and all tests passed green (including code styling checks).