Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate missing .notdef like ufo2ft #423

Merged
merged 2 commits into from
Aug 29, 2023
Merged

Generate missing .notdef like ufo2ft #423

merged 2 commits into from
Aug 29, 2023

Conversation

rsheeter
Copy link
Contributor

@rsheeter rsheeter commented Aug 28, 2023

For WghtVar.glyphs, which does not define notdef, we get this:

image
$ python resources/scripts/ttx_diff.py ../OswaldFont/sources/Oswald.glyphs
# default parameter comparison
COMPARISON
  Only fontmake produced 'HVAR'
  DIFF 'GDEF', build/default/fontc.GDEF.ttx build/default/fontmake.GDEF.ttx
  DIFF 'GPOS', build/default/fontc.GPOS.ttx build/default/fontmake.GPOS.ttx
  DIFF 'GSUB', build/default/fontc.GSUB.ttx build/default/fontmake.GSUB.ttx
  Identical 'GlyphOrder'
  Identical 'OS_2'
  Identical 'STAT'
  Identical 'avar'
  Identical 'cmap'
  Identical 'fvar'
  Identical 'glyf'
  DIFF 'gvar', build/default/fontc.gvar.ttx build/default/fontmake.gvar.ttx
  Identical 'head'
  Identical 'hhea'
  Identical 'hmtx'
  Identical 'loca'
  Identical 'maxp'
  Identical 'name'
  Identical 'post'

Fixes #149
Fixes #420

@rsheeter rsheeter force-pushed the notdef0 branch 2 times, most recently from 7963776 to a86d9e8 Compare August 28, 2023 23:45
@rsheeter rsheeter changed the title [WIP] Generate missing .notdef like ufo2ft Generate missing .notdef like ufo2ft Aug 29, 2023
@rsheeter rsheeter marked this pull request as ready for review August 29, 2023 03:33
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple little notes but looks good, happy to see this addition :)

fontdrasil/src/types.rs Outdated Show resolved Hide resolved
fontir/src/glyph.rs Outdated Show resolved Hide resolved

Self {
name: NOTDEF.clone(),
codepoints: HashSet::from([0]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd double-check with @anthrotype but I'm not sure .notdef has any codepoints. Some fonts include a NUL glyph in addition to notdef, although I'm not sure about (and am curious to learn more!) the semantics/rationale for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oswald cmap and glyphorder are now identical so I think this is right. I will double-check with Cosimo just in case it's only sometimes right or not as simplistic as I made it. A lot of these little details turn out to be fiddly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Colin was right, the codepoints for the generated .notdef glyph must be left empty, .notdef should be understood as the absence of a character mapping; 0x0000 is a different unicode codepoint denoting the NULL character (like in NULL-terminated C strings), it used to be among the recommended first 4 glyphs in old TrueType but current OT spec no longer does that and modern fonts don't contain NULL (and neither the carriage return CR character), but they all contain .notdef (un-cmapped) glyph as the first one (index=0).

@rsheeter rsheeter added this pull request to the merge queue Aug 29, 2023
Merged via the queue into main with commit 23ce03f Aug 29, 2023
9 checks passed
@cmyr cmyr deleted the notdef0 branch August 30, 2023 15:15
(0x0030, 2),
(0x031, 3),
(0x032, 4)
(0x0000, 0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm .notdef should not be mapped to anything, 0x0000 is the NULL character which is something else, a control character that is no longer required to be defined (there used to be a recommendation in the TrueType spec about the first 4 glyphs which was removed later on, so nowadays a font no longer needs to have a glyph for NULL 0x0000 character).


assert_eq!(
GlyphId::new(0),
font.cmap().unwrap().map_codepoint(0u32).unwrap()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, this is wrong, NULL character (0x0000) should not be mapped to ".notdef" glyph, i.e. the first glyph (gid=0) in the font. They are different things.

],
[0x20, 0x21, 0x2d, 0x3d]
[0x00, 0x20, 0x21, 0x2d, 0x3d]
Copy link
Member

@anthrotype anthrotype Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, {0x00: GlyphId(0)} should be absent from the cmap, unless the source explicitly contained this for whatever reason..., but in this case fontc wrongly generated that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fontc does not cmap latin captial A in Oswald should add .notdef when missing from the source
3 participants