Closed mb706 closed 1 year ago
Hmm interesting, it looks like the values for sx
and sy
in the C code are twice what they should be, but no idea why.
I've added a workaround but I need to investigate why this started happening. I'm pretty sure I tested this before. Maybe it depends on whether or not the svg has a viewport set?
OK I have pushed a new version with this fix to CRAN. I'm still not sure where this problem started appearing but it looks like the fix is easy.
Hi didn't know whether best to open a new issue or resurrect this one:
I'm still getting this problem (or similar) in 2.4.0 in the rsvg_pdf
and rsvg_svg
calls.
I hope this is enough to demonstrate, (and is not just an issue with my setup):
library(rsvg)
svg_text <- '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="100pt"
height="100pt"
viewBox="0 0 100 100"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<g>
<rect
style="fill:#b3b3b3;stroke:#000000;"
width="90"
height="90"
x="5"
y="5" />
<rect
style="fill:#b3b3b3;stroke:#000000;"
width="20"
height="20"
x="60"
y="60" />
</g>
</svg>
'
# a simple box centred in the pdf with a smaller box in the bottom right
expected = tempfile(fileext = ".expected.pdf")
rsvg::rsvg_pdf(charToRaw(svg_text),file = expected)
rstudioapi::viewer(expected)
# I expect the same image to be scaled to 50x50
# instead I see only the top left corner
observed = tempfile(fileext = ".observed.pdf")
rsvg::rsvg_pdf(charToRaw(svg_text),file = observed,width = 50,height = 50)
rstudioapi::viewer(observed)
# rsvg to svg also produces image that is not scaled but viewport is smaller.
observed2 = tempfile(fileext = ".observed.svg")
rsvg::rsvg_svg(charToRaw(svg_text),file = observed2,width = 50,height = 50)
rstudioapi::viewer(observed2)
# Inspecting the new SVG there is only one path element - the smaller box is no
# longer there.
readLines(observed2)
# rsvg to bitmap works as expected
bitmap = rsvg::rsvg(charToRaw(svg_text),width = 50,height = 50)
im <- magick::image_read(bitmap)
grid::grid.raster(im)
# sessionInfo()
# R version 4.2.2 Patched (2022-11-10 r83330)
# Platform: x86_64-pc-linux-gnu (64-bit)
# Running under: Ubuntu 22.04.1 LTS
#
# Matrix products: default
# BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
# LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#
# locale:
# [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8 LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 LC_PAPER=en_GB.UTF-8 LC_NAME=C LC_ADDRESS=C
# [10] LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
#
# attached base packages:
# [1] stats graphics grDevices datasets utils methods base
#
# other attached packages:
# [1] rsvg_2.4.0
N.B. my librsvg2-2
is at version 2.52.2+dfsg-3
if that is relevant
file1532e38e37382.expected.pdf file1532e378b02d1.observed.pdf
When I apply scaling by specifying a width or height, the resulting image has the correct size, but the content is incorrectly cropped. It looks like the underlying picture is scaled twice.
This works (using the example from #30):
Scaling the image 2x does not work; the resulting image has the correct width 1024, but the image looks like it was scaled 4x and then cropped:
This may be due to a change in the librsvg API since scaling used to work until recently. I am not sure to what degree this is related to https://github.com/ropensci/rsvg/issues/30, but since the specific example in that issue currently works I am opening a new issue.
Session Info