/** Builds an <code>SVGGraphics2D</code> with a default configuration. */ protected SVGGraphics2D buildSVGGraphics2D() { // CSSDocumentHandler.setParserClassName(CSS_PARSER_CLASS_NAME); DOMImplementation impl = GenericDOMImplementation.getDOMImplementation(); String namespaceURI = SVGConstants.SVG_NAMESPACE_URI; Document domFactory = impl.createDocument(namespaceURI, SVG_SVG_TAG, null); SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(domFactory); GraphicContextDefaults defaults = new GraphicContextDefaults(); defaults.font = new Font("Arial", Font.PLAIN, 12); ctx.setGraphicContextDefaults(defaults); ctx.setPrecision(12); return new SVGGraphics2D(ctx, false); }
/** * Creates an Element which can refer to an image. Note that no assumptions should be made by the * caller about the corresponding SVG tag. By default, an <image> tag is used, but the * {@link CachedImageHandlerBase64Encoder}, for example, overrides this method to use a different * tag. */ public Element createElement(SVGGeneratorContext generatorContext) { // Create a DOM Element in SVG namespace to refer to an image Element imageElement = generatorContext.getDOMFactory().createElementNS(SVG_NAMESPACE_URI, SVG_IMAGE_TAG); return imageElement; }
/** * Determines the transformation needed to get the cached image to scale & position properly. Sets * x and y attributes on the element accordingly. */ protected AffineTransform handleTransform( Element imageElement, double x, double y, double srcWidth, double srcHeight, double dstWidth, double dstHeight, SVGGeneratorContext generatorContext) { // In this the default case, <image> element, we just // set x, y, width and height attributes. // No additional transform is necessary. imageElement.setAttributeNS(null, SVG_X_ATTRIBUTE, generatorContext.doubleString(x)); imageElement.setAttributeNS(null, SVG_Y_ATTRIBUTE, generatorContext.doubleString(y)); imageElement.setAttributeNS(null, SVG_WIDTH_ATTRIBUTE, generatorContext.doubleString(dstWidth)); imageElement.setAttributeNS( null, SVG_HEIGHT_ATTRIBUTE, generatorContext.doubleString(dstHeight)); return null; }