fontsource / google-font-metadata

A metadata generator that fetches and parses the Google Fonts API.
MIT License
29 stars 9 forks source link

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

Closed lojjic closed 1 year ago

lojjic commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

https://github.com/fontsource/fontsource/issues/643 - Adding this for future reference on why these files are smaller.