-
Notifications
You must be signed in to change notification settings - Fork 265
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
Changes from all commits
9fd37a8
1c005fe
a3855aa
369fbf1
83af3e7
d9a247f
ab766ee
06739cb
d14084c
ec10cf8
8d8d946
65af26f
b25f555
011254c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,16 @@ def test_add_font_uppercase(): | |
assert pdf.fonts is not None and len(pdf.fonts) != 0 # fonts add successful | ||
|
||
|
||
def test_add_font_missing_notdef_glyph(caplog): | ||
pdf = FPDF() | ||
pdf.add_font(family="Roboto", fname=HERE / "Roboto-Regular-without-notdef.ttf") | ||
assert pdf.fonts is not None and len(pdf.fonts) != 0 # fonts add successful | ||
assert ( | ||
"TrueType Font 'roboto' is missing the '.notdef' glyph. " | ||
"Fallback glyph will be provided." | ||
) in caplog.text | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
What does this line do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I'll run it once.
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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe it would be worth adding a comment explaining that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FYI, this line causes a linter error.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you included the TTF font already, I'd say just remove generating the font again (remove lines 151 to 161). It should be good to merge after that. |
||
def test_font_missing_glyphs(caplog): | ||
pdf = FPDF() | ||
pdf.add_page() | ||
|
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.