deeplook/svglib

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:
image

But with svglib we get:
image

And rendered directly in edge we get:
image



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.