Dear R-Devel list members,

I would like to report an inconsistency in how grDevices::cairo_pdf()
handles font discovery on Windows compared to the CRAN Cairo package.
On Windows, grDevices::cairo_pdf() fails to render specific installed
fonts (falling back to Helvetica/Arial), whereas Cairo::CairoPDF()
locates and renders the exact same font correctly. Specifically, it
applies to the Ubuntu Condensed true type font (I was not successful
replicating the issue with other fonts, surprisingly).

Since the Cairo package works, I suspect the font file itself is valid
and accessible by the OS. This suggests the issue may lie in the
specific version or configuration of the Pango/Cairo libraries bundled
with Base R for Windows. Interestingly, there was no such issue in R
3.6.3 (checked today). Maybe it could relate to
https://blog.r-project.org/2020/04/17/changes-to-symbol-fonts-for-cairo-graphics-devices/
though that might be a red herring.

The following code reproduces the issue on Windows, with R 4.5.2
(requires the Cairo package for comparison and the TTF font file):

```r
# get the font from Google Fonts, and install it as an admin (or "for all")
download.file(
  
"https://fonts.gstatic.com/s/ubuntucondensed/v17/u-4k0rCzjgs5J7oXnJcM_0kACGMtf-fVqvHoJXw.ttf";,
  "Ubuntu Condensed-regular.ttf",
  mode = "wb"
)


# get the "native" R PDF Cairo device and the one from Cairo package
gr_devices <- c(
  grDevices_pdf_device = grDevices::cairo_pdf,
  Cairo_pdf_device = Cairo::CairoPDF
)

# for each device, create a PDF with text in Ubuntu Condensed font
# and open it
lapply(
  names(gr_devices),
  \(dev_name) {
    figure_file <- paste0(dev_name, ".pdf")

    gr_devices[[dev_name]](figure_file, width = 6, height = 6)

    grid::grid.newpage()

    grid::grid.text(
      "This should be typed in\nUbuntu Condensed\nfont",
      gp = grid::gpar(
        fontfamily = "Ubuntu Condensed",
        fontsize = 30
      )
    )

    dev.off()
  }
)
```

Thank you for looking into it.

Best regards,
Jan Netík

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to