Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

element_marquee() does not use font families created with register_font() #38

Open
petrbouchal opened this issue Sep 19, 2024 · 0 comments

Comments

@petrbouchal
Copy link

When a style uses a font family created using systemfonts::register_font(), that font is not picked up in text elements in ggplot2 created using element_marquee() - see first plot in reprex below. When the same font file is used directly by referring to the family found in the system font list, it is used correctly in the text element - see second plot. At the same time, plain ggplot2 does pick up the family name created via register_font() - see third plot.

Reprex below was created on MacOS but the same occurs on Ubuntu.

The workaround is to install the fonts on the system, but that is much less convenient and not always feasible.

Reprex

library(ggplot2)
library(marquee)
library(systemfonts)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ragg)
fd <- "/Users/petr/Library/Fonts/"

clear_registry()
systemfonts::register_font("Blahfont", plain = file.path(fd, "Consolas.ttf"))

registry_fonts()
#> # A tibble: 4 × 7
#>   path                                 index family style weight italic features
#>   <chr>                                <int> <chr>  <chr> <ord>  <lgl>  <list>  
#> 1 /Users/petr/Library/Fonts//Consolas…     0 Blahf… Regu… normal FALSE  <int>   
#> 2 /Users/petr/Library/Fonts//Consolas…     0 Blahf… Bold  bold   FALSE  <int>   
#> 3 /Users/petr/Library/Fonts//Consolas…     0 Blahf… Ital… normal TRUE   <int>   
#> 4 /Users/petr/Library/Fonts//Consolas…     0 Blahf… Bold… bold   TRUE   <int>
match_fonts("Blahfont")
#> # A tibble: 1 × 3
#>   path                                    index features  
#>   <chr>                                   <int> <list>    
#> 1 /Users/petr/Library/Fonts//Consolas.ttf     0 <font_ftr>

system_fonts() |> filter(family == "Consolas")
#> # A tibble: 4 × 9
#>   path                    index name  family style weight width italic monospace
#>   <chr>                   <int> <chr> <chr>  <chr> <ord>  <ord> <lgl>  <lgl>    
#> 1 /Users/petr/Library/Fo…     0 Cons… Conso… Bold… bold   norm… TRUE   TRUE     
#> 2 /Users/petr/Library/Fo…     0 Cons… Conso… Ital… normal norm… TRUE   TRUE     
#> 3 /Users/petr/Library/Fo…     0 Cons… Conso… Regu… normal norm… FALSE  TRUE     
#> 4 /Users/petr/Library/Fo…     0 Cons… Conso… Bold  bold   norm… FALSE  TRUE

s1 <- marquee::classic_style() |> modify_style("body", family = "Blahfont")
s2 <- marquee::classic_style() |> modify_style("body", family = "Consolas")

ggplot(mtcars) +
  geom_point(aes(mpg, wt)) +
  theme(text = element_marquee(style = s1, width = NA)) +
  labs(title = "Blah blah")

ggplot(mtcars) +
  geom_point(aes(mpg, wt)) +
  theme(text = element_marquee(style = s2, width = NA)) +
  labs(title = "Blah blah")

ggplot(mtcars) +
  geom_point(aes(mpg, wt)) +
  theme(text = element_text(family = "Blahfont")) +
  labs(title = "Blah blah")

ggplot(mtcars) +
  geom_point(aes(mpg, wt)) +
  theme(text = element_text(family = "Consolas")) +
  labs(title = "Blah blah")

Created on 2024-09-19 with reprex v2.1.1

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.1 (2024-06-14)
#>  os       macOS Sonoma 14.6.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Europe/Prague
#>  date     2024-09-19
#>  pandoc   3.2.1 @ /opt/homebrew/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.6.3.9000 2024-07-22 [1] Github (r-lib/cli@d9febb5)
#>  colorspace    2.1-0      2023-01-23 [1] CRAN (R 4.4.0)
#>  curl          5.2.1      2024-03-01 [1] CRAN (R 4.4.0)
#>  digest        0.6.36     2024-06-23 [1] CRAN (R 4.4.0)
#>  dplyr       * 1.1.4      2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate      0.24.0     2024-06-10 [1] CRAN (R 4.4.0)
#>  fansi         1.0.6      2023-12-08 [1] CRAN (R 4.4.0)
#>  farver        2.1.2      2024-05-13 [1] CRAN (R 4.4.0)
#>  fastmap       1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  fs            1.6.4      2024-04-25 [1] CRAN (R 4.4.0)
#>  generics      0.1.3      2022-07-05 [1] CRAN (R 4.4.0)
#>  ggplot2     * 3.5.1      2024-04-23 [1] CRAN (R 4.4.0)
#>  glue          1.7.0      2024-01-09 [1] CRAN (R 4.4.0)
#>  gtable        0.3.5      2024-04-22 [1] CRAN (R 4.4.0)
#>  highr         0.11       2024-05-26 [1] CRAN (R 4.4.0)
#>  htmltools     0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  knitr         1.48       2024-07-07 [1] CRAN (R 4.4.0)
#>  labeling      0.4.3      2023-08-29 [1] CRAN (R 4.4.0)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  marquee     * 0.1.0      2024-05-28 [1] CRAN (R 4.4.0)
#>  munsell       0.5.1      2024-04-01 [1] CRAN (R 4.4.0)
#>  pillar        1.9.0      2023-03-22 [1] CRAN (R 4.4.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.4.0)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
#>  ragg        * 1.3.3      2024-09-11 [1] CRAN (R 4.4.1)
#>  reprex        2.1.1      2024-07-06 [1] CRAN (R 4.4.0)
#>  rlang         1.1.4.9000 2024-07-22 [1] Github (r-lib/rlang@f185e62)
#>  rmarkdown     2.27       2024-05-17 [1] CRAN (R 4.4.0)
#>  rstudioapi    0.16.0     2024-03-24 [1] CRAN (R 4.4.0)
#>  scales        1.3.0      2023-11-28 [1] CRAN (R 4.4.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.4.0)
#>  systemfonts * 1.1.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  textshaping   0.4.0      2024-05-24 [1] CRAN (R 4.4.0)
#>  tibble        3.2.1      2023-03-20 [1] CRAN (R 4.4.0)
#>  tidyselect    1.2.1      2024-03-11 [1] CRAN (R 4.4.0)
#>  utf8          1.2.4      2023-10-22 [1] CRAN (R 4.4.0)
#>  vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
#>  withr         3.0.0      2024-01-16 [1] CRAN (R 4.4.0)
#>  xfun          0.45       2024-06-16 [1] CRAN (R 4.4.0)
#>  xml2          1.3.6      2023-12-04 [1] CRAN (R 4.4.0)
#>  yaml          2.3.9      2024-07-05 [1] CRAN (R 4.4.0)
#> 
#>  [1] /Users/petr/Library/R/4.4/library
#>  [2] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant