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

system_fonts() returning empty tibble on devtools::check_win_devel() build #87

Closed
AllanCameron opened this issue Jan 20, 2022 · 6 comments

Comments

@AllanCameron
Copy link

We have been using systemfonts successfully in the development of a ggplot2 extension package which has got to the point of CRAN submission. Unforunately, all though all the tests and CMD checks are working on local machines and GH actions, the package fails on incoming tests to CRAN because systemfonts doesn't seem to find any fonts on the test machine.

After examining the logs, I traced the problem via a warning that was emitted by systemfonts::get_fallback(), and included in the logs, which says

#> warning: No fonts detected on your system. Using an empty font.`

I thought this was a bit odd, so added the following test to ensure that systemfonts was detecting the fonts on the Windows system on CRAN:

test_that("Some fonts are available on the system", {

  expect_gt(nrow(systemfonts::system_fonts()), 0)
})

This test passes locally and on GH actions, but fails on the CRAN machine. I asked CRAN to check whether there was a problem, but got a fairly curt reply saying that there must be a problem with the dependency we are using to detect fonts - that we should fix and re-submit. The Linux machines on CRAN seem to be fine, and as I say, the local and GH Windows tests are passing.

On the off chance, I thought I would open this issue here in case there was an obvious fix. The package relies on text metric measurements and there isn't a great alternative out there.

Any ideas?

@AllanCameron
Copy link
Author

Ah, I've just seen the updated systemfonts CRAN checks that were run today, and see that they are getting the same error on the Windows build...

@thomasp85
Copy link
Member

Thanks for the info. I'm aware of the issue and looking into it. There is something wonky going on with the new CRAN machine and I haven't been able to replicate it. I'm waiting on CRAN to get back to me on the matter

@AllanCameron
Copy link
Author

Yes, I can't replicate the problem anywhere else and have no way of doing so except submitting it for scrutiny on their idiosyncratic machine. I thought I might get a more useful reply from CRAN than "your problem, not ours"

@AllanCameron
Copy link
Author

In case anyone else has a similar issue, I thought I'd post my workaround to get through the CRAN checks when there is a problem with systemfonts being unable to detect any fonts on the CRAN build machine.

I created a ./inst/font/ directory in the source package and added an open source fontfile. This can then be used via systemfonts::register_font in .onLoad.

.onLoad <- function(libname, pkgname) {

  sans <- system.file("font", "Open_Sans_Regular.ttf", package = "geomtextpath")

  # Provide fallback fonts in case unable to detect system fonts
  if (nrow(systemfonts::system_fonts()) == 0) {
    systemfonts::register_font("fallback", sans)
  } else {
    systemfonts::register_font("fallback", systemfonts::font_info("")$path[1])
  }

}

However, systemfonts will not use this as the fallback font, so any reference to font families requires manual fallback inside the package. To do this, I wrote the following little infix operator:

# replace non-zero characters with alternatives
`%nz%` <- function(a, b) {
  a[!nzchar(a)] <- b[1]
  a
}

So that in calls to functions needing a family parameter we can do

package_function <- function(family)
{
  info <- systemfonts::font_info(family %nz% "fallback")
 # do stuff with info....
}

@thomasp85 sorry this doesn't help the broader issue of the wonky Win Dev machine on CRAN.

@thomasp85
Copy link
Member

I have located the issue (not in systemfonts but on the CRAN machine), and will soon push an update special casing the CRAN machines behaviour

@AllanCameron
Copy link
Author

Great - that should stop us from having to special-case it and hopefully ditch our manual fallbacks. I'll keep an eye on the systemfonts CRAN checks myself, so please feel free to close this issue.

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