Element visibility in style attribute not respected
Opened this issue · 2 comments
Hi, I love that a pure python svg library exists so thanks for that.
I'm trying to write a cross-platform sphinx script and requiring platform-fussy binaries like cairo and inkscape just to convert svg->pdf is a complexity I did not need.
There is inconsistency in visibility attributes and styles.
I noticed this whilst using an svg with layers (as groups) where some of them are disabled using style="display:none"
.
This rendered as expected in cairosvg but included all the layers in svglib's output.
I'll include a simple svg to demonstrate the different flavours of the issue.
This renders a series of labels with corresponding black boxes which should conditionally render to match the label.
<svg height="200" width="240" xmlns="http://www.w3.org/2000/svg">
<text x="20" y="15">Always visible</text>
<rect x="5" y="5" width="10" height="10" />
<text x="20" y="35">display none attribute</text>
<rect x="5" y="25" width="10" height="10" display="none" />
<text x="20" y="55">visibility hidden attribute</text>
<rect x="5" y="45" width="10" height="10" visibility="hidden" />
<text x="20" y="75">display none style</text>
<rect x="5" y="65" width="10" height="10" style="display:none" />
<text x="20" y="95">visibility hidden style</text>
<rect x="5" y="85" width="10" height="10" style="visibility:hidden" />
<text x="20" y="115">visible group</text>
<g>
<rect x="5" y="105" width="10" height="10" />
</g>
<text x="20" y="135">display none group</text>
<g display="none">
<rect x="5" y="125" width="10" height="10" />
</g>
<text x="20" y="155">visibility hidden group</text>
<g visibility="hidden">
<rect x="5" y="145" width="10" height="10" />
</g>
<text x="20" y="175">display none group style</text>
<g style="display: none;">
<rect x="5" y="165" width="10" height="10" />
</g>
<text x="20" y="195">visibility hidden group style</text>
<g style="visibility: hidden;">
<rect x="5" y="185" width="10" height="10" />
</g>
</svg>
When converted to pdf via cairosvg we get:
And rendered directly in edge we get:
-
when
display="none"
is set as an attribute, it always works as expected (which makes sense looking at https://github.com/deeplook/svglib/blob/main/svglib/svglib.py#L541 and https://github.com/deeplook/svglib/blob/main/svglib/svglib.py#L579 ). -
Interestingly it also seems to respect
display:none
in the style of a non-group element (which I can't seem to find a path to in svglib.py). -
display:none
in the style of a group in not respected (which is the failure case I first saw) -
"visibility hidden" does not seem to be respected anywhere.
I'd love for this to match the cairosvg output, but right now we're just modifying our svgs to turn the display style into an attribute.
Thank you for raising your first issue! Your help to improve svglib is much appreciated!
Thanks for the report. The package is maintained, but few active development is done. If you provide some code through PR, we will happily review it.