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 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 processing by processing.
the class PGraphicsSVG method beginDraw.
public void beginDraw() {
DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String ns = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(ns, "svg", null);
// Create an instance of the SVG Generator.
g2 = new SVGGraphics2D(document);
((SVGGraphics2D) g2).setSVGCanvasSize(new Dimension(width, height));
// Done with our work, let's check on defaults and the rest
//super.beginDraw();
// Can't call super.beginDraw() because it'll nuke our g2
checkSettings();
// reset model matrix
resetMatrix();
vertexCount = 0;
// Also need to push the matrix since the matrix doesn't reset on each run
// http://dev.processing.org/bugs/show_bug.cgi?id=1227
pushMatrix();
}
use of org.apache.batik.svggen.SVGGraphics2D in project megameklab by MegaMek.
the class PrintRecordSheet method print.
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
final String METHOD_NAME = "print(Graphics,PageFormat,int)";
Graphics2D g2d = (Graphics2D) graphics;
if (null != g2d) {
File f = new File("data/images/recordsheets/" + getSVGFileName());
svgDocument = null;
try {
InputStream is = new FileInputStream(f);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
final String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXDocumentFactory df = new SAXDocumentFactory(impl, parser);
svgDocument = df.createDocument(f.toURI().toASCIIString(), is);
} catch (Exception e) {
MegaMekLab.getLogger().log(PrintRecordSheet.class, METHOD_NAME, e);
}
if (null == svgDocument) {
MegaMekLab.getLogger().log(PrintRecordSheet.class, METHOD_NAME, LogLevel.ERROR, "Failed to open Mech SVG file! Path: data/images/recordsheets/" + getSVGFileName());
} else {
svgGenerator = new SVGGraphics2D(svgDocument);
printImage(g2d, pageFormat, pageIndex - firstPage);
GraphicsNode node = build();
node.paint(g2d);
}
}
return Printable.PAGE_EXISTS;
}
use of org.apache.batik.svggen.SVGGraphics2D in project knime-core by knime.
the class HistogramColumn method createSvgImageCell.
/**
* @param histogramData A {@link HistogramModel}.
* @return The SVG image cell.
*/
private DataCell createSvgImageCell(final HistogramModel<?> histogramData, final boolean paintLabels) {
DOMImplementation domImpl = new SVGDOMImplementation();
String svgNS = "http://www.w3.org/2000/svg";
Document myFactory = domImpl.createDocument(svgNS, "svg", null);
SVGGraphics2D g = new SVGGraphics2D(myFactory);
g.setSVGCanvasSize(new Dimension(m_width, m_height));
paint(histogramData, paintLabels, g);
myFactory.replaceChild(g.getRoot(), myFactory.getDocumentElement());
DataCell dc = new SvgCell((SVGDocument) myFactory);
return dc;
}
Aggregations