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

Element visibility in style attribute not respected #401

Open
BrennanGit opened this issue Jun 27, 2024 · 2 comments
Open

Element visibility in style attribute not respected #401

BrennanGit opened this issue Jun 27, 2024 · 2 comments

Comments

@BrennanGit
Copy link

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.

Copy link

Thank you for raising your first issue! Your help to improve svglib is much appreciated!

@claudep
Copy link
Collaborator

claudep commented Jun 27, 2024

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.

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

No branches or pull requests

2 participants