svgSalamander icon indicating copy to clipboard operation
svgSalamander copied to clipboard

SVG renders solid black shapes

Open bancika opened this issue 4 years ago • 5 comments

No matter what I do, all I get are black shapes.

Here's my code below. Due to the nature of my project, I need to embed the SVG file, so it's stored as byte array (data variable below).

  private SVGDiagram getSvgDiagram() {
    if (svgDiagram == null) {
      ByteArrayInputStream bis = new ByteArrayInputStream(data);
      SVGUniverse universe = new SVGUniverse();
//      universe.setImageDataInlineOnly(true);
      //universe.setVerbose(true);
      try {
        URI url = universe.loadSVG(bis, "SVG-" + Integer.toHexString(new Random(System.currentTimeMillis()).nextInt()));
        svgDiagram = universe.getDiagram(url);  
        svgDiagram.setIgnoringClipHeuristic(true);
      } catch (IOException e) {
        LOG.error("Error loading SVG", e);
      }
    }
    return svgDiagram;
  }

to render it on my Graphics2D I use

svgDiagram.render(g2d);

Here's one of the files I tried loading, it loads as a solid black rectangle, but playing with alpha it's possible to see that all shapes are there, just black.

diylc.zip

bancika avatar Jul 10 '21 11:07 bancika

Another issue with that code is that some files make it hang when calling svgDiagram.render(g2d);

This is an example of such file pcb.zip

I tried opening it in few other apps and loads nicely.

What am I missing? Thanks!

bancika avatar Jul 10 '21 11:07 bancika

I had a look at what was going on. The problem is that your svg is relying on style sheet notation and SVG Salamander currently doesn't handle style sheets. It's something that has been on the back burner for a while - I'm not sure when I'll be able to implement it.

If you can export your SVG without style sheets, it ought to work.

blackears avatar Jul 10 '21 21:07 blackears

Thanks, that works!

bancika avatar Jul 10 '21 22:07 bancika

Just stumbled across this thread because of the same issue. @blackears is style sheets the only feature of SVGs that is not supported or are there others I should be aware of as well? And is there any way workaround for when you don't have the ability to re-export the svg and must work with one that includes a style sheet?

mgroth0 avatar Jan 06 '23 21:01 mgroth0

This implementation also does not support most of Javascript (I wrote a my own interpreter that can evaluate expressions, but that's all). It also does not support compositing layers or raster effects. There might be other omissions, but those are the ones I know of.

You might be able to import your SVG into a program like Inkscape (or so,ething else that can import svg) and then reexport without a stylesheet.

blackears avatar Jan 07 '23 04:01 blackears