Search in sources :

Example 1 with SVGDocument

use of org.w3c.dom.svg.SVGDocument in project yamcs-studio by yamcs.

the class SVGHandler method createWrapper.

private Document createWrapper(final SVGDocument doc) {
    // creation of the SVG document
    String svgNamespace = SVGDOMImplementation.SVG_NAMESPACE_URI;
    DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
    final Document newDocument = impl.createDocument(svgNamespace, "svg", null);
    // get the root element
    svgRootNode = newDocument.getDocumentElement();
    mainGraphicNode = newDocument.createElementNS(svgNamespace, "g");
    // attach the root of original doc to transform to the root
    Node copiedRoot = newDocument.importNode(doc.getDocumentElement(), true);
    mainGraphicNode.appendChild(copiedRoot);
    svgRootNode.appendChild(mainGraphicNode);
    updateMatrix();
    return newDocument;
}
Also used : CanvasGraphicsNode(org.apache.batik.gvt.CanvasGraphicsNode) CompositeGraphicsNode(org.apache.batik.gvt.CompositeGraphicsNode) GraphicsNode(org.apache.batik.gvt.GraphicsNode) Node(org.w3c.dom.Node) CSSStyleSheetNode(org.apache.batik.css.engine.CSSStyleSheetNode) DOMImplementation(org.w3c.dom.DOMImplementation) SVGDOMImplementation(org.apache.batik.anim.dom.SVGDOMImplementation) Document(org.w3c.dom.Document) SVGOMDocument(org.apache.batik.anim.dom.SVGOMDocument) SVGDocument(org.w3c.dom.svg.SVGDocument)

Example 2 with SVGDocument

use of org.w3c.dom.svg.SVGDocument in project charts by vaadin.

the class PdfExportDemo method createSVGDocument.

private SVGDocument createSVGDocument(String svg, UserAgent agent) throws IOException {
    SVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(agent.getXMLParserClassName(), true);
    SVGDocument svgdoc = documentFactory.createSVGDocument(null, new StringReader(svg));
    return svgdoc;
}
Also used : SAXSVGDocumentFactory(org.apache.batik.dom.svg.SAXSVGDocumentFactory) SVGDocumentFactory(org.apache.batik.dom.svg.SVGDocumentFactory) StringReader(java.io.StringReader) SAXSVGDocumentFactory(org.apache.batik.dom.svg.SAXSVGDocumentFactory) SVGDocument(org.w3c.dom.svg.SVGDocument)

Example 3 with SVGDocument

use of org.w3c.dom.svg.SVGDocument in project charts by vaadin.

the class PdfExportDemo method buildBatikGraphicsNode.

/**
 * Use Batik SVG Toolkit to create GraphicsNode for the target SVG.
 * <ol>
 * <li>Create SVGDocument</li>
 * <li>Create BridgeContext</li>
 * <li>Build GVT tree. Results to GraphicsNode</li>
 * </ol>
 *
 * @param svg
 *            SVG as a String
 * @return GraphicsNode
 * @throws IOException
 *             Thrown when SVG could not be read properly.
 */
private GraphicsNode buildBatikGraphicsNode(String svg) throws IOException {
    UserAgent agent = new UserAgentAdapter();
    SVGDocument svgdoc = createSVGDocument(svg, agent);
    DocumentLoader loader = new DocumentLoader(agent);
    BridgeContext bridgeContext = new BridgeContext(agent, loader);
    bridgeContext.setDynamicState(BridgeContext.STATIC);
    GVTBuilder builder = new GVTBuilder();
    GraphicsNode imageGraphics = builder.build(bridgeContext, svgdoc);
    return imageGraphics;
}
Also used : UserAgentAdapter(org.apache.batik.bridge.UserAgentAdapter) UserAgent(org.apache.batik.bridge.UserAgent) BridgeContext(org.apache.batik.bridge.BridgeContext) DocumentLoader(org.apache.batik.bridge.DocumentLoader) SVGDocument(org.w3c.dom.svg.SVGDocument) GVTBuilder(org.apache.batik.bridge.GVTBuilder) GraphicsNode(org.apache.batik.gvt.GraphicsNode)

Example 4 with SVGDocument

use of org.w3c.dom.svg.SVGDocument in project charts by vaadin.

the class SwingDemo method display.

public static void display(Configuration conf) {
    String svg = SVGGenerator.getInstance().generate(conf);
    String parser = XMLResourceDescriptor.getXMLParserClassName();
    SVGDocumentFactory documentFactory = new SAXSVGDocumentFactory(parser, true);
    SVGDocument svgdoc;
    try {
        svgdoc = documentFactory.createSVGDocument(null, new StringReader(svg));
        JSVGCanvas jsvgCanvas = new JSVGCanvas();
        jsvgCanvas.setSVGDocument(svgdoc);
        JFrame f = new JFrame();
        f.setSize(600, 400);
        f.getContentPane().add(jsvgCanvas);
        f.pack();
        f.setVisible(true);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : JFrame(javax.swing.JFrame) SAXSVGDocumentFactory(org.apache.batik.dom.svg.SAXSVGDocumentFactory) SVGDocumentFactory(org.apache.batik.dom.svg.SVGDocumentFactory) StringReader(java.io.StringReader) SAXSVGDocumentFactory(org.apache.batik.dom.svg.SAXSVGDocumentFactory) JSVGCanvas(org.apache.batik.swing.JSVGCanvas) IOException(java.io.IOException) SVGDocument(org.w3c.dom.svg.SVGDocument)

Example 5 with SVGDocument

use of org.w3c.dom.svg.SVGDocument 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;
}
Also used : SVGDOMImplementation(org.apache.batik.dom.svg.SVGDOMImplementation) DOMImplementation(org.w3c.dom.DOMImplementation) SVGDOMImplementation(org.apache.batik.dom.svg.SVGDOMImplementation) SVGGraphics2D(org.apache.batik.svggen.SVGGraphics2D) DataCell(org.knime.core.data.DataCell) SvgCell(org.knime.base.data.xml.SvgCell) Dimension(java.awt.Dimension) Document(org.w3c.dom.Document) SVGDocument(org.w3c.dom.svg.SVGDocument)

Aggregations

SVGDocument (org.w3c.dom.svg.SVGDocument)6 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 SAXSVGDocumentFactory (org.apache.batik.dom.svg.SAXSVGDocumentFactory)2 SVGDocumentFactory (org.apache.batik.dom.svg.SVGDocumentFactory)2 GraphicsNode (org.apache.batik.gvt.GraphicsNode)2 DOMImplementation (org.w3c.dom.DOMImplementation)2 Document (org.w3c.dom.Document)2 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 JFrame (javax.swing.JFrame)1 SAXSVGDocumentFactory (org.apache.batik.anim.dom.SAXSVGDocumentFactory)1 SVGDOMImplementation (org.apache.batik.anim.dom.SVGDOMImplementation)1 SVGOMDocument (org.apache.batik.anim.dom.SVGOMDocument)1 BridgeContext (org.apache.batik.bridge.BridgeContext)1 DocumentLoader (org.apache.batik.bridge.DocumentLoader)1 GVTBuilder (org.apache.batik.bridge.GVTBuilder)1 UserAgent (org.apache.batik.bridge.UserAgent)1 UserAgentAdapter (org.apache.batik.bridge.UserAgentAdapter)1 CSSStyleSheetNode (org.apache.batik.css.engine.CSSStyleSheetNode)1