r-lib / svglite

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

Japanese text placed wrong #59

Closed okumuralab closed 8 years ago

okumuralab commented 8 years ago
svglite("dnorm.svg", width=7, height=4)
curve(dnorm(x), xlim=c(-3,3), main="正規分布")
dev.off()

places Japanese string "正規分布" in wrong position. If the width cannot be determined, it'd be better to center the text like <text ... text-anchor="middle">正規分布</text>.

A related issue: cex=0.5 doesn't work.

hadley commented 8 years ago

The underlying problem is

gdtools::str_metrics("正規分布")
#>  width  ascent descent 
#>     0       0       0 

I think because R has some fall back that it uses when the symbol is not available in the current font

hadley commented 8 years ago

@davidgohel any idea why this fails, but it works ok in R? The base R code is at https://github.com/wch/r-source/blob/master/src/library/grDevices/src/cairo/cairoFns.c#L524.