google-webfonts-helper icon indicating copy to clipboard operation
google-webfonts-helper copied to clipboard

Variable fonts

Open phillipseamore opened this issue 6 years ago • 4 comments

It would be great to add support for variable fonts, e.g. https://fonts.google.com/specimen/Inter

phillipseamore avatar Mar 06 '20 17:03 phillipseamore

Google Fonts API docs: https://developers.google.com/fonts/docs/css2#non-standard_weights

We have discovered a way to obtain a CSS that includes variable font files from the Google Fonts API, is to call it with a wght property that is not one of the set of listed weights (200, 300, 400, 500, 600, 700, 800, 900). The font file for that weight will be variable. So, for example, the font file for 200 will not be variable, while the font file for 201 will be variable. Here is an example of a CSS without variable font files:

https://fonts.googleapis.com/css2?family=Inconsolata:wght@200

And here is one with a variable font file:

https://fonts.googleapis.com/css2?family=Inconsolata:wght@201

This is undocumented, but will likely work for a while.

mightyiam avatar Jun 16 '20 08:06 mightyiam

Here is the API that the fonts.google.com frontend web client uses to obtain fonts metadata. It provides information regarding which fonts are variable and all the details necessary. But it doesn't seem to be a public API. So, using it means it would probably break at some point. Perhaps it would be best to ask the Google Fonts team for a public API for this.

https://fonts.google.com/metadata/fonts

mightyiam avatar Jun 17 '20 03:06 mightyiam

On Tue, Jun 16, 2020, 4:55 AM Shahar Dawn Or [email protected] wrote:

Google Fonts API docs: https://developers.google.com/fonts/docs/css2#non-standard_weights

We have discovered a way to obtain a CSS that includes variable font files from the Google Fonts API, is to call it with a wght property that is not one of the set of listed weights (200, 300, 400, 500, 600, 700, 800, 900). The font file for that weight will be variable. So, for example, the font file for 200 will not be variable, while the font file for 201 will be variable. Here is an example of a CSS without variable font files:

https://fonts.googleapis.com/css2?family=Inconsolata:wght@200

And here is one with a variable font file:

https://fonts.googleapis.com/css2?family=Inconsolata:wght@201

This is undocumented, but will likely work for a while.

Kindly, this is a misunderstanding of the documented api.

You should use a range selector to get a variable font. Eg

https://fonts.googleapis.com/css2?family=Hepta+Slab:[email protected]

If you do @201, you are only guaranteed to get a font which contains that single weight instance. You might get a VF with a wider range today, but it will likely change to be more and more exact to only what you actually requested.

davelab6 avatar Jun 17 '20 04:06 davelab6

That's great. So, that means that it is possible to obtain a variable font. And it could be obtained by the full range (from the lightest weight to the heaviest weight, for example).

The only public API missing is an indication of which fonts are variable.

BTW, there seems to be some rate limiting on that metadata API. So here's the file, just for reference: json.txt

mightyiam avatar Jun 17 '20 05:06 mightyiam