deweese 2002/11/20 04:55:42 Modified: sources/org/apache/batik/extension/svg BatikMultiImageElementBridge.java MultiResGraphicsNode.java Log: 1) Fixed problem using percentages with multi-image element 2) Fixed a potentially huge performace problem with multi-image element. 3) Fixed a 'memory leak' in multi-image element 4) Fixed a problem with pointer events on multi-image elements. Revision Changes Path 1.7 +33 -3 xml-batik/sources/org/apache/batik/extension/svg/BatikMultiImageElementBridge.java Index: BatikMultiImageElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikMultiImageElementBridge.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- BatikMultiImageElementBridge.java 3 Oct 2002 18:57:15 -0000 1.6 +++ BatikMultiImageElementBridge.java 20 Nov 2002 12:55:42 -0000 1.7 @@ -29,6 +29,7 @@ import org.apache.batik.bridge.SVGUtilities; import org.apache.batik.dom.svg.SVGOMDocument; +import org.apache.batik.dom.svg.SVGOMElement; import org.apache.batik.dom.svg.XMLBaseSupport; import org.apache.batik.dom.util.XLinkSupport; @@ -101,7 +102,7 @@ return null; } - ImageNode imgNode = (ImageNode)super.createGraphicsNode(ctx, e); + ImageNode imgNode = (ImageNode)instantiateGraphicsNode(); if (imgNode == null) { return null; } @@ -144,6 +145,10 @@ Rectangle2D b = getImageBounds(ctx, e); + // System.out.println("Bounds: " + bounds); + // System.out.println("ImgB: " + imgBounds); + + GraphicsNode node = new MultiResGraphicsNode(e, b, uary, dary); // 'transform' @@ -153,11 +158,36 @@ (SVGUtilities.convertTransform(e, SVG_TRANSFORM_ATTRIBUTE, s)); } // 'visibility' - node.setVisible(CSSUtilities.convertVisibility(e)); + imgNode.setVisible(CSSUtilities.convertVisibility(e)); imgNode.setImage(node); return imgNode; + } + + /** + * Returns false as shapes are not a container. + */ + public boolean isComposite() { + return false; + } + + /** + * This method is invoked during the build phase if the document + * is dynamic. The responsability of this method is to ensure that + * any dynamic modifications of the element this bridge is + * dedicated to, happen on its associated GVT product. + */ + protected void initializeDynamicSupport(BridgeContext ctx, + Element e, + GraphicsNode node) { + this.e = e; + this.node = node; + this.ctx = ctx; + // HACK due to the way images are represented in GVT + ImageNode imgNode = (ImageNode)node; + ctx.bind(e, imgNode.getImage()); + ((SVGOMElement)e).setSVGContext(this); } protected void addInfo(Element e, Collection dims, Collection uris) { 1.2 +19 -73 xml-batik/sources/org/apache/batik/extension/svg/MultiResGraphicsNode.java Index: MultiResGraphicsNode.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/extension/svg/MultiResGraphicsNode.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MultiResGraphicsNode.java 3 Oct 2002 18:57:15 -0000 1.1 +++ MultiResGraphicsNode.java 20 Nov 2002 12:55:42 -0000 1.2 @@ -71,8 +71,6 @@ Dimension [] sizes; Rectangle2D bounds; - GraphicsNode lastSrc; - UserAgent userAgent; DocumentLoader loader; BridgeContext ctx; @@ -181,17 +179,17 @@ (srcURLs[idx].toString()); GraphicsNode gn; - gn = createSVGImageNode(ctx, multiImgElem, svgDoc); - lastSrc = gn; + gn = createSVGImageNode(ctx, multiImgElem, + bounds, svgDoc); srcs[idx] = new SoftReference(gn); return gn; } catch (Exception ex) { /* ex.printStackTrace(); */ } try { GraphicsNode gn; - gn = createRasterImageNode(ctx, multiImgElem, srcURLs[idx]); + gn = createRasterImageNode(ctx, multiImgElem, + bounds, srcURLs[idx]); srcs[idx] = new SoftReference(gn); - lastSrc = gn; return gn; } catch (Exception ex) { /* ex.printStackTrace(); */ } @@ -208,7 +206,8 @@ * @param uriStr the uri of the image */ protected static GraphicsNode createRasterImageNode(BridgeContext ctx, - Element e, + Element e, + Rectangle2D bounds, ParsedURL purl) { RasterImageNode node = new RasterImageNode(); @@ -219,11 +218,10 @@ (SVGBrokenLinkProvider.SVG_BROKEN_LINK_DOCUMENT_PROPERTY); if ((obj != null) && (obj instanceof SVGDocument)) { // Ok so we are dealing with a broken link. - return createSVGImageNode(ctx, e, (SVGDocument)obj); + return createSVGImageNode(ctx, e, bounds, (SVGDocument)obj); } node.setImage(img); Rectangle2D imgBounds = img.getBounds2D(); - Rectangle2D bounds = getImageBounds(ctx, e); // create the implicit viewBox for the raster image. The viewBox for a // raster image is the size of the image @@ -235,9 +233,9 @@ // System.out.println("Bounds: " + bounds); // System.out.println("ImgB: " + imgBounds); - // handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets the - // appropriate AffineTransform to the image node - initializeViewport(ctx, e, node, vb, bounds); + // handles the 'preserveAspectRatio', 'overflow' and 'clip' and + // sets the appropriate AffineTransform to the image node + initializeViewport(e, node, vb, bounds); return node; } @@ -247,10 +245,12 @@ * * @param ctx the bridge context * @param e the image element + * @param bounds the bounds for this graphicsNode * @param imgDocument the SVG document that represents the image */ protected static GraphicsNode createSVGImageNode(BridgeContext ctx, Element e, + Rectangle2D bounds, SVGDocument imgDocument) { CompositeGraphicsNode result = new CompositeGraphicsNode(); @@ -275,12 +275,12 @@ svgElement.getAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE); float [] vb = ViewBox.parseViewBoxAttribute(e, viewBox); - // handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets the - // appropriate AffineTransform to the image node - Rectangle2D bounds = getImageBounds(ctx, e); + // handles the 'preserveAspectRatio', 'overflow' and 'clip' and sets + // the appropriate AffineTransform to the image node + // System.out.println("Bounds: " + bounds); // System.out.println("ViewBox: " + viewBox); - initializeViewport(ctx, e, result, vb, bounds); + initializeViewport(e, result, vb, bounds); return result; } @@ -291,14 +291,12 @@ * 'viewBox', 'preserveAspectRatio', and 'clip' properties. According to * those properties, a AffineTransform and a clip is set. * - * @param ctx the bridge context * @param e the image element that defines the properties * @param node the graphics node * @param vb the implicit viewBox definition * @param bounds the bounds of the image element */ - protected static void initializeViewport(BridgeContext ctx, - Element e, + protected static void initializeViewport(Element e, GraphicsNode node, float [] vb, Rectangle2D bounds) { @@ -310,6 +308,7 @@ AffineTransform at = ViewBox.getPreserveAspectRatioTransform(e, vb, w, h); + // System.out.println("VP Affine: " + at); at.preConcatenate(AffineTransform.getTranslateInstance(x, y)); node.setTransform(at); @@ -339,59 +338,6 @@ node.setClip(new ClipRable8Bit(filter, clip)); } catch (java.awt.geom.NoninvertibleTransformException ex) {} } - } - - - /** - * Returns the bounds of the specified image element. - * - * @param ctx the bridge context - * @param element the image element - */ - protected static - Rectangle2D getImageBounds(BridgeContext ctx, Element element) { - - UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, element); - - // 'x' attribute - default is 0 - String s = element.getAttributeNS(null, SVG_X_ATTRIBUTE); - float x = 0; - if (s.length() != 0) { - x = UnitProcessor.svgHorizontalCoordinateToUserSpace - (s, SVG_X_ATTRIBUTE, uctx); - } - - // 'y' attribute - default is 0 - s = element.getAttributeNS(null, SVG_Y_ATTRIBUTE); - float y = 0; - if (s.length() != 0) { - y = UnitProcessor.svgVerticalCoordinateToUserSpace - (s, SVG_Y_ATTRIBUTE, uctx); - } - - // 'width' attribute - required - s = element.getAttributeNS(null, SVG_WIDTH_ATTRIBUTE); - float w; - if (s.length() == 0) { - throw new BridgeException(element, ERR_ATTRIBUTE_MISSING, - new Object[] {SVG_WIDTH_ATTRIBUTE}); - } else { - w = UnitProcessor.svgHorizontalLengthToUserSpace - (s, SVG_WIDTH_ATTRIBUTE, uctx); - } - - // 'height' attribute - required - s = element.getAttributeNS(null, SVG_HEIGHT_ATTRIBUTE); - float h; - if (s.length() == 0) { - throw new BridgeException(element, ERR_ATTRIBUTE_MISSING, - new Object[] {SVG_HEIGHT_ATTRIBUTE}); - } else { - h = UnitProcessor.svgVerticalLengthToUserSpace - (s, SVG_HEIGHT_ATTRIBUTE, uctx); - } - - return new Rectangle2D.Float(x, y, w, h); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]