Skip to content
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

feat: v2 woff files are now split by unicode-range subset #116

Merged
merged 4 commits into from
Mar 1, 2023

Conversation

lojjic
Copy link
Contributor

@lojjic lojjic commented Dec 24, 2022

This removes the prior limitation for woff files in the v2 API where it would use a single combined file for all unicode-range subsets. Safari 11 briefly had support for unicode-range but didn't yet support woff2, so if you use a Safari 11 user-agent then GFonts will serve up CSS with individual woff files per subset, just like woff2.

I've regenerated the data files locally with this change and verified the output includes the subset woff files. Sample diff:

           "[4]": {
             "url": {
               "woff2": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt9E3g-Lbpcnr20eUBAZG30RMhmVkJXC-1MKE3QRp5zkww.4.woff2",
-              "woff": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt8g.woff",
+              "woff": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt8iX8-qzYBR2czuUKGJi6mhkslBoPRyOEMbc0fwtw3D1FuxsCDw.4.woff",
               "opentype": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt9w.otf"
             }
           },
           "[5]": {
             "url": {
               "woff2": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt9E3g-Lbpcnr20eUBAZG30RMhmVkJXC-1MKE3QRp5zkww.5.woff2",
-              "woff": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt8g.woff",
+              "woff": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt8iX8-qzYBR2czuUKGJi6mhkslBoPRyOEMbc0fwtw3D1FuxsCDw.5.woff",
               "opentype": "https://fonts.gstatic.com/s/notosanssc/v26/k3kIo84MPvpLmixcA63oeALZraWt9w.otf"
             }
           },

I was unable to get the unit tests passing with this change -- I think fixtures/google-fonts-v2.json needs to be regenerated but I was unable to figure out how, it doesn't get updated by the generate-fixtures script. I'm happy to do so with some instruction.

Thanks!

@ayuhito
Copy link
Member

ayuhito commented Dec 24, 2022

Thanks for the PR! This is an interesting but breaking change in terms of browser support.

Is the browser support loss major? Not really. I do like the fact it unifies the behaviour of APIv2 but I need to do a much deeper review of this and its effects when I'm actively working on the Fontsource v5 CLI (possibly next month) since this is a breaking change all around. Looks good so far!

As for fixtures/google-fonts-v2.json. That's a manual change to update. Honestly better off as a snapshot 😅

@lojjic
Copy link
Contributor Author

lojjic commented Dec 28, 2022

If it would avoid breaking downstream Fontsource code, this could also be approached by adding it as an additional format, something like "woff-split", rather than overwriting the "woff". For my use case I'm more interested in using this metadata directly rather than the Fontsource packages, so it would serve my needs that way. Food for thought. 🤷‍♂️

@ayuhito
Copy link
Member

ayuhito commented Dec 28, 2022

If we can get tests passing, I don't think there's any issue merging this and releasing a new major version. I think this is a solid intuitive change to make.

The APIv2 fixture is a manually updated fixture but feel free to change that into a snapshot to clean things up in the future.

Downstream won't have any issues since they'll just rely on an older version until the dep is updated.

@ayuhito ayuhito merged commit 293d373 into fontsource:main Mar 1, 2023
@ayuhito
Copy link
Member

ayuhito commented Mar 1, 2023

Once again, thank you for the PR! I've updated the tests for it to work in this case.

An added benefit of this is reducing package sizes for Fontsource! Noto Serif HK was around 250MB which just about trips NPM package size limitations. This PR reduces that package to around 190MB instead. 🎉

@lojjic
Copy link
Contributor Author

lojjic commented Mar 1, 2023

An added benefit of this is reducing package sizes for Fontsource!

Oh! That's actually the opposite of what I'd have expected, I was under the impression that the sum of individual files would be larger than the combined file due to repetition of common data across all of them. 🤔

@ayuhito
Copy link
Member

ayuhito commented Mar 1, 2023

Oh! That's actually the opposite of what I'd have expected, I was under the impression that the sum of individual files would be larger than the combined file due to repetition of common data across all of them. 🤔

Just a guess, but Google's subsetting probably cuts out a bunch of glyphs. I've seen people mention that the all woff files supports more characters and features than woff2 variants, so that may hold some bearing.

@ayuhito
Copy link
Member

ayuhito commented May 21, 2023

fontsource/fontsource#643 - Adding this for future reference on why these files are smaller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants