Jan NetÃk
2026-Jan-15 14:15 UTC
[Rd] [Windows] grDevices::cairo_pdf fails to map certain font families (vs Cairo::CairoPDF)
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
Ivan Krylov
2026-Jan-15 20:39 UTC
[Rd] [Windows] grDevices::cairo_pdf fails to map certain font families (vs Cairo::CairoPDF)
Dear Jan Net?k, Thank you for providing an easily reproduced example! ? Thu, 15 Jan 2026 15:15:56 +0100 Jan Net?k <netikja at gmail.com> ?????:> 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.This seems to be fixed in both R-devel and the Cairo package on CRAN: https://bugs.r-project.org/show_bug.cgi?id=18955 (I've tried your example and it works in R-to-be-4.6.0, but not R-4.5.) -- Best regards, Ivan