MCPcopy Create free account
hub / github.com/rambaut/figtree / exportSVGFile

Method exportSVGFile

src/figtree/application/FigTreeFrame.java:1283–1302  ·  view source on GitHub ↗
(JComponent component, OutputStream stream)

Source from the content-addressed store, hash-verified

1281 }
1282
1283 private final static void exportSVGFile(JComponent component, OutputStream stream) throws IOException {
1284 // Get a DOMImplementation and create an XML document
1285 DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
1286 org.w3c.dom.Document document = domImpl.createDocument(null, "svg", null);
1287
1288 // Create an instance of the SVG Generator
1289 SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
1290
1291 component.paint(svgGenerator);
1292 Element svgRoot = svgGenerator.getRoot();
1293 Rectangle2D bounds = component.getBounds();
1294 String viewBox = "0 0 " + bounds.getWidth() + " " + bounds.getHeight();
1295 svgRoot.setAttributeNS(null, svgGenerator.SVG_VIEW_BOX_ATTRIBUTE, viewBox);
1296 svgRoot.setAttributeNS(null, svgGenerator.SVG_WIDTH_ATTRIBUTE, Double.toString(bounds.getWidth()));
1297 svgRoot.setAttributeNS(null, svgGenerator.SVG_HEIGHT_ATTRIBUTE, Double.toString(bounds.getHeight()));
1298
1299 // Write svg file
1300 Writer out = new OutputStreamWriter(stream, "UTF-8");
1301 svgGenerator.stream(svgRoot, out, true /* use css */, false /* escaped */);
1302 }
1303
1304 public final static void exportPDFFile(JComponent component, OutputStream stream) throws DocumentException {
1305 Rectangle2D bounds = component.getBounds();

Callers 1

exportGraphicsMethod · 0.95

Calls 3

paintMethod · 0.65
getHeightMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected