opentype.js
opentype.js copied to clipboard
Set correctly unicode 0 to ".null" glyph
as per https://docs.microsoft.com/en-us/typography/opentype/otspec170/recom#first-four-glyphs-in-fonts the unicode number fo the ".null" glyph should be 0 but was set to undefined
Description
The default value of the unicode property in the glyph object was evaluated as https://github.com/opentypejs/opentype.js/blob/88f7c1755ceec3326cdac4de53bc5ec89d38a615/src/glyph.js#L64 So was set to undefined when the unicode property was set to 0.
Formally should be
this.unicode = options.unicode !== undefined || undefined;
that we can short circuit to
this.unicode = options.unicode;
Motivation and Context
No open issues.
How Has This Been Tested?
Added new unit test
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
- [x] I did
npm run testand all tests passed green (including code styling checks). - [x] I have added tests to cover my changes.
- [x] I have read the CONTRIBUTING document.
- [x] I have updated the README accordingly.
- [ ] My change requires a change to the documentation.
as per https://docs.microsoft.com/en-us/typography/opentype/otspec170/recom#first-four-glyphs-in-fonts the unicode number fo the ".notdef" glyph should be 0
That is not what the link is saying. .notdef is given Glyph ID 0 and undefined Unicode value. Unicode 0 (i.e. U+0000) is mapped to .null glyph.
Anyway, this is a recommendation for font authors not consumers.
as per https://docs.microsoft.com/en-us/typography/opentype/otspec170/recom#first-four-glyphs-in-fonts the unicode number fo the ".notdef" glyph should be 0
That is not what the link is saying.
.notdefis given Glyph ID 0 and undefined Unicode value. Unicode 0 (i.e.U+0000) is mapped to.nullglyph.
Cool ;) anyway this fixes the .null glyph then, cause is not possible to give a 0 value to the unicode attribute within the glyph object... should I update the tests?
I saw it frequently used, like:
https://github.com/opentypejs/opentype.js/blob/88f7c1755ceec3326cdac4de53bc5ec89d38a615/test/opentypeSpec.js#L83-L87
Anyway, this is a recommendation for font authors not consumers.
Yeah thats the purpose, I'm playing an experiment for creative and algorithmic typeface generation via browser, and happened to step into this issue ;p
Noticed this when looking at the docs, but this PR addresses the same issue.
Looks worth merging still.
I added my suggested changes as well as tests for them.