ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
459 stars 64 forks source link

magick doesn't accept font names with spaces #173

Open jzadra opened 5 years ago

jzadra commented 5 years ago

Magick does not properly apply fonts when given values that have spaces, despite the fonts being in types.xml and showing as a result of convert -list font.

If you manually edit types.xml and remove the spaces from the family value, it applies the font correctly.

It appears that what it is doing is taking the first word, and dropping the rest. So if you have a font that matches the first word, it works. But this causes problems when you have bold or italic versions of the font named things like "Roboto", "Roboto Bold", "Roboto Condensed", etc.

For example, note that specifying "Times" instead of "Times New Roman works:

require(magick)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.40
#> Enabled features: fontconfig, freetype, fftw, ghostscript, lcms, webp, x11
#> Disabled features: cairo, pango, rsvg
image_blank(500,500, color = "yellow") %>%
  image_annotate("12345 TEST", location = "+0+0", font = "Times", size = 118, color = "black") %>% 
  image_annotate("12345 TEST", location = "+0+0", size = 118, color = "red")

Created on 2019-02-04 by the reprex package (v0.2.1)

And that specifying "Times" and "Times New Roman" produces the same font results:

require(magick)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.40
#> Enabled features: fontconfig, freetype, fftw, ghostscript, lcms, webp, x11
#> Disabled features: cairo, pango, rsvg
image_blank(500,500, color = "yellow") %>%
  image_annotate("12345 TEST", location = "+0+0", font = "Times", size = 118, color = "black") %>% 
  image_annotate("12345 TEST", location = "+0+0", font = "Times New Roman", size = 118, color = "red") 

Created on 2019-02-04 by the reprex package (v0.2.1)

An example of how this prevents using different versions of the same font:

require(magick)
#> Loading required package: magick
#> Linking to ImageMagick 6.9.9.40
#> Enabled features: fontconfig, freetype, fftw, ghostscript, lcms, webp, x11
#> Disabled features: cairo, pango, rsvg
image_blank(500,500, color = "yellow") %>%
  image_annotate("12345 TEST", location = "+0+0", font = "Arial", size = 118, color = "black") %>% 
  image_annotate("12345 TEST", location = "+0+0", font = "Arial Bold", size = 118, color = "red") 

Created on 2019-02-04 by the reprex package (v0.2.1)

dmi3kno commented 5 years ago

I believe this is related to your operating system font management, not magick. Here's result on Ubuntu

library(magick)

image_blank(500,500, color = "yellow") %>%
  image_annotate("12345 TEST", location = "+0+0", font = "Roboto", size = 118, color = "black") %>% 
  image_annotate("12345 TEST", location = "+0+0", font = "Roboto Condensed", size = 118, color = "red")

preview

sessionInfo() ```r R version 3.6.1 (2019-07-05) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.2 LTS Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8 [4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] magick_2.0.9000 loaded via a namespace (and not attached): [1] compiler_3.6.1 magrittr_1.5 tools_3.6.1 curl_3.3 urltools_1.7.3 Rcpp_1.0.1 [7] triebeard_0.3.0 pdftools_2.2 qpdf_1.1 robotstxt_0.6.2 askpass_1.1 ```

And here's results on Windows


library(magick)

image_blank(500,500, color = "yellow") %>%
  image_annotate("Arial Narrow", location = "+0+0", font = "Arial Narrow", size = 50, color = "black") %>% 
  image_annotate("Times New Roman", location = "+0+50", font = "Times New Roman", size = 50, color = "red") %>%
  image_annotate("Comic Sans", location = "+0+100", font = "Comic Sans", size = 50, color = "green") %>% 
  image_annotate("Freestyle Script", location = "+0+180", font ="Freestyle Script" , size = 50, color = "blue")

preview

sessionInfo() ```r R version 3.6.0 (2019-04-26) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 17763) Matrix products: default locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] magick_2.0.9000 loaded via a namespace (and not attached): [1] Rcpp_1.0.1 Rttf2pt1_1.3.7 rstudioapi_0.10 magrittr_1.5 R6_2.4.0 [6] spiderbar_0.2.1 stringr_1.4.0 httr_1.4.0 globals_0.12.4 tools_3.6.0 [11] pkgbuild_1.0.3 parallel_3.6.0 cli_1.1.0 extrafontdb_1.0 withr_2.1.2 [16] remotes_2.0.4 rprojroot_1.3-2 robotstxt_0.6.2 digest_0.6.19 assertthat_0.2.1 [21] crayon_1.3.4 processx_3.3.1 callr_3.2.0 ps_1.3.0 codetools_0.2-16 [26] curl_3.3 future.apply_1.3.0 stringi_1.4.3 compiler_3.6.0 backports_1.1.4 [31] prettyunits_1.0.2 extrafont_0.17 future_1.14.0 listenv_0.7.0 ```
jeroen commented 5 years ago

Finding and rendering fonts is really specific to the OS and the version of imagemagick. Unfortunately the builds of imagemagick from homebrew are configured without fontconfig support.

However the magick CRAN binary package should be able to find most fonts.

jzadra commented 5 years ago

Sorry for the lack of info - my issues are occurring on OSX Mojave.