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); }
/** * Creates the BridgeContext. Subclass this method to provide customized bridges. For example, * Apache FOP uses this method to register special bridges for optimized text painting. * @param svgVersion the SVG version in use (ex. "1.0", "1.x" or "1.2") * @return the newly instantiated BridgeContext */ protected BridgeContext createBridgeContext(String svgVersion) { if ("1.2".equals(svgVersion)) { return new SVG12BridgeContext(userAgent); } else { return new BridgeContext(userAgent); } }
/** * Creates the BridgeContext. Subclass this method to provide customized bridges. For example, * Apache FOP uses this method to register special bridges for optimized text painting. * @param svgVersion the SVG version in use (ex. "1.0", "1.x" or "1.2") * @return the newly instantiated BridgeContext */ protected BridgeContext createBridgeContext(String svgVersion) { if ("1.2".equals(svgVersion)) { return new SVG12BridgeContext(userAgent); } else { return new BridgeContext(userAgent); } }
/** * 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()); } }
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; }
final BridgeContext ctx = new BridgeContext( userAgent, loader ); final GVTBuilder builder = new GVTBuilder(); final GraphicsNode node = builder.build( ctx, document );
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; }
/** * This function creates a new BridgeContext, it mostly * exists so subclasses can provide an instance of * themselves when a sub BridgeContext is needed. */ public BridgeContext createBridgeContext(SVGOMDocument doc) { if (doc.isSVG12()) { return new SVG12BridgeContext(getUserAgent(), getDocumentLoader()); } return new BridgeContext(getUserAgent(), getDocumentLoader()); }
/** * This function creates a new BridgeContext, it mostly * exists so subclasses can provide an instance of * themselves when a sub BridgeContext is needed. */ public BridgeContext createBridgeContext(SVGOMDocument doc) { if (doc.isSVG12()) { return new SVG12BridgeContext(getUserAgent(), getDocumentLoader()); } return new BridgeContext(getUserAgent(), getDocumentLoader()); }
/** * 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); }
/** * This function creates a new BridgeContext, it mostly * exists so subclasses can provide an instance of * themselves when a sub BridgeContext is needed. */ public BridgeContext createBridgeContext(SVGOMDocument doc) { if (doc.isSVG12()) { return new SVG12BridgeContext(getUserAgent(), getDocumentLoader()); } return new BridgeContext(getUserAgent(), getDocumentLoader()); }
/** * 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 ); } }
/** * 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; }
new BridgeContext(userAgent), svgElement);