Search in sources :

Example 1 with DocumentLoader

use of org.apache.batik.bridge.DocumentLoader 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)

Aggregations

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 GraphicsNode (org.apache.batik.gvt.GraphicsNode)1 SVGDocument (org.w3c.dom.svg.SVGDocument)1