opentype.js icon indicating copy to clipboard operation
opentype.js copied to clipboard

Set correctly unicode 0 to ".null" glyph

Open puria opened this issue 4 years ago • 2 comments
trafficstars

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 test and 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.

puria avatar Dec 15 '20 12:12 puria

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.

khaledhosny avatar Dec 15 '20 13:12 khaledhosny

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.

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

puria avatar Dec 15 '20 14:12 puria

Noticed this when looking at the docs, but this PR addresses the same issue.

Looks worth merging still.

Templarian avatar Oct 26 '22 04:10 Templarian

I added my suggested changes as well as tests for them.

Connum avatar Feb 12 '23 18:02 Connum