use of org.apache.batik.svggen.SVGGraphics2D in project mzmine2 by mzmine.
the class SwingExportUtil method writeToSVG.
public static void writeToSVG(JComponent panel, File fileName) throws IOException {
// print the panel to pdf
int width = panel.getWidth();
int height = panel.getWidth();
logger.info(() -> MessageFormat.format("Exporting panel to SVG file (width x height; {0} x {1}): {2}", width, height, fileName.getAbsolutePath()));
// Get a DOMImplementation
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
svgGenerator.setSVGCanvasSize(new Dimension(width, height));
panel.print(svgGenerator);
// we want to use CSS style attribute
boolean useCSS = true;
try (Writer out = new OutputStreamWriter(new FileOutputStream(fileName), "UTF-8")) {
svgGenerator.stream(out, useCSS);
}
}
Aggregations