rstudio / bslib

Tools for theming Shiny and R Markdown via Bootstrap 3, 4, or 5.
https://rstudio.github.io/bslib/
Other
443 stars 50 forks source link

Switch bundled font file type from woff to woff2 #1004

Closed cpsievert closed 4 months ago

cpsievert commented 4 months ago

Closes #1002 (at least partially)

This PR should fix the "constantly updating" font files mentioned in #1002 by switching from woff to woff2. The difference in browser support nowadays is barely noticeable (97.98% vs 97.32%). Essentially the only difference is a drop of IE11 support, which Bootstrap 5 has officially dropped. As an additional benefit, the compression of the font files should be much better with woff2.

As a technical note, the font file downloading script (tools/download_preset_files.R) sets the User-Agent when requesting files to a modern version of Chrome, just to let Google Fonts know that we'd like woff2 (surprisingly, there doesn't seem to be any other way to do this). It's worth noting that sass:::read_gfont_url does something similar to get woff files. We may want to consider updating the User-Agent there as well, but I'm a bit skeptical the other issues we've been seeing would be fixed by that.

cpsievert commented 4 months ago

I think the failures here will have to be fixed by schloerke/shiny-workflows by pulling in the latest setup-r-dependencies@v2 fix pandoc installation

https://github.com/r-lib/actions/releases/tag/v2 https://github.com/rstudio/shiny-workflows/blob/main/setup-r-package/action.yaml#L81-L83

gadenbuie commented 4 months ago

I was a little worried about the number of changed files. It turns out the number of font files has gone up quite a bit, but the overall size is somewhat smaller.

Before

ls -l inst/fonts | grep "^-" | wc -l
#> 70
* checking installed package size ... NOTE
  installed size is 12.7Mb
  sub-directories of 1Mb or more:
    components   1.0Mb
    fonts        3.7Mb
    lib          5.4Mb

After

ls -l inst/fonts | grep "^-" | wc -l
#> 151
* checking installed package size ... NOTE
  installed size is 12.2Mb
  sub-directories of 1Mb or more:
    components   1.0Mb
    fonts        2.8Mb
    lib          5.6Mb
cpsievert commented 4 months ago

Would the change in sass::read_gfont_url() affect thematic? Asking because these error seem possibly related.

No, thematic has its own standalone gfont logic that seems to always uses ttf since (I think?) that's more widely supported by {systemfonts}/{sysfonts}/etc. It could also be ttf since that's what all these packages used when they first started.