weisJ / jsvg

Java SVG renderer
MIT License
132 stars 7 forks source link

Cyclic dependency involving node 'white' detected while reading an SVG created by codecov. #91

Open bric3 opened 3 weeks ago

bric3 commented 3 weeks ago

Suppose the following SVG created by https://codecov.io tool

With JSVG 1.6.1, the following code fails with the cyclic dependency.

new SVGLoader().load(URI.create("https://camo.githubusercontent.com/ca6f04cc3d7d26ba9f9bce39862c3b44db4ffb93683580829f33b7940433d6d2/68747470733a2f2f636f6465636f762e696f2f67682f73706f636b6672616d65776f726b2f73706f636b2f70756c6c2f313235302f6772617068732f747265652e7376673f77696474683d363530266865696768743d313530267372633d707226746f6b656e3d786e773657457a64566f").toURL())
Oct 03, 2024 11:03:55 AM com.github.weisj.jsvg.parser.css.impl.SimpleCssParser$Parser expected
WARNING: Expected 'CURLY_OPEN' but got 'Token{type=CLASS_NAME, data='s'}'
Oct 03, 2024 11:03:55 AM com.github.weisj.jsvg.parser.css.impl.SimpleCssParser$Parser expected
WARNING: Expected 'CURLY_OPEN' but got 'Token{type=EOF, data='null'}'
Oct 03, 2024 11:03:55 AM com.github.weisj.jsvg.parser.SVGLoader load
WARNING: Could not load SVG 
java.lang.IllegalStateException: Cyclic dependency involving node 'white' detected.
    at com.github.weisj.jsvg.parser.ParsedElement.cyclicDependencyDetected(ParsedElement.java:126)
    at com.github.weisj.jsvg.parser.ParsedElement.nodeEnsuringBuildStatus(ParsedElement.java:83)
    at com.github.weisj.jsvg.parser.ParsedDocument.getElementById(ParsedDocument.java:53)
    at com.github.weisj.jsvg.parser.DefaultElementLoader.loadElement(DefaultElementLoader.java:56)
    at com.github.weisj.jsvg.parser.AttributeNode.getElementByUrl(AttributeNode.java:126)
    at com.github.weisj.jsvg.parser.AttributeNode.getPaint(AttributeNode.java:186)
    at com.github.weisj.jsvg.renderer.PaintContext.parse(PaintContext.java:78)
    at com.github.weisj.jsvg.nodes.ShapeNode.build(ShapeNode.java:84)
    at com.github.weisj.jsvg.parser.ParsedElement.build(ParsedElement.java:116)
    at com.github.weisj.jsvg.parser.ParsedElement.build(ParsedElement.java:114)
    at com.github.weisj.jsvg.parser.ParsedElement.build(ParsedElement.java:114)
    at com.github.weisj.jsvg.parser.ParsedElement.build(ParsedElement.java:114)
    at com.github.weisj.jsvg.parser.SVGDocumentBuilder.build(SVGDocumentBuilder.java:178)
    at com.github.weisj.jsvg.parser.StaxSVGLoader.load(StaxSVGLoader.java:169)
    at com.github.weisj.jsvg.parser.SVGLoader.load(SVGLoader.java:111)
    at com.github.weisj.jsvg.parser.SVGLoader.load(SVGLoader.java:62)
    at com.github.weisj.jsvg.parser.SVGLoader.load(SVGLoader.java:54)
    at com.github.weisj.jsvg.parser.SVGLoader.load(SVGLoader.java:49)
    at sandbox.swing.QuickImageViewer.main(QuickImageViewer.kt:35)

SVG attached : treemap

weisJ commented 3 weeks ago

From a quick glance I think the following is happening: The CSS parser is incorrectly applying the rect.s rule to the rect inside the pattern#white which tries to apply the mask referencing said pattern.

bric3 commented 2 weeks ago

I'm not sure on how to help fix that at this time 😵

weisJ commented 2 weeks ago

The current CSS parser is very rudimentary. I am currently working on a bit more advanced version which should support loads more selectors.

weisJ commented 1 day ago

See #93

bric3 commented 7 hours ago

Thank you, I'll try to find some time to try code in #94.