/** * Retrieves a Batik {@link GraphicsNode} for a given SVG. * * @param svgLocation an URL that specifies the SVG. * @return the corresponding GraphicsNode. * @throws IOException * @throws URISyntaxException */ GraphicsNode getGraphicNode(Document doc) { // instantiates objects needed for building the node UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamic(true); // creates node builder and builds node GVTBuilder builder = new GVTBuilder(); return builder.build(ctx, doc); }
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory( XMLResourceDescriptor.getXMLParserClassName()); File file = new File("C:/resources/chessboard.svg"); InputStream is = new FileInputStream(file); Document document = factory.createDocument( file.toURI().toURL().toString(), is); UserAgent agent = new UserAgentAdapter(); DocumentLoader loader= new DocumentLoader(agent); BridgeContext context = new BridgeContext(agent, loader); context.setDynamic(true); GVTBuilder builder= new GVTBuilder(); GraphicsNode root= builder.build(context, document); System.out.println(root.getPrimitiveBounds().getWidth()); System.out.println(root.getPrimitiveBounds().getHeight());
this.bridgeContext.setDynamic(true);
@Override public Dimension getDimension(Document document) { UserAgent agent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(agent); BridgeContext context = new BridgeContext(agent, loader); context.setDynamic(true); GVTBuilder builder = new GVTBuilder(); Rectangle2D primitiveBounds = builder.build(context, document).getPrimitiveBounds(); return new Dimension((float)primitiveBounds.getWidth(), (float)primitiveBounds.getHeight()); } }
/** * Retrieves a Batik {@link GraphicsNode} for a given SVG. * * @param svgLocation * an URL that specifies the SVG. * @return the corresponding GraphicsNode. * @throws IOException * @throws URISyntaxException */ private GraphicsNode getGraphicNode(Document doc) { // instantiates objects needed for building the node UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamic(true); // creates node builder and builds node GVTBuilder builder = new GVTBuilder(); return builder.build(ctx, doc); }
/** * 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; }
GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(userAgent); ctx.setDynamic(true);
ctx.setDynamic(true); GVTBuilder builder = new GVTBuilder(); rootNode = builder.build(ctx, document);
GVTBuilder builder = new GVTBuilder(); BridgeContext ctx = new BridgeContext(userAgent); ctx.setDynamic(true); Exception e = null; try {