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)
And correctly in PNG:
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.
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)
And correctly in PNG:
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.