-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add Fallback '.notdef' Glyph for Improved Cross-Platform TrueType Font Support #1352
base: master
Are you sure you want to change the base?
Conversation
Hi @spacegaori Thank you very much for this PR 👍 Overall it seems a good idea to me, but I'll let @andersonhc have a look at this, because he's more expert on she subject of fonts than myself 😅 A couple of suggestions of minors changes to make to this PR before we accept it:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job on this PR. I really like your solution
|
||
self.ttfont["glyf"][".notdef"] = pen.glyph() | ||
self.ttfont["hmtx"][".notdef"] = (600, 0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe having the fixed 0,0 to 600,600 would look weird on different fonts.
Maybe having your coordinates set to (ttfont['head'].xMin, ttfont['head'].yMax), (ttfont['head'].xMax, ttfont['head'].yMax) would generate a more consistent notdef outline.
"Fallback glyph will be provided." | ||
) in caplog.text | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Times New Roman is a commercial font owned by Monotype, so we can't include it in our repository.
I recommend getting a OFL font and renaming the .notdef glyph to something else to create your test font.
something like this:
from fontTools import ttLib
font = ttLib.TTFont("NotoSans-Regular.ttf")
glyphnames = font.getGlyphOrder()
glyphnames[0] = "dummy"
font = ttLib.TTFont("NotoSans-Regular.ttf")
font.setGlyphOrder(glyphnames)
post = font['post']
font.save("NotoSans-Regular-without-notdef.ttf")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post = font['post']
What does this line do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
post = font['post']
What does this line do?
If you don't read the 'post' table, fontTools will never apply the change on this table and the change won't be saved on the new font. It's because of the lazy loading they do to improve performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to include the "NotoSans-Regular-without-notdef.ttf" - you can create the font and commit the ttf into the repository.
Also, the CI is failing because test/font/test_charmap.py
will create a test file with the first 999 chars of every font on test/font
, so you need to run it with generate=True
once to create a reference file for the new font.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I'll run it once.
You don't need to include the "NotoSans-Regular-without-notdef.ttf" - you can create the font and commit the ttf into the repository.
Do you mean that I don't need to include the process of creating "NotoSans-Regular-without-notdef.ttf" and just include the created font?
I propose adding a fallback '.notdef' glyph for TrueType fonts. I encountered a similar issue to this one on macOS and Linux when attempting to use a system font, Times New Roman, for Unicode support. A key error was raised because the system fonts were missing the '.notdef' glyph. While the inclusion of this glyph is mandatory for TTF fonts, it is evidently not standardized across platforms. Instead of assuming the glyph’s existence, implementing a fallback option would improve cross-platform support and prevent these errors.
Checklist:
A unit test is covering the code added / modified by this PR
This PR is ready to be merged
In case of a new feature, docstrings have been added, with also some documentation in the
docs/
folderA mention of the change is present in
CHANGELOG.md