extrafont
extrafont copied to clipboard
Font embedding not working due to GhostScript `-I` switch
After using embed_fonts()
, fonts are embedded but do not display correctly:
library(ggplot2)
library(extrafont)
#> Registering fonts with R
temp <- ggplot() +
geom_text(aes(x = 1, y = 1, label = "Courier"), family = "Courier New") +
geom_text(aes(x = 1, y = 0, label = "Whitney"), family = "Whitney Book") +
geom_text(aes(x = 1, y = -1, label = "Gotham"), family = "Gotham Book")
pdf("before.pdf", height = 5 / 2.54, width = 10 / 2.54)
temp
grDevices::dev.off()
#> quartz_off_screen
#> 2
extrafont::embed_fonts("before.pdf")
pdftools::pdf_fonts("before.pdf")
#> # A tibble: 4 × 4
#> name type embedded file
#> <chr> <chr> <lgl> <chr>
#> 1 LYPKWD+CourierNewPSMT type1c TRUE ""
#> 2 VDRBSP+Whitney-Book type1c TRUE ""
#> 3 ZYKQGV+Gotham-Book type1c TRUE ""
#> 4 Helvetica type1 FALSE "/System/Library/Fonts/Helvetica.ttc"
Here I specify the location of the fontmap:
library(ggplot2)
library(extrafont)
#> Registering fonts with R
temp <- ggplot() +
geom_text(aes(x = 1, y = 1, label = "Courier"), family = "Courier New") +
geom_text(aes(x = 1, y = 0, label = "Whitney"), family = "Whitney Book") +
geom_text(aes(x = 1, y = -1, label = "Gotham"), family = "Gotham Book")
pdf("after.pdf", height = 5 / 2.54, width = 10 / 2.54)
temp
grDevices::dev.off()
#> quartz_off_screen
#> 2
extrafont::embed_fonts("after.pdf", options = list("-sFONTMAP='/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/extrafontdb/fontmap/Fontmap'"))
pdftools::pdf_fonts("after.pdf")
#> # A tibble: 3 × 4
#> name type embedded file
#> <chr> <chr> <lgl> <chr>
#> 1 OIFJQI+CourierNewPSMT truetype TRUE ""
#> 2 TVYEXO+Whitney-Book truetype TRUE ""
#> 3 MCGSWN+Gotham-Book truetype TRUE ""
This is the output before and after.
Here is some system and session info:
Sys.info()
#> sysname
#> "Darwin"
#> release
#> "22.3.0"
#> version
#> "Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000"
#> machine
#> "arm64"
#> login
#> "root"
sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: aarch64-apple-darwin20 (64-bit)
#> Running under: macOS Ventura 13.2
#>
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib
#>
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> loaded via a namespace (and not attached):
#> [1] digest_0.6.31 withr_2.5.0 lifecycle_1.0.3 reprex_2.0.2
#> [5] evaluate_0.20 rlang_1.0.6 cli_3.6.0 rstudioapi_0.14
#> [9] fs_1.6.1 rmarkdown_2.20 tools_4.2.2 glue_1.6.2
#> [13] xfun_0.37 yaml_2.3.7 fastmap_1.1.0 compiler_4.2.2
#> [17] htmltools_0.5.4 knitr_1.42
Is the GhostScript -I
switch not working correctly?