s-u / Cairo

R graphics device using cairo graphics library for creating high-quality output
12 stars 10 forks source link

Fontconfig error with CairoPNG on Windows with R 4.2.0 or higher #37

Closed cpsievert closed 2 years ago

cpsievert commented 2 years ago

It appears that, from a fresh R 4.2.0 (or higher) session on Windows, the first call to Cairo::CairoPNG() always generates:

Fontconfig error: Cannot load default config file: No such file: (null)

Plots are still generated, but the fonts appear thinner and poorer quality then they should be. See https://github.com/rstudio/shiny/issues/3626 for some examples

s-u commented 2 years ago

How did you compile Cairo? This looks like problem in your fontconfig installation missing font configuration files. Can you, please, provide more complete details on how you compiled fonconfig, what are your font locations etc.?

s-u commented 2 years ago

Preliminary investigation suggests that Windows doesn't support fontconfig, so it shouldn't be linked, but the suggested UCRT configuration included it. R's internal cairo does not use it so if it has desired effect, we could remote it.

s-u commented 2 years ago

The Windows UCRT toolchain includes cairo-ft, but it cannot be actually used, because the FontConfig configuration is not included. Cairo uses cairo-ft if available, so that causes the problem as the user doesn't have valid FontConfig configuration. The non-UCRT toolchain did not have cairo-ft, so Cairo fell back to the native functions. R explicitly disables cairo-ft on Windows cairoFns.c#L1645 so we should probably do the same.

Thanks to Tomáš Kalibera for debugging!

s-u commented 2 years ago

@cpsievert can you, please, check if the latest version fixed the problem? Use

install.packages("Cairo",,"https://rforge.net",type='source')

with full Rtools42 installed.

cpsievert commented 2 years ago

That appears to have fixed, thanks!

s-u commented 2 years ago

Excellent, thanks! I'll post the new version to CRAN.