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

SVG renders solid black shapes #75

Open
bancika opened this issue Jul 10, 2021 · 5 comments
Open

SVG renders solid black shapes #75

bancika opened this issue Jul 10, 2021 · 5 comments

Comments

@bancika
Copy link

bancika commented Jul 10, 2021

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
Copy link
Author

bancika commented Jul 10, 2021

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 bancika changed the title Any SVG renders black and white SVG renders solid black shapes Jul 10, 2021
@blackears
Copy link
Owner

blackears commented Jul 10, 2021

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.

@bancika
Copy link
Author

bancika commented Jul 10, 2021

Thanks, that works!

@mgroth0
Copy link

mgroth0 commented Jan 6, 2023

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?

@blackears
Copy link
Owner

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.

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

3 participants