Skip to content

Conversation

@cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Mar 11, 2024

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
Copy link
Collaborator Author

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
Copy link
Member

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

Copy link
Member

@gadenbuie gadenbuie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

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

@cpsievert
Copy link
Collaborator Author

cpsievert commented Mar 12, 2024

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.

@fernandoroa-ss
Copy link

Is this Windows problem related?

Only in Windows the font is not available for a shiny app, with errors:

Screenshot 2024-07-27 085204

The workaround (for windows) is to add the tags$head ... while in Linux, the bs_theme... alone, works fine

    tags$head(
      tags$link(
        rel = "stylesheet",
        href = "https://fonts.googleapis.com/css2?family=Oswald:wght@400;700&display=swap"
      )
    ),
    theme = bs_theme(
      version = "5", bootswatch = "flatly",
      base_font = font_google("Oswald"),
      heading_font = font_google("Oswald")
    ),

I don't know if this related to the use of http instead of https

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

Successfully merging this pull request may close these issues.

Fix Google Font font downloading

4 participants