jfree / jfreesvg

A fast, lightweight Java library for creating Scalable Vector Graphics (SVG) output.
http://www.jfree.org/jfreesvg
GNU General Public License v3.0
319 stars 58 forks source link

Can an existing SVG be loaded to include in the newly created SVG #34

Open FDelporte opened 3 years ago

FDelporte commented 3 years ago

I see multiple writeToSVG methods are included in SVGUtils, but I'm wondering if I can also load an existing SVG to add it to the SVG I'm creating?

jfree commented 3 years ago

No, that's not supported, since the goal of the library is to provide a Graphics2D API and translate the input that hits that interface into SVG output.

One way that feature could be added, without stepping outside of the Graphics2D API, would be to enhance the basic drawImage() method so that it checks for a custom RenderingHint. Suppose the value of the rendering hint is a String containing the SVG element that should take the place of the Image that is passed - then JFreeSVG could simply insert the element instead of handling the supplied image. The nice part of this approach (assuming you have a corresponding image for your SVG) is that switching to another Graphics2D implementation (for example JFreePDF) would still work, since any other Graphics2D implementation can handle the Image (and ignore the SVG in the rendering hint).

Alternatively, if you don't need the Graphics2D compatibility, you could simply add a drawSVG() or embedSVGElement() method to the API and insert the supplied SVG element into the output. I don't know what issues might arise from conflicts between the "inner" SVG (supplied by you) and the "outer" SVG (being generated by JFreeSVG). Presumable the SVG specification has some rules about it, but I didn't study this case in any detail.