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

visibility ignored using svg2rlg and renderPM.drawToFile #359

Open
RobertSchueler opened this issue Oct 6, 2022 · 3 comments
Open

visibility ignored using svg2rlg and renderPM.drawToFile #359

RobertSchueler opened this issue Oct 6, 2022 · 3 comments

Comments

@RobertSchueler
Copy link

An svg element where the attribute "visibility" is set to "hidden" should not be plotted, but it is.

Small example:

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM

svg_string = """
<ns0:svg xmlns:ns0="http://www.w3.org/2000/svg" xmlns:ns1="http://www.inkscape.org/namespaces/inkscape" xmlns:ns2="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="210mm" height="297mm" viewBox="0 0 210 297" version="1.1" id="svg5" ns1:version="1.1 (c68e22c387, 2021-05-23)" ns2:docname="test.svg">
  <ns2:namedview id="namedview7" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" ns1:pageshadow="2" ns1:pageopacity="0.0" ns1:pagecheckerboard="0" ns1:document-units="mm" showgrid="false" ns1:zoom="0.67081229" ns1:cx="396.53418" ns1:cy="561.25984" ns1:window-width="1680" ns1:window-height="987" ns1:window-x="-8" ns1:window-y="-8" ns1:window-maximized="1" ns1:current-layer="layer1" />
  <ns0:defs id="defs2" />
  <ns0:g ns1:label="Ebene 1" ns1:groupmode="layer" id="layer1">
    <ns0:path style="fill:none;stroke:#FF0000;stroke-width:5.63426" d="M 93.91599,350.32155 V 204.97537 h 84.08396 84.08396 l -5.14971,13.04389 c -25.58743,64.81145 -44.58875,161.07403 -52.08331,263.85921 l -1.00544,13.78925 H 148.88072 93.91599 Z" id="path948" transform="scale(0.26458333)" ns1:label="LustigerPfad" visibility="hidden" />
  </ns0:g>
</ns0:svg>
"""

with open("my.svg", "w", encoding="utf-8") as file:
    file.write(svg_string)

drawing = svg2rlg("my.svg")

renderPM.drawToFile(drawing, "my.png", fmt="PNG")

Resulting image:

my

@claudep
Copy link
Collaborator

claudep commented Oct 6, 2022

Sure, svglib does only support a subset of the (did I say huge??) CSS specification, so visibility is currently not handled. Patch welcome!

@deeplook
Copy link
Owner

deeplook commented Oct 6, 2022

Sounds like a low hanging froot. But if you generate the SVG yourself, you could of course skip the invisible le element. 😉

@RobertSchueler
Copy link
Author

Sounds like a low hanging froot. But if you generate the SVG yourself, you could of course skip the invisible le element. 😉

Yes, this is exactly what I do right now. But it would be nice if I could switch visibility on and off as I wish without loosing everything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants