Skip to content

Inconsistent kerning when using ggsave() with device = cairo_pdf #6647

@archavan

Description

@archavan

When saving a plot with ggsave() with device = cairo_pdf, the kerning appears to be inconsistent for text. This is not a problem with the default pdf device or when using the Cairo::CairoPDF() directly.

Below is code to reproduce the issue, and attached is a picture illustrating an example of the problem.

library(ggplot2)
library(Cairo)

df <- data.frame(
  x = "a",
  y = "avoid awkward spacing issues between sequences of letters"
)

p <- ggplot(df, aes(x, y)) +
  geom_point()

ww <- 4
hh <- 1

# this has inconsistent kerning
ggsave("kerning_ggsave_cairopdf.pdf", plot = p, device = cairo_pdf, width = ww, height = hh)

# this has no issues
ggsave("kerning_ggsave_default.pdf", plot = p, width = ww, height = hh)

# this has no issues either
CairoPDF("kerning_CairoPDF.pdf", width = ww, height = hh)
print(p)
dev.off()

sessionInfo()
#> R version 4.5.1 (2025-06-13)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS Sequoia 15.6.1
#> 
#> Matrix products: default
#> BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: America/New_York
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] Cairo_1.6-5   ggplot2_3.5.2
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.5        knitr_1.50         cli_3.6.5          xfun_0.53          rlang_1.1.6       
#>  [6] processx_3.8.6     generics_0.1.4     textshaping_1.0.3  glue_1.8.0         labeling_0.4.3    
#> [11] clipr_0.8.0        htmltools_0.5.8.1  ps_1.9.1           ragg_1.5.0         rmarkdown_2.29    
#> [16] scales_1.4.0       grid_4.5.1         evaluate_1.0.5     tibble_3.3.0       fastmap_1.2.0     
#> [21] yaml_2.3.10        lifecycle_1.0.4    compiler_4.5.1     dplyr_1.1.4        fs_1.6.6          
#> [26] RColorBrewer_1.1-3 pkgconfig_2.0.3    rstudioapi_0.17.1  digest_0.6.37      systemfonts_1.2.3 
#> [31] farver_2.1.2       R6_2.6.1           reprex_2.1.1       tidyselect_1.2.1   pillar_1.11.0     
#> [36] callr_3.7.6        magrittr_2.0.3     tools_4.5.1        withr_3.0.2        gtable_0.3.6
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions