r-lib / textshaping

Bindings to the HarfBuzz library for Text Shaping
Other
17 stars 8 forks source link

agg_png drops Greek characters used in an expression #24

Closed sw-rifai closed 3 years ago

sw-rifai commented 3 years ago

I noticed this first issue when using ggsave (https://github.com/tidyverse/ggplot2/issues/4562#issue-950952738). Greek characters are dropped after I installed ragg.

plot(sin, -pi, 2*pi, 
  main=expression(paste(alpha~beta~Delta~eta~gamma)), 
  xlab=expression(paste(frac(a,b))))

# that plot works

# but with agg_png... 
ragg::agg_png(filename='test.png',
  width = 1000,height=1000,units = 'px',
  pointsize = 25)
plot(sin, -pi, 2*pi, 
  main=expression(paste(alpha~beta~Delta~eta~gamma)), 
  xlab=expression(paste(frac(a,b))))
dev.off()
#> png 
#>   2

Created on 2021-08-01 by the reprex package (v2.0.0)

test

thomasp85 commented 3 years ago

I can't reproduce this so it is likely to be an issue on your system. Can you share some info about your setup?

sw-rifai commented 3 years ago

Sure thing, any other info I can provide?

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       Pop!_OS 20.04 LTS           
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language en_US:en                    
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/Los_Angeles         
#>  date     2021-08-02                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  cli           2.5.0   2021-04-26 [1] CRAN (R 4.0.3)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.3)
#>  evaluate      0.14    2019-05-28 [1] RSPM (R 4.0.2)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.3)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.3)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.0.3)
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 4.0.3)
#>  knitr         1.33    2021-04-24 [1] CRAN (R 4.0.3)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 4.0.3)
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 4.0.3)
#>  rmarkdown     2.9     2021-06-15 [1] CRAN (R 4.0.3)
#>  rstudioapi    0.13    2020-11-12 [1] CRAN (R 4.0.3)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  stringi       1.6.2   2021-05-17 [1] CRAN (R 4.0.3)
#>  stringr       1.4.0   2019-02-10 [1] RSPM (R 4.0.2)
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.3)
#>  xfun          0.24    2021-06-15 [1] CRAN (R 4.0.3)
#>  yaml          2.2.1   2020-02-01 [1] RSPM (R 4.0.2)
#> 
#> [1] /home/sami/R/x86_64-pc-linux-gnu-library/4.0
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library

Created on 2021-08-02 by the reprex package (v2.0.0)

pooranis commented 3 years ago

I had the same symptom of greek letters not showing up when using ragg devices. In case this helps someone else, for me, the problem was I had 2 fonts (variants? not duplicates) installed from the same family "Symbol" which appears to be the family ragg uses on macOS for symbol/plotmath characters - a system font and another user(me)-installed one. I disabled the non-system one, and then the symbols worked with ragg.

I used systemfonts::system_fonts() and systemfonts::match_font to investigate the possible fonts ragg could be using. I don't know if it was something wrong with the particular .ttf for the non-system font or just that there were 2 fonts with the same family name. That font works ok in other programs.

thomasp85 commented 3 years ago

@sw-rifai can you share the output of systemfonts::match_font('Symbol')?

sw-rifai commented 3 years ago
systemfonts::match_font('Symbol')
#> $path
#> [1] "/usr/share/fonts/opentype/urw-base35/StandardSymbolsPS.otf"
#> 
#> $index
#> [1] 0
#> 
#> $features
#> NULL

Created on 2021-10-06 by the reprex package (v2.0.0)

thomasp85 commented 3 years ago

Hmm... there is something weird going on with that font - I'll try to investigate

thomasp85 commented 3 years ago

So, the issue seems to be that the font does not have a unicode character map, i.e. a mapping from unicode codes to the glyphs in the font. Because of this, Freetype marks the requested glyphs as non-existing.

I'm afraid this means that this issue is a wontfix - The whole fontstack relies heavily on unicode encoding to allow all the script support available. However, you can install a more modern symbol font and set that as your symbol font using font-config