-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Fonts API] does not correctly handle variable fonts files in .woff2 format #41158
Comments
I stumbled upon an issue with the new webfonts registration via Switching to WP 6.0 my Twenty Twenty-Two based theme (the original Twenty Twenty-Two is affected as well!) the headings - which use the Source Serif Pro (web-)font - switched font-weight and italics in headings doesn't work anymore (see screenshots). The cause is that the webfont handler By removing the So the result in my case is the same as above, a font being used not responding to font-weight settings (or italic style). But the cause is not an incorrect handling of the Anyway, I consider this behaviour a bug, it just renders font-weight/italic settings useless, the headings of Twenty Twenty-Two theme now look different on my PC and my tablet (obviously unwanted). From a development point of view the webfont handler should probably create several font-faces with the appropriate font names in Currently it's not even possible to avoid or fix this behaviour in a "clean" way. The only "solutions" I found are: |
I can confirm the issue described by @SchecDev, it also occurs in WP 6.0.1 in the block editor. Is there an advantage to using By the way... I would like to help with WordPress development.... who would I need to contact to discuss the behavior so we can fix it? |
In addition to the local version of the font taking precedence, the setup of the local font file(s) can come into play here too. My theme.json used "Inter" (Inter-VariableFont_slnt,wght.ttf) which worked fine while I had that very same file installed on my desktop, as expected there were no visual differences in the browser when it detected and called the locally installed (singular) file. However, I had to remove the variable version of Inter and install the individual/static .ttf files instead, so that desktop publishing software would load the font. It was then I noticed the issues described in this thread. If I had left the variable version installed on my machine, I might not have picked up the problem without close inspection, because visually at least, everything looked fine. Like @SchecDev I got around the issue of different font file versions by prefixing "fontFamily":
That was a clean a solution as I could come up with for now, as it still shows the font family as "Inter" in the editor. |
I tried what @SchecDev & @nigel-maher suggested on wp 6.1.1 and Gutenberg 15.0.1 as a workaround. The prefix trick temporarily fixes the problem. Thx btw |
The
|
@aristath what do you think? |
Reading the docs for font-formats on MDN, I see that the proper way to write this would be There is no fast, performant & reliable way to automatically detect if a font-file contains variations or not, so perhaps we could add a
I created a PR on #49653 that does just that, let me know what you think 👍 |
Reproduction ReportThis report focuses on The Fonts API has undergone extensive changes since this ticket was opened. I was unable to reproduce, but am I missing anything? Environment
Steps to Test
{
"fontFace": [
{
"fontFamily": "Oswald",
"fontStretch": "normal",
"fontStyle": "normal",
"fontWeight": "200 700",
"src": [
"file:./assets/fonts/oswald/Oswald-VariableFont_wght.woff2"
]
}
],
"fontFamily": "\"Oswald\", sans-serif",
"name": "Oswald",
"slug": "oswald"
},
Actual Results
Additional Notes
Supplemental Artifacts |
Thank you @ironprogrammer for your test report. I agree this API is vastly different from the implementation when this issue was first opened. @alexandrebuffet can you retest please with Gutenberg 15.9.1 or newer? Is this still an issue for you?
As @aristath noted, it is not yet "supported by all browsers". Given that the new I'll close this issue for now. However, if the issue still persists, please re-open and share the step-by-step instructions on how to reproduce the problem. |
Note: I added the
|
Description
When I register custom font families with variable font files in
.woff2
format into mytheme.json
, the browser doesn't seem to understand the font format and the "variable" properties doesn't work.Tested up with WordPress 5.9.3 + Gutenberg 13.2.1 and a webfont registration via
theme.json
in a custom Block Theme (as explained in #37140 PR).Maybe I'm wrong, but it seems to be the format declared in the
@font-face
that is incorrect. I believe that a variable font file in.woff2
format should be declared withformat('woff2' supports variations)
hint.Currently, it's the Webfonts Provider that deduces the format. Wouldn't it be better to leave the possibility to declare the "format" inside
src
array (via PHP ortheme.json
) for each source file?Step-by-step reproduction instructions
.woff2
variable webfont file as sourceScreenshots, screen recording, code snippet
No response
Environment info
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: