r-lib / svglite

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

unicode characters in plotmath expressions break all future metrics calculations #81

Closed ilia-kats closed 8 years ago

ilia-kats commented 8 years ago

If I plot a plotmath expression with a greek character as unicode symbol instead of the plotmath code (which works perfectly with cairo_pdf), all subsequent calls to strwidth return 0, leading to weird results when trying to precisely position text. Here's a minimal example:

library(svglite)
svglite()
plot(1:10)
strwidth("test", "user")
text(1, 9, expression(rho==1))
text(1, 8, 'ρ=1')
strwidth("test", "user")
text(x=grconvertX(0.95, 'npc', 'user'), y=grconvertY(0.9, 'npc', 'user'), "test", adj=c(1, 0))
text(3, 9, expression(ρ==1))
strwidth("test", "user")
text(3, 8, 'ρ=1')
text(x=grconvertX(0.95, 'npc', 'user'), y=grconvertY(0.7, 'npc', 'user'), "test", adj=c(1, 0))
dev.off()
lionel- commented 8 years ago

Thanks, this should be fixed on master.