Repository navigation
write_html: use the first available font of a <font face> list, like browsers - #2009
Merged
Merged
Conversation
andersonhc
reviewed
Oct 12, 2026
Author
|
Good idea, thanks! It now uses get_font_from_family(), so the extra mapping is gone and the change is just a few lines. If none of the fonts in the list is available, it falls back to the old behavior, so an unknown font still raises as before. |
Collaborator
|
Hi, thank you for the PR! I’ll do a more thorough review later, but a few things come to mind:
It would be helpful to add tests covering these cases. |
…s its PDF/A check, and respect bold and italic
# Conflicts: # CHANGELOG.md
Author
|
Thanks, good questions. Two of them were real problems, now fixed:
Added tests for each, plus small unit tests for resolve_font_family(). |
andersonhc
approved these changes
Oct 13, 2026
Author
|
Thanks for the review and for pointing out those cases. I’ve addressed them and added coverage for the PDF/A, registered font, and bold/italic behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<font face="Arial, Helvetica, sans-serif">, the usual way fonts are written in older HTML and email templates, raisedFPDFException: Undefined font: arial, helvetica, sans-serif, because the whole list was used as one font name. Browsers use the first font in the list that is available. Now fpdf2 does too: a core font or one added withadd_font(), with the genericserif,sans-serifandmonospacefamilies mapped to Times, Helvetica and Courier. If none of the names is available it uses the first one as before, so an unknown font still raises (test_html_bad_fontis unchanged). Added tests.e.g. Fixes #0
Checklist:
A unit test is covering the code added / modified by this PR
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.mdThis PR is ready to be merged
By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.