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

woff / woff2 #367

Open
SNagel opened this issue Oct 10, 2022 · 1 comment
Open

woff / woff2 #367

SNagel opened this issue Oct 10, 2022 · 1 comment

Comments

@SNagel
Copy link

SNagel commented Oct 10, 2022

is there a way to get a full-featured woff/woff2 file for embedding from a local webserver instead of google?

  • in europe, using google fonts as a font file provider currently is a data protection problem (technically absurd, but yet legally existing).
  • Embedding the .ttf file is quite a heavy weight with 1.8MB file size.
@Lorp
Copy link
Contributor

Lorp commented Oct 10, 2022

Probably the easiest way is to use the Google Fonts CSS API.

Here is how to get Roboto Flex with its opsz and wght axes, but without the parametric axes:

https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,[email protected],100..1000&display=swap

This CSS links to 6 woff2 fonts, split by Unicode range. Here is the Latin font (88 kB):

https://fonts.gstatic.com/s/robotoflex/v9/NaNeepOXO_NexZs0b5QrzlOHb8wCikXpYqmZsWI-__OGfttPZktqc2VdZ80KvCLZaPcSBZtOx2MifRuWR28sPJtUMbsFEK6cRrleUx9Xgbm3WLHa_F4Ep4Fm0PN19Ik5Dntczx0wZGzhPlL1YNMYKbv9_1IQXOw7AiUJVXRrV8cWW4O8LJCoXjCnwSRSaLshNP1d9-EmF8tqHbE.woff2

You can download these fonts and serve them yourself. Copy the CSS, edit the URLs to your server and maybe edit the filenames to something handier. Use the same font-family: 'Roboto Flex';. Note that the unicode-range descriptor means only those fonts required by the document are served to browsers, so it’s no burden to your server to include all six.

To make them even smaller you can drop the opsz axis if you don’t need it, or pin it to a value you like:

https://fonts.googleapis.com/css2?family=Roboto+Flex:[email protected]&display=swap

Again we get 6 fonts, split by Unicode range. Here is the Latin font (38 kB):

https://fonts.gstatic.com/s/robotoflex/v9/NaNNepOXO_NexZs0b5QrzlOHb8wCikXpYqmZsWI-__OGfttPZktqc2VdZ80KvCLZaPcSBZtOx2MifRuWR28sPJtUMbsFEK6cRrleUx9Xgbm3WLHa_F4Ep4Fm0PN19Ik5Dntczx0wZGzhPlL1YNMYKbv9_1IQXOw7AiUJVXpRJ6cXW4O8TNGoXjC79QRyaLshNDUf3e0O-gn5rrZCu20YNau4OPFu02G5.woff2

If your website is mostly Western European content, then this 38 kB font is all they will need for Roboto Flex with a 100..1000 Weight axis.

Curiously, even though only the wght axis was requested, the font also includes an XOPQ axis, which most users will not need — and dropping it would make the font even smaller. I’ve asked in another place why this happens, and have not understood why it is there. Any thoughts, @davelab6 @anthrotype @sannorozco @rsheeter?

davidbgk added a commit to davidbgk/TODS that referenced this issue Oct 18, 2024
Fixes clagnut#3

What a ride!

I initially attempt a conversion to woff2 with https://www.fontsquirrel.com/tools/webfont-generator from the original ttf https://github.com/googlefonts/roboto-flex/tree/main/fonts

My issue with that option: it was not keeping relevant axis and there are so many of them anyway by default (13! see https://wakamaifondue.com/ for details) so I tried to slice the font prior to that with https://slice-gui.netlify.app/ which did the job but I eventually found the related bug on the Roboto repository googlefonts/roboto-flex#367 and I end up forging that URL:

https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght,[email protected],100..1000,-200..150&display=swap

Which contains the 3 pertinent grades for our case, then select the URL from the /* latin */ part :

https://fonts.gstatic.com/s/robotoflex/v26/NaNeepOXO_NexZs0b5QrzlOHb8wXqDGRY6mZsaJ8__OGfttPZktqc2VdZ80KvCLZaPcSBZtOx2MifRuWR28sPJtUMbsFEK6cRrleUx9Xgbm3WLHa_F4Ep4Fm0PN19Ik5Dntczx0wZGzhPlL1YNMYKbv9_1IQXOw7AiUJVXRrV8cWW4O8LJCoXjCnwSRSaLshNP1d9-EmF8tqHbE.woff2

And there we are :)
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

No branches or pull requests

2 participants