r-lib/ragg

ragg not using font found by systemfonts

Closed this issue · 1 comments

ragg isn't finding a font that is accessible by systemfonts and grDevices. I first noticed this while using ggsave(), so I tried some methods of specifying both family and fontface in theme(), but that didn't appear to work either. I eventually reduced it down to this reprex:

fonts <- systemfonts::system_fonts()
fonts[fonts$family == "Lato", c("name", "family", "style", "weight")]
#> # A tibble: 10 × 4
#>    name                family style           weight
#>    <chr>               <chr>  <chr>           <ord> 
#>  1 Lato-Black          Lato   Black           heavy 
#>  2 Lato-Light          Lato   Light           light 
#>  3 Lato-LightItalic    Lato   Light Italic    light 
#>  4 Lato-Italic         Lato   Italic          normal
#>  5 Lato-HairlineItalic Lato   Hairline Italic thin  
#>  6 Lato-Regular        Lato   Regular         normal
#>  7 Lato-BoldItalic     Lato   Bold Italic     bold  
#>  8 Lato-BlackItalic    Lato   Black Italic    heavy 
#>  9 Lato-Hairline       Lato   Hairline        thin  
#> 10 Lato-Bold           Lato   Bold            bold

grDevices::png("grDevices.png")
plot(987654321, family = "Lato-LightItalic")
dev.off()
#> quartz_off_screen 
#>                 2

grDevices

Correct font is used, Lato Light Italic.


ragg::agg_png("ragg.png")
plot(987654321, family = "Lato-LightItalic")
dev.off()
#> quartz_off_screen 
#>                 2

ragg

Incorrect font is used, seems to default to regular Lato.

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.1.3 (2022-03-10)
#>  os       macOS Catalina 10.15.7      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/Chicago             
#>  date     2022-04-06                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  backports     1.4.1   2021-12-13 [1] CRAN (R 4.1.0)
#>  cli           3.1.1   2022-01-20 [1] CRAN (R 4.1.2)
#>  crayon        1.4.2   2021-10-29 [1] CRAN (R 4.1.0)
#>  digest        0.6.29  2021-12-01 [1] CRAN (R 4.1.0)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi         1.0.2   2022-01-14 [1] CRAN (R 4.1.2)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.1.0)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.1.0)
#>  glue          1.6.1   2022-01-22 [1] CRAN (R 4.1.2)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools     0.5.2   2021-08-25 [1] CRAN (R 4.1.0)
#>  knitr         1.37    2021-12-16 [1] CRAN (R 4.1.0)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.1.0)
#>  magrittr      2.0.2   2022-01-26 [1] CRAN (R 4.1.0)
#>  pillar        1.6.5   2022-01-25 [1] CRAN (R 4.1.2)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.1.0)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.1.0)
#>  ragg          1.2.2   2022-02-21 [1] CRAN (R 4.1.2)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.1.0)
#>  rlang         1.0.0   2022-01-26 [1] CRAN (R 4.1.2)
#>  rmarkdown     2.11    2021-09-14 [1] CRAN (R 4.1.0)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.1.0)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.1.0)
#>  stringi       1.7.6   2021-11-29 [1] CRAN (R 4.1.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.1.0)
#>  styler        1.4.1   2021-03-30 [1] CRAN (R 4.1.0)
#>  systemfonts   1.0.4   2022-02-11 [1] CRAN (R 4.1.2)
#>  textshaping   0.3.6   2021-10-13 [1] CRAN (R 4.1.0)
#>  tibble        3.1.6   2021-11-07 [1] CRAN (R 4.1.0)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.1.0)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 4.1.0)
#>  withr         2.4.3   2021-11-30 [1] CRAN (R 4.1.0)
#>  xfun          0.29    2021-12-14 [1] CRAN (R 4.1.0)
#>  yaml          2.2.2   2022-01-25 [1] CRAN (R 4.1.2)
#> 
#> [1] /Users/MJ/R_Packages_4.1
#> [2] /Library/Frameworks/R.framework/Versions/4.1/Resources/library

Created on 2022-04-06 by the reprex package (v2.0.1)

Yes - systemfonts and ragg is much more strict about this than e.g. quartz. The family name is Lato and not Lato-LightItalic so passing the latter will not work. For now you'll need to register a new font to access weights not supported by the graphic engine. Will consider if there is a better way