public SwtUniversalImageSvg( SvgImage svg ) { // get GraphicsNode and size from svg document UserAgentAdapter userAgentAdapter = new UserAgentAdapter(); DocumentLoader documentLoader = new DocumentLoader( userAgentAdapter ); BridgeContext ctx = new BridgeContext( userAgentAdapter, documentLoader ); GVTBuilder builder = new GVTBuilder(); svgGraphicsNode = builder.build( ctx, svg.getDocument() ); svgGraphicsSize = ctx.getDocumentSize(); }
public SwingUniversalImageSvg( SvgImage svg ) { // get GraphicsNode and size from svg document UserAgentAdapter userAgentAdapter = new UserAgentAdapter(); DocumentLoader documentLoader = new DocumentLoader( userAgentAdapter ); BridgeContext ctx = new BridgeContext( userAgentAdapter, documentLoader ); GVTBuilder builder = new GVTBuilder(); svgGraphicsNode = builder.build( ctx, svg.getDocument() ); svgGraphicsSize = ctx.getDocumentSize(); }
/** * 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); }
/** * Constructs a new bridge context. * @param userAgent the user agent */ public BridgeContext(UserAgent userAgent) { this(userAgent, sharedPool, new DocumentLoader(userAgent)); }
/** * Constructs a new bridge context. * @param userAgent the user agent */ public BridgeContext(UserAgent userAgent) { this(userAgent, sharedPool, new DocumentLoader(userAgent)); }
/** * Constructs a new bridge context. * @param userAgent the user agent */ public BridgeContext(UserAgent userAgent) { this(userAgent, sharedPool, new DocumentLoader(userAgent)); }
public void run() { String url = newURI.toString(); fragmentIdentifier = newURI.getRef(); loader = new DocumentLoader(userAgent); nextDocumentLoader = new SVGDocumentLoader(url, loader); nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); Iterator it = svgDocumentLoaderListeners.iterator(); while (it.hasNext()) { nextDocumentLoader.addSVGDocumentLoaderListener ((SVGDocumentLoaderListener)it.next()); } startDocumentLoader(); } });
/** * Creates a new bridge context. */ protected BridgeContext createBridgeContext(SVGOMDocument doc) { if (loader == null) { loader = new DocumentLoader(userAgent); } BridgeContext result; if (doc.isSVG12()) { result = new SVG12BridgeContext(userAgent, loader); } else { result = new BridgeContext(userAgent, loader); } return result; }
/** * Creates a new bridge context. */ protected BridgeContext createBridgeContext(SVGOMDocument doc) { if (loader == null) { loader = new DocumentLoader(userAgent); } BridgeContext result; if (doc.isSVG12()) { result = new SVG12BridgeContext(userAgent, loader); } else { result = new BridgeContext(userAgent, loader); } return result; }
/** * Creates a new bridge context. */ protected BridgeContext createBridgeContext(SVGOMDocument doc) { if (loader == null) { loader = new DocumentLoader(userAgent); } BridgeContext result; if (doc.isSVG12()) { result = new SVG12BridgeContext(userAgent, loader); } else { result = new BridgeContext(userAgent, loader); } return result; }
@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()); } }
/** * Loads a SVG document from the given URL. * <em>Note: Because the loading is multi-threaded, the current * SVG document is not guaranteed to be updated after this method * returns. The only way to be notified a document has been loaded * is to listen to the <code>SVGDocumentLoaderEvent</code>s.</em> */ public void loadSVGDocument(String url) { String oldURI = null; if (svgDocument != null) { oldURI = svgDocument.getURL(); } final ParsedURL newURI = new ParsedURL(oldURI, url); stopThenRun(new Runnable() { public void run() { String url = newURI.toString(); fragmentIdentifier = newURI.getRef(); loader = new DocumentLoader(userAgent); nextDocumentLoader = new SVGDocumentLoader(url, loader); nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); for (Object svgDocumentLoaderListener : svgDocumentLoaderListeners) { nextDocumentLoader.addSVGDocumentLoaderListener ((SVGDocumentLoaderListener) svgDocumentLoaderListener); } startDocumentLoader(); } }); }
/** * Loads a SVG document from the given URL. * <em>Note: Because the loading is multi-threaded, the current * SVG document is not guaranteed to be updated after this method * returns. The only way to be notified a document has been loaded * is to listen to the <code>SVGDocumentLoaderEvent</code>s.</em> */ public void loadSVGDocument(String url) { String oldURI = null; if (svgDocument != null) { oldURI = svgDocument.getURL(); } final ParsedURL newURI = new ParsedURL(oldURI, url); stopThenRun(new Runnable() { public void run() { String url = newURI.toString(); fragmentIdentifier = newURI.getRef(); loader = new DocumentLoader(userAgent); nextDocumentLoader = new SVGDocumentLoader(url, loader); nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); Iterator it = svgDocumentLoaderListeners.iterator(); while (it.hasNext()) { nextDocumentLoader.addSVGDocumentLoaderListener ((SVGDocumentLoaderListener)it.next()); } startDocumentLoader(); } }); }
private GraphicsNode getGraphicsNode(SVGDocument svgDocument, int dpi) throws IOException { UserAgent userAgent = new DensityAwareUserAgent(dpi); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamicState(BridgeContext.DYNAMIC); GVTBuilder builder = new GVTBuilder(); GraphicsNode rootGN = builder.build(ctx, svgDocument); return rootGN; }
private GraphicsNode getGraphicsNode(SVGDocument svgDocument, int dpi) throws IOException { UserAgent userAgent = new DensityAwareUserAgent(dpi); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext ctx = new BridgeContext(userAgent, loader); ctx.setDynamicState(BridgeContext.DYNAMIC); GVTBuilder builder = new GVTBuilder(); GraphicsNode rootGN = builder.build(ctx, svgDocument); return rootGN; }
public void run() { String url = newURI.toString(); fragmentIdentifier = newURI.getRef(); loader = new DocumentLoader(userAgent); nextDocumentLoader = new SVGDocumentLoader(url, loader); nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); for (Object svgDocumentLoaderListener : svgDocumentLoaderListeners) { nextDocumentLoader.addSVGDocumentLoaderListener ((SVGDocumentLoaderListener) svgDocumentLoaderListener); } startDocumentLoader(); } });
public void run() { String url = newURI.toString(); fragmentIdentifier = newURI.getRef(); loader = new DocumentLoader(userAgent); nextDocumentLoader = new SVGDocumentLoader(url, loader); nextDocumentLoader.setPriority(Thread.MIN_PRIORITY); for (Object svgDocumentLoaderListener : svgDocumentLoaderListeners) { nextDocumentLoader.addSVGDocumentLoaderListener ((SVGDocumentLoaderListener) svgDocumentLoaderListener); } startDocumentLoader(); } });
/** * Enhance the SVG DOM for the given document to provide CSS- and * SVG-specific DOM interfaces. * * @param document * The document to enhance. * @link http://wiki.apache.org/xmlgraphics-batik/BootSvgAndCssDom */ private void initSVGDOM(Document document) { UserAgent userAgent = new UserAgentAdapter(); DocumentLoader loader = new DocumentLoader(userAgent); BridgeContext bridgeContext = new BridgeContext(userAgent, loader); bridgeContext.setDynamicState(BridgeContext.DYNAMIC); // Enable CSS- and SVG-specific enhancements. (new GVTBuilder()).build(bridgeContext, document); }
/** * 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); }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { try { final long version = data.getVersion( caller ); final HeadlessSVGUserAgent userAgent = new HeadlessSVGUserAgent(); final DocumentLoader loader = new DocumentLoader( userAgent ); final ResourceKey key = data.getKey(); URL url = caller.toURL( key ); if ( url == null ) { url = new File( "." ).toURI().toURL(); } final SVGDocument document = (SVGDocument) loader.loadDocument ( url.toURI().toASCIIString(), data.getResourceAsStream( caller ) ); final BridgeContext ctx = new BridgeContext( userAgent, loader ); final GVTBuilder builder = new GVTBuilder(); final GraphicsNode node = builder.build( ctx, document ); return new SimpleResource( data.getKey(), new SVGDrawable( node ), DrawableWrapper.class, version ); } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to process SVG file", e ); } catch ( URISyntaxException e ) { throw new ResourceLoadingException( "Failed to process SVG file", e ); } }