Add initial support for variable fonts #6771
Draft
+342
−102
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.
This PR is still in-progress and aims to add some initial support for variable fonts. Initial because the aim is not to give the user full control over setting custom variation coordinates (this could be good future work, but probably makes more sense to implement in conjunction with the planned
font
object). The aim is to automatically select a correct instance based on thewght
(font weight),wdth
(font stretch), andital
/slnt
(italic) axes, which I think should over 95%+ of the use cases.It also adds support for embedding CFF2 fonts in PDFs by converting them to a TTF font, which is not the best approach (better would be to convert to CFF), but it should do the job. CFF2 fonts are pretty rare (less than 1% of variable fonts), but based on past issues it seems like some systems do use some CFF2-based Noto fonts, so this is definitely worth fixing.
Fixes #185 (tracking support for specifying variable font axes is probably worth opening a new issue for).
Example:
Result:
test.pdf
TODOs:
wdth
andslant
/italic
axes.pixglyph
bug that makes CFF2 fonts render as black rectangles in PNG export.