davidgohel / rvg

https://davidgohel.github.io/rvg/
132 stars 15 forks source link

Text width / inaccurate justification in SVG #10

Closed econandrew closed 1 year ago

econandrew commented 7 years ago

This is probably not fixable, but since text is rendered in elements, the text width reported by e.g. grid::stringWidth may not be exactly what you get when the SVG is rendered. There is an interaction with justification since it seems R graphics calculates the justification rather than passing this to the device.

This isn't a big problem for left-justified or even center-justified text, but right-justified text can go quite wrong. In my case, I'm trying to combine a chart label with a line callout connecting it to the data, and the label can overlap the callout as a result, e.g. (where the rectangle is the calculated bounding box)

screenshot 2017-04-11 18 45 57

And correctly in PNG:

screenshot 2017-04-11 18 46 33

This seems to be a limitation on the amount of fine control SVG gives over text rendering. One solution would be to use SVG's own text-anchor attribute - then widths would still be calculated incorrectly but at least justification would be correct. But from scanning the source it seems like the justification is already dealt with before it reaches this package - although if there is some way around this, that would be great!

In the meantime I guess the workaround, in my case, is use callouts from the left-hand side of text labels, which is calculated reliably.

davidgohel commented 7 years ago

Thanks

I don't have time right now but I will invest that later.

David

davidgohel commented 1 year ago

Closing the issue as svg dev shifted in ggiraph only, and I think it is now fixed.