Search in sources :

Example 1 with BridgeContext

use of org.apache.batik.bridge.BridgeContext in project yamcs-studio by yamcs.

the class SimpleImageTranscoder method initCSSEngine.

/**
 * Call before querying for CSS properties. If document has CSS engine installed returns null. Client is responsible
 * to dispose bridge context if it was returned by this method.
 */
public BridgeContext initCSSEngine() {
    if (this.document == null) {
        return null;
    }
    SVGOMDocument sd = (SVGOMDocument) this.document;
    if (sd.getCSSEngine() != null) {
        return null;
    }
    class BridgeContextEx extends BridgeContext {

        public BridgeContextEx() {
            super(SimpleImageTranscoder.this.userAgent);
            BridgeContextEx.this.setDocument(SimpleImageTranscoder.this.document);
            BridgeContextEx.this.initializeDocument(SimpleImageTranscoder.this.document);
        }
    }
    return new BridgeContextEx();
}
Also used : SVGOMDocument(org.apache.batik.anim.dom.SVGOMDocument) BridgeContext(org.apache.batik.bridge.BridgeContext)

Example 2 with BridgeContext

use of org.apache.batik.bridge.BridgeContext 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)2 SVGOMDocument (org.apache.batik.anim.dom.SVGOMDocument)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