Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

circles drawn in grid viewports are too big #93

Closed
trevorld opened this issue Nov 21, 2018 · 3 comments · Fixed by #97
Closed

circles drawn in grid viewports are too big #93

trevorld opened this issue Nov 21, 2018 · 3 comments · Fixed by #97

Comments

@trevorld
Copy link
Contributor

trevorld commented Nov 21, 2018

I'm observing svglite drawing circles that are too big when drawing circles in grid viewports. This issue doesn't seem to affect rectangles. I don't observe this behaviour with the cairo family of graphic devices.

Here is a minimal example where the circles should touch (but not significantly overlap):

library("grid")

draw_two_circles <- function() {
    pushViewport(viewport(width=unit(2, "inches"), height=unit(1, "inches")))
    pushViewport(viewport(x=0.25, width=unit(1, "inches"), height=unit(1, "inches")))
    grid.circle()
    popViewport()
    pushViewport(viewport(x=0.75, width=unit(1, "inches"), height=unit(1, "inches")))
    grid.circle()
    popViewport()
    popViewport()
}

svg("svg_test.svg"); draw_two_circles(); dev.off()
svglite::svglite("svglite_test.svg"); draw_two_circles(); dev.off()

svglite_test

@trevorld
Copy link
Contributor Author

Here is perhaps a better minimal example where the circle should be completely hidden by a rectangle (filling up the entire viewport) but instead when drawn in svglite the circle is too big and parts of it become visible (escaping the boundaries of its viewport).

library("grid")
draw_hidden_circle <- function() {
    pushViewport(viewport(width=0.5, height=0.5))
    grid.circle(gp=gpar(fill="blue"))
    grid.rect(gp=gpar(fill="yellow"))
    popViewport()
}


svg("svg_test.svg"); draw_hidden_circle(); dev.off()
svglite::svglite("svglite_test.svg"); draw_hidden_circle(); dev.off()

svglite_test

@vandenman
Copy link
Contributor

vandenman commented Jan 9, 2020

I'm also quite affected by this issue hence I'm reviving the thread (just tell me if that's a bad idea!).

Using some trial and error, I was able to find the source of the issue:

I modified the example above so that the resulting svg is square (svglite::svglite("~/svglite_test.svg", height = 7, width = 7)). Examining the resulting svg, the key issue is this:

                                   ↓  pt???
<circle cx='252.00' cy='252.00' r='126.00pt' style='stroke-width: 0.75; fill: #0000FF;' />
<rect x='126.00' y='126.00' width='252.00' height='252.00' style='stroke-width: 0.75; fill: #FFFF00;' />

The radius is rendered using pt. However, I think this is unnecessary. If I remove the pt and examine the result in Inkscape then the circle appears to have the correct size and is completely covered by the square.

I'm happy to create a fork in an attempt to fix this. However, this change may very well break things downstream (or at least make it look differently, causing unit tests to fail). Any pointers on how to proceed?

Edit:
it looks like 'pt' is just hardcoded on line 548 of https://github.com/r-lib/svglite/blob/master/src/devSVG.cpp .

@lionel-
Copy link
Member

lionel- commented Jan 9, 2020

I think this makes sense, could you send a PR please?

For the difference in outputs, vdiffr embeds its own version of svglite so at least this trouble is avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants