-
-
Notifications
You must be signed in to change notification settings - Fork 705
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
Variable Font Instantiation Limited #1981
Comments
Note, it seems that only "Regular" and "Bold" font-weights are used for naming instances, which means users are limited to two arbitrary real visual weights. Expanding this to include at least Light, Medium, SemiBold would already significantly improve things, although this won't be a "proper" fix. That being said, given that fonts can have multiple axis of variation, you'll quickly end up having to do something like font-family + '-' + trunc(hmac-sha256(font-family, axis1 + axis2 + axis3 + axis4 + axis5 + etc), 10) I guess? |
In my example, https://github.com/Kozea/WeasyPrint/blob/main/weasyprint/pdf/stream.py#L18 only gets called twice. |
Presumably this is where the problem may reside: |
Removing: |
Only a minor metadata cosmetic issue remains, all variations are either encoded as "Roboto-Flex" (implicitly regular), or "Roboto-Flex-Bold", presumably this is Pango misbehaving? As I'd expect wght 450-550 to be encoded as "Roboto-Flex-Medium"... |
The following:
Results in:
So 700 and above is automatically getting the Bold Suffix. While this is minor, it results in cases where the naming is very misleading where a -Bold could have a real wght of 100 :) |
Fixed by #1988. |
My pull request didn't fix the bug in it's entirety... There's still the interaction with font-weight: as illustrated in my last post, but I haven't been successful in figuring out where this issue might lie... Do you have any thoughts/hints on this matter? |
I’m not sure to understand your problem. Do you mean that the name of the font in the metadata is wrong? |
Yeah sortof...
The above will result in two fonts (Roboto-Flex + Roboto-Flex-Bold) being embedded, even though they're the same font variation. And having something called 'Bold', while being 'Light' in reality is a bit misleading of course. Practically speaking, this won't happen too often in real world use-cases, and when it does it just results in a larger PDF than optimal, so it's not the end of the world. But if you can give me some pointers, I may look into this a little further... |
This would have made some sense:
However, it seems to have no effects on the generated PDF, neither does:
|
So this fixes the issue:
Though this patch is probably not entirely proper, as some code is now duplicated, so some refactoring might be worth while. I'd love to hear your thoughts. |
To be honest, I don’t want to add extra code for this, as we could introduce other bugs that will be hard to debug later. If I can find some time, I’ll create a variable testing font and add some tests, we need to avoid regressions more that to have better font names in metadata 😀. |
(1) Prevents identical wght variations from being doubly embedded under different named weights (typically normal and bold) (2) Assign good approximate named weights, which prevents metadata from being actively misleading.
As I mentioned earlier it also causes identical fonts to be doubly embedded, thus easily avoidably enlarging some PDFs. Given I was almost done when you responded, I just posted a pull request, which has my earlier suggestion refactored to the best of my (somewhat limited) ability. I really hope you would reconsider this, I understand the need to prevent regressions, but Weasy's current behavior is actively misleading, and as far as I can tell risk of regression should not be excessive here. Also you've done beta releases for weasy in the past, so why not considering doing that in this case as well? |
Oh and I forgot to mention, Weasy's variable font support is now still young, thus it's use in the real world is probably quite limited at this point in time. This will only increase over time. Therefore if this has to be fixed in the deeper future, (for whatever reason) the pain of any potential regression will only be that much bigger. |
(1) Prevents identical wght variations from being doubly embedded under different named weights (typically normal and bold) (2) Assign good approximate named weights, which prevents metadata from being actively misleading.
I just revised for PEP8 compliance as far as it's possible, as the pango API makes complying with the 79 char line length impossible without violating other rules. However PEP8, allows for 99 char lines in some cases, and my commit does comply with that: |
Adds italic naming to font metadata where appropriate
Adds stretch naming to font metadata where appropriate
(1) Prevents identical wght variations from being doubly embedded under different named weights (typically normal and bold) (2) Assign good approximate named weights, which prevents metadata from being actively misleading.
Adds italic naming to font metadata where appropriate
Adds stretch naming to font metadata where appropriate
variable-font-bug.zip
It seems that WeasyPrint instantiates each font-weight when it first encounters it, even if later on, it encounters a different font-variation-settings: 'wght' applied to that font-weight. Seeming font-weight is used for "naming" the embedded font, so Roboto-Flex-Bold and font-variation-settings is used to actually determine the real visual weight (wght). However once real visual wght X is assigned/applied to "Bold" it remains fixed after that.
While the current variable font implementation is already quite useful in it's current form, as it allows users to finetune font weights, more creative uses of variable fonts quickly leads to very confusing situations.
If this is not so trivial to fix, maybe consider adding a CLI warning about this limiation?
The text was updated successfully, but these errors were encountered: