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);
}
}
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 "";
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations