google-font-download
google-font-download copied to clipboard
Switch to Google Fonts API v2
Docs are available here: https://developers.google.com/fonts/docs/css2
Changes:
- different syntax for multiple font families - https://developers.google.com/fonts/docs/css2#multiple_families
- different format and style syntax - https://developers.google.com/fonts/docs/css2#axis_ranges
- "As a general note, the updated CSS API is more strict about what requests are accepted than the original CSS API." - https://developers.google.com/fonts/docs/css2#strictness
- a display parameter is supported - https://developers.google.com/fonts/docs/css2#use_font-display
- a text parameter is supported - https://developers.google.com/fonts/docs/css2#optimizing_your_font_requests
- the subset parameter is no longer supported
- for modern browsers, a font-face with a unicorn-range prop (https://developer.mozilla.org/en-US/docs/Web/CSS/%40font-face/unicode-range) is returned for each available subset
- for legacy browsers (https://caniuse.com/#feat=font-unicode-range), a font with all subsets is returned
- some info: https://github.com/google/fonts/issues/2379
Things to do:
- add a parser for v2 URLs
- make sure we handle https://fonts.google.com/xxx URLs correctly, as these can use both the v1 and the v2 format/style syntax
- unrelated, but we could also parse more than just the font family and weight from URLs - this also applies to v1 (and would fix #23)
- replace
--formatwith something like--legacy-browsersto download the font with all subsets (or the old API can be used when--formatis used) - add support for display and text parameters
- add support for additional axis like slnt - (https://developers.google.com/fonts/docs/css2#list_of_variable_fonts)
- make sure we handle fallback weights correctly - https://developers.google.com/fonts/docs/css2#legacy_browser_support
- use the new API for downloading
I wrote these notes down mostly for myself to slowly work through, but if anyone else wants to help, that's even better!
👍🏻
This patch worked for me. Thank you!
The formatting example needs to be updated. This worked for me:
./google-font-download --url="https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900"