use of org.apache.batik.bridge.UserAgentAdapter 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;
}
use of org.apache.batik.bridge.UserAgentAdapter in project megameklab by MegaMek.
the class PrintRecordSheet method build.
protected GraphicsNode build() {
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(new UserAgentAdapter() {
@Override
public // rather than throwing an exception.
SVGDocument getBrokenLinkDocument(Element e, String url, String message) {
LogManager.getLogger().warn("Cannot render image: " + message);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
SVGDocument doc = (SVGDocument) impl.createDocument(svgNS, SVGConstants.SVG_SVG_TAG, null);
Element text = doc.createElementNS(svgNS, SVGConstants.SVG_TEXT_TAG);
text.setTextContent("?");
doc.getDocumentElement().appendChild(text);
return doc;
}
});
ctx.setDynamic(true);
return builder.build(ctx, svgDocument);
}
use of org.apache.batik.bridge.UserAgentAdapter in project megameklab by MegaMek.
the class PrintRecordSheet method build.
protected GraphicsNode build() {
GVTBuilder builder = new GVTBuilder();
BridgeContext ctx = new BridgeContext(new UserAgentAdapter() {
@Override
public // rather than throwing an exception.
SVGDocument getBrokenLinkDocument(Element e, String url, String message) {
MegaMekLab.getLogger().log(PrintRecordSheet.class, "build()", LogLevel.WARNING, "Cannot render image: " + message);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
SVGDocument doc = (SVGDocument) impl.createDocument(svgNS, "svg", null);
Element text = doc.createElementNS(svgNS, SVGConstants.SVG_TEXT_TAG);
text.setTextContent("?");
doc.getDocumentElement().appendChild(text);
return doc;
}
});
ctx.setDynamic(true);
return builder.build(ctx, svgDocument);
}
use of org.apache.batik.bridge.UserAgentAdapter in project scout.rt by eclipse.
the class SVGUtility method readSVGDocumentForGraphicalModification.
/**
* Parses a SVG document read by the given input stream and attaches a GVT tree. An attached GVT tree is required for
* performing CSS, text size and and bounding box operations on the SVG document.
* <p/>
* The resulting bridge context holds a reference to the SVG document {@link BridgeContext#getDocument()}
* <p/>
* <h1>Important:</h1> Callers are required to invoke {@link BridgeContext#dispose()} on the returned bridge context
* as soon as the bridge or the document it references is not required anymore.
* <p/>
* If the documents needs not be manipulated, use {@link #readSVGDocument(InputStream)} instead.
*
* @param in
* input stream the SVG document is read from.
* @return Returns a bridge context that holds references to the SVG document as well as to the GVT tree wrapping
* objects.
*/
public static BridgeContext readSVGDocumentForGraphicalModification(InputStream in) {
SVGDocument doc = readSVGDocument(in);
// add a gvt tree for text and alignment calculations
BridgeContext bc = new BridgeContext(new UserAgentAdapter());
bc.setDynamic(true);
GVTBuilder builder = new DynamicGVTBuilder();
builder.build(bc, doc);
return bc;
}
Aggregations