r-lib / svglite

A lightweight svg graphics device for R
https://svglite.r-lib.org
180 stars 39 forks source link

Output differs across platforms #69

Closed lionel- closed 8 years ago

lionel- commented 8 years ago

The following:

library("ggplot2")

p <- ggplot(mtcars, aes(disp, cyl)) + geom_point()

svg <- svglite::svgstring()
tryCatch(
  print(p),
  finally = grDevices::dev.off()
)
svg()

produces plots with different spacing on Linux and OSX.

issue-svg.zip

hadley commented 8 years ago

Can you try running this on both platforms:

gdtools::str_metrics("disp")
#>     width    ascent   descent 
#> 22.013672  8.636719  2.501953 
lionel- commented 8 years ago

In the Debian:testing docker I have:

gdtools::str_metrics("disp")
##    width   ascent  descent 
## 24.82031  9.12500  2.50000 

And on OSX:

gdtools::str_metrics("disp")
##   width  ascent descent 
##   22.01    8.64    2.50 
lionel- commented 8 years ago

Oops, with the full decimal places, the OSX metrics are exactly the same as yours.

hadley commented 8 years ago

Can you file on https://github.com/davidgohel/gdtools and see if David has any ideas?

davidgohel commented 8 years ago

Almost ready...

You can test it with the following R commands

devtools::install_github('davidgohel/fontquiver')
devtools::install_github('lionel-/fontHeavy')
devtools::install_github('davidgohel/gdtools')
devtools::install_github('davidgohel/svglite')

library(svglite)
htmlSVG(hist(rnorm(100)), font_description = font_desc_dejavu$new())

Using bitstream vera as default font is not ideal as this font does not offer serif italic neither serif bolditalic. I would prefer a mix of fonts: