Search in sources :

Example 1 with SVGGraphics2D

use of org.apache.batik.svggen.SVGGraphics2D in project neo4j by neo4j.

the class CoverageChartWriter method dumpSVG.

public void dumpSVG(Map<String, Integer> data) {
    SVGGraphics2D svgGenerator = new SVGGraphics2D(getDocument());
    createBarChart(data).draw(svgGenerator, new Rectangle(1500, 500));
    try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(outDirectory, filename + ".svg")))) {
        svgGenerator.stream(writer, true);
    } catch (IOException e) {
        throw new RuntimeException("Unexpected error during SVG file creation", e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Example 2 with SVGGraphics2D

use of org.apache.batik.svggen.SVGGraphics2D in project webanno by webanno.

the class SvgChart method renderSvg.

private String renderSvg() {
    // Get a DOMImplementation and create an XML document
    DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
    Document document = domImpl.createDocument(null, "svg", null);
    // Create an instance of the SVG Generator
    SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
    // draw the chart in the SVG generator
    getModelObject().draw(svgGenerator, new Rectangle(options.getViewBoxWidth(), options.getViewBoxHeight()));
    Element svgRoot = svgGenerator.getRoot();
    svgRoot.setAttributeNS(XMLNS_NAMESPACE_URI, XMLNS_PREFIX, SVG_NAMESPACE_URI);
    svgRoot.setAttributeNS(XMLNS_NAMESPACE_URI, XMLNS_PREFIX + ":" + XLINK_PREFIX, XLINK_NAMESPACE_URI);
    SVGCSSStyler.style(svgRoot);
    // String style = svgRoot.getAttributeNS(null, SVG_STYLE_ATTRIBUTE);
    // style = "height: " + SVG_HEIGHT + "px; width: " + SVG_WIDTH + "px; " + style;
    // svgRoot.setAttributeNS(null, SVG_STYLE_ATTRIBUTE, style);
    String style = svgRoot.getAttributeNS(null, SVG_STYLE_ATTRIBUTE);
    style = "height: auto; width: 100%; " + style;
    svgRoot.setAttributeNS(null, SVG_STYLE_ATTRIBUTE, style);
    svgRoot.setAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + options.getViewBoxWidth() + " " + options.getViewBoxHeight());
    try {
        @SuppressWarnings("resource") StringWriter writer = new StringWriter();
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        trans.setOutputProperty(OutputKeys.VERSION, "1.0");
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        trans.transform(new DOMSource(svgRoot), new StreamResult(writer));
        writer.close();
        return writer.toString();
    } catch (Exception e) {
        LOG.error("Unable to render SVG", e);
        return "";
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringWriter(java.io.StringWriter) StreamResult(javax.xml.transform.stream.StreamResult) Element(org.w3c.dom.Element) Rectangle(java.awt.Rectangle) DOMImplementation(org.w3c.dom.DOMImplementation) GenericDOMImplementation(org.apache.batik.dom.GenericDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document)

Example 3 with SVGGraphics2D

use of org.apache.batik.svggen.SVGGraphics2D in project freeplane by freeplane.

the class ExportSvg method export.

public void export(MapModel map, File chosenFile) {
    if (!ExportController.getContoller().checkCurrentMap(map)) {
        return;
    }
    try {
        final MapView view = (MapView) Controller.getCurrentController().getMapViewManager().getMapViewComponent();
        if (view == null) {
            return;
        }
        Controller.getCurrentController().getViewController().setWaitingCursor(true);
        final SVGGraphics2D g2d = fillSVGGraphics2D(view);
        final FileOutputStream bos = new FileOutputStream(chosenFile);
        final BufferedOutputStream bufStream = new BufferedOutputStream(bos);
        final OutputStreamWriter osw = new OutputStreamWriter(bufStream, "UTF-8");
        g2d.stream(osw);
        osw.flush();
        bos.flush();
        bos.close();
    } catch (final Exception ex) {
        org.freeplane.core.util.LogUtils.warn(ex);
        UITools.errorMessage(ex.getLocalizedMessage());
    } finally {
        Controller.getCurrentController().getViewController().setWaitingCursor(false);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) MapView(org.freeplane.view.swing.map.MapView) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) OutputStreamWriter(java.io.OutputStreamWriter) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with SVGGraphics2D

use of org.apache.batik.svggen.SVGGraphics2D in project dbeaver by serge-rider.

the class ERDExportSVG method exportDiagram.

@Override
public void exportDiagram(EntityDiagram diagram, IFigure diagramFigure, DiagramPart diagramPart, File targetFile) throws DBException {
    checkWriterRegister();
    try {
        IFigure figure = diagramPart.getFigure();
        Rectangle contentBounds = figure instanceof FreeformLayeredPane ? ((FreeformLayeredPane) figure).getFreeformExtent() : figure.getBounds();
        String svgNS = "http://www.w3.org/2000/svg";
        // domImpl.createDocument(svgNS, "svg", null);
        Document document = XMLUtils.createDocument();
        document.createAttributeNS(svgNS, "svg");
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
        // We need a converter from Draw2D.Graphics (GEF) to awt.Graphics2D (Batik)
        Graphics graphics = new GraphicsToGraphics2DAdaptor(svgGenerator);
        // Reset origin to make it the top/left most part of the diagram
        graphics.translate(contentBounds.x * -1, contentBounds.y * -1);
        paintDiagram(graphics, figure);
        LayerManager layerManager = (LayerManager) diagramPart.getViewer().getEditPartRegistry().get(LayerManager.ID);
        IFigure connectionLayer = layerManager.getLayer("Connection Layer");
        if (connectionLayer != null) {
            paintDiagram(graphics, connectionLayer);
        }
        String filePath = targetFile.getAbsolutePath();
        svgGenerator.stream(filePath);
        UIUtils.launchProgram(filePath);
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError("Save ERD as SVG", null, e);
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) LayerManager(org.eclipse.gef.editparts.LayerManager) DBException(org.jkiss.dbeaver.DBException)

Example 5 with SVGGraphics2D

use of org.apache.batik.svggen.SVGGraphics2D in project dbeaver by dbeaver.

the class ERDExportSVG method exportDiagram.

@Override
public void exportDiagram(EntityDiagram diagram, IFigure diagramFigure, DiagramPart diagramPart, File targetFile) throws DBException {
    checkWriterRegister();
    try {
        IFigure figure = diagramPart.getFigure();
        Rectangle contentBounds = figure instanceof FreeformLayeredPane ? ((FreeformLayeredPane) figure).getFreeformExtent() : figure.getBounds();
        String svgNS = "http://www.w3.org/2000/svg";
        // domImpl.createDocument(svgNS, "svg", null);
        Document document = XMLUtils.createDocument();
        document.createAttributeNS(svgNS, "svg");
        SVGGraphics2D svgGenerator = new SVGGraphics2D(document);
        // We need a converter from Draw2D.Graphics (GEF) to awt.Graphics2D (Batik)
        Graphics graphics = new GraphicsToGraphics2DAdaptor(svgGenerator);
        // Reset origin to make it the top/left most part of the diagram
        graphics.translate(contentBounds.x * -1, contentBounds.y * -1);
        paintDiagram(graphics, figure);
        LayerManager layerManager = (LayerManager) diagramPart.getViewer().getEditPartRegistry().get(LayerManager.ID);
        IFigure connectionLayer = layerManager.getLayer("Connection Layer");
        if (connectionLayer != null) {
            paintDiagram(graphics, connectionLayer);
        }
        String filePath = targetFile.getAbsolutePath();
        svgGenerator.stream(filePath);
        UIUtils.launchProgram(filePath);
    } catch (Exception e) {
        DBWorkbench.getPlatformUI().showError("Save ERD as SVG", null, e);
    }
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) Document(org.w3c.dom.Document) LayerManager(org.eclipse.gef.editparts.LayerManager) DBException(org.jkiss.dbeaver.DBException)

Aggregations

SVGGraphics2D (org.apache.batik.svggen.SVGGraphics2D)19 Document (org.w3c.dom.Document)14 DOMImplementation (org.w3c.dom.DOMImplementation)10 GenericDOMImplementation (org.apache.batik.dom.GenericDOMImplementation)8 OutputStreamWriter (java.io.OutputStreamWriter)6 Dimension (java.awt.Dimension)5 FileOutputStream (java.io.FileOutputStream)5 File (java.io.File)4 IOException (java.io.IOException)4 Writer (java.io.Writer)4 SVGGeneratorContext (org.apache.batik.svggen.SVGGeneratorContext)4 Rectangle (java.awt.Rectangle)3 Element (org.w3c.dom.Element)3 Font (java.awt.Font)2 Rectangle2D (java.awt.geom.Rectangle2D)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2