coolbutuseless / minisvg

Create SVG documents with R
https://coolbutuseless.github.io/package/minisvg/
MIT License
31 stars 3 forks source link

Remove internal quotes in "url('#id')" #4

Closed dmi3kno closed 4 years ago

dmi3kno commented 4 years ago

Apparently librsvg (which is an underlying C library behind rsvg and also base svg rendering library in GNOME e.g. also in GIMP and Inkscape) does not allow hashtagged identifiers inside url() call to be quoted.

library(minisvg)

doc <- svg_doc(width = 300, height = 30)
pat  <- stag$defs()$pattern(id = 'motif', width=60, height=30, 
                            patternUnits = 'userSpaceOnUse')
pat$add('rect', x = 0, y=0, width = 30, height = 30, fill='black')
doc$append(pat)
doc$rect(x=0, y=0, width="100%", height="100%", fill=pat) 
doc$show()
doc
#> <?xml version="1.0" encoding="UTF-8"?>
#> <svg width="300" height="30" viewBox="0 0 300 30" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
#>   <pattern id="motif" width="60" height="30" patternUnits="userSpaceOnUse">
#>     <rect x="0" y="0" width="30" height="30" fill="black" />
#>   </pattern>
#>   <rect fill="url('#motif')" x="0" y="0" width="100%" height="100%" />
#> </svg>

The last line before closing tag should instead read

#> <rect fill="url(#motif)" x="0" y="0" width="100%" height="100%" />

Then the document will be valid and can be rendered by librsvg, i.e. read by rsvg, magick and the like

coolbutuseless commented 4 years ago

Thanks for the bug report (and all the other testing you're doing!)

I will fix this for the next release.

coolbutuseless commented 4 years ago

Fixed in https://github.com/coolbutuseless/minisvg/commit/ab5237f6c4d51408b649f3ebe95e6df5b52d5e81

dmi3kno commented 4 years ago

Thank you very much!