tkormann 02/05/25 11:08:41 Modified: test-resources/org/apache/batik/test samplesRendering.xml sources/org/apache/batik/bridge SVGImageElementBridge.java Added: samples/tests/spec/scripting image.svg imageraster.svg imagesvg.svg samples/tests/resources/images svg.png test-references/samples/tests/spec/scripting image.png imageraster.png imagesvg.png Log: include nicolas'fix for x,y,w,h and pAR+ViewBox on <image> Revision Changes Path 1.1 xml-batik/samples/tests/spec/scripting/image.svg Index: image.svg =================================================================== <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <!-- ========================================================================= --> <!-- Copyright (C) The Apache Software Foundation. All rights reserved. --> <!-- --> <!-- This software is published under the terms of the Apache Software License --> <!-- version 1.1, a copy of which has been included with this distribution in --> <!-- the LICENSE file. --> <!-- ========================================================================= --> <!-- ========================================================================= --> <!-- dynamic update for image --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: image.svg,v 1.1 2002/05/25 18:08:41 tkormann Exp $ --> <!-- ========================================================================= --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="body" width="450" height="500" viewBox="0 0 450 500"> <title>update on <image></title> <style type="text/css"><![CDATA[ ]]></style> <script type="text/ecmascript" > function setPAR(evt,par){ var e = evt.target; e.setAttribute('preserveAspectRatio',par); } function setPosition(evt,x,y,width,height){ var e = evt.target; e.setAttribute("x",x); e.setAttribute("y",y); e.setAttribute("width",width); e.setAttribute("height",height); } </script> <g id="content"> <text class="title" x="50%" y="40"><image> dynamic tests</text> <defs> <rect id="Rect1" x="40" y="-20" width="100" height="40" /> <rect id="Rect2" x="60" y="-60" width="40" height="100" /> </defs> <g transform="translate(70,150)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="0" y="0" width="1" height="1" xlink:href="../../resources/images/svg.svg" onload="setPosition(evt,40,-20,100,40)"/> <text font-size="10" x="35" y="60">SVG image <tspan x="40" dy="12"> x,y,width,height update</tspan></text> </g> <g transform="translate(230,150)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-60" width="40" height="100" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'none')"/> <text font-size="10" x="35" y="60">SVG Image : aspectRatio none</text> </g> <g transform="translate(70,300)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPosition(evt,60,-60,40,100)"/> <text font-size="10" x="35" y="60">PNG Image <tspan x="40" dy="12"> x,y,width,height update</tspan></text> </g> <g transform="translate(230,300)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="-20" width="100" height="40" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'none')"/> <text font-size="10" x="35" y="60">PNG Image : aspectRatio none</text> </g> </g> <!-- ============================================================= --> <!-- Batik sample mark --> <!-- ============================================================= --> <use xlink:href="../../../batikLogo.svg#Batik_Tag_Box" /> </svg> 1.1 xml-batik/samples/tests/spec/scripting/imageraster.svg Index: imageraster.svg =================================================================== <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <!-- ========================================================================= --> <!-- Copyright (C) The Apache Software Foundation. All rights reserved. --> <!-- --> <!-- This software is published under the terms of the Apache Software License --> <!-- version 1.1, a copy of which has been included with this distribution in --> <!-- the LICENSE file. --> <!-- ========================================================================= --> <!-- ========================================================================= --> <!-- dynamic update for image --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: imageraster.svg,v 1.1 2002/05/25 18:08:41 tkormann Exp $ --> <!-- ========================================================================= --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="body" width="450" height="500" viewBox="0 0 450 500"> <title>update on <image></title> <style type="text/css"><![CDATA[ ]]></style> <script type="text/ecmascript" > function setPAR(evt,par){ var e = evt.target; e.setAttribute('preserveAspectRatio',par); } </script> <g id="content"> <text class="title" x="50%" y="40"><image> tests <tspan font-size="12">(preserveAspectRatio)</tspan></text> <defs> <rect id="Rect1" x="40" y="0" width="50" height="20" /> <rect id="Rect2" x="60" y="-10" width="20" height="50" /> </defs> <g transform="translate(0,70)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMin meet')"/> <text font-size="10" x="35" y="60">xMin* meet</text> </g> <g transform="translate(150,70)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMidYMin meet')"/> <text font-size="10" x="35" y="60">xMid* meet</text> </g> <g transform="translate(300,70)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMaxYMin meet')"/> <text font-size="10" x="35" y="60">xMax* meet</text> </g> <g transform="translate(0,170)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMin meet')"/> <text font-size="10" x="35" y="60">*YMin meet</text> </g> <g transform="translate(150,170)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMid meet')"/> <text font-size="10" x="35" y="60">*YMid meet</text> </g> <g transform="translate(300,170)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMax meet')"/> <text font-size="10" x="35" y="60">*YMax meet</text> </g> <g transform="translate(0,270)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMin slice')"/> <text font-size="10" x="35" y="60">xMin* slice</text> </g> <g transform="translate(150,270)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMidYMin slice')"/> <text font-size="10" x="35" y="60">xMid* slice</text> </g> <g transform="translate(300,270)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMaxYMin slice')"/> <text font-size="10" x="35" y="60">xMax* slice</text> </g> <g transform="translate(0,370)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMin slice')"/> <text font-size="10" x="35" y="60">*YMin slice</text> </g> <g transform="translate(150,370)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMid slice')"/> <text font-size="10" x="35" y="60">*YMid slice</text> </g> <g transform="translate(300,370)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.png" onload="setPAR(evt,'xMinYMax slice')"/> <text font-size="10" x="35" y="60">*YMax slice</text> </g> </g> <!-- ============================================================= --> <!-- Batik sample mark --> <!-- ============================================================= --> <use xlink:href="../../../batikLogo.svg#Batik_Tag_Box" /> </svg> 1.1 xml-batik/samples/tests/spec/scripting/imagesvg.svg Index: imagesvg.svg =================================================================== <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <!-- ========================================================================= --> <!-- Copyright (C) The Apache Software Foundation. All rights reserved. --> <!-- --> <!-- This software is published under the terms of the Apache Software License --> <!-- version 1.1, a copy of which has been included with this distribution in --> <!-- the LICENSE file. --> <!-- ========================================================================= --> <!-- ========================================================================= --> <!-- dynamic update for image --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: imagesvg.svg,v 1.1 2002/05/25 18:08:41 tkormann Exp $ --> <!-- ========================================================================= --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="body" width="450" height="500" viewBox="0 0 450 500"> <title>update on <image></title> <style type="text/css"><![CDATA[ ]]></style> <script type="text/ecmascript" > function setPAR(evt,par){ var e = evt.target; e.setAttribute('preserveAspectRatio',par); } </script> <g id="content"> <text class="title" x="50%" y="40"><image> tests <tspan font-size="12">(preserveAspectRatio)</tspan></text> <defs> <rect id="Rect1" x="40" y="0" width="50" height="20" /> <rect id="Rect2" x="60" y="-10" width="20" height="50" /> </defs> <g transform="translate(0,70)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMin meet')"/> <text font-size="10" x="35" y="60">xMin* meet</text> </g> <g transform="translate(150,70)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMidYMin meet')"/> <text font-size="10" x="35" y="60">xMid* meet</text> </g> <g transform="translate(300,70)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMaxYMin meet')"/> <text font-size="10" x="35" y="60">xMax* meet</text> </g> <g transform="translate(0,170)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMin meet')"/> <text font-size="10" x="35" y="60">*YMin meet</text> </g> <g transform="translate(150,170)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMid meet')"/> <text font-size="10" x="35" y="60">*YMid meet</text> </g> <g transform="translate(300,170)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMax meet')"/> <text font-size="10" x="35" y="60">*YMax meet</text> </g> <g transform="translate(0,270)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMin slice')"/> <text font-size="10" x="35" y="60">xMin* slice</text> </g> <g transform="translate(150,270)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMidYMin slice')"/> <text font-size="10" x="35" y="60">xMid* slice</text> </g> <g transform="translate(300,270)"> <use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/> <image x="60" y="-10" width="20" height="50" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMaxYMin slice')"/> <text font-size="10" x="35" y="60">xMax* slice</text> </g> <g transform="translate(0,370)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMin slice')"/> <text font-size="10" x="35" y="60">*YMin slice</text> </g> <g transform="translate(150,370)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMid slice')"/> <text font-size="10" x="35" y="60">*YMid slice</text> </g> <g transform="translate(300,370)"> <use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/> <image x="40" y="0" width="50" height="20" xlink:href="../../resources/images/svg.svg" onload="setPAR(evt,'xMinYMax slice')"/> <text font-size="10" x="35" y="60">*YMax slice</text> </g> </g> <!-- ============================================================= --> <!-- Batik sample mark --> <!-- ============================================================= --> <use xlink:href="../../../batikLogo.svg#Batik_Tag_Box" /> </svg> 1.1 xml-batik/samples/tests/resources/images/svg.png <<Binary file>> 1.1 xml-batik/test-references/samples/tests/spec/scripting/image.png <<Binary file>> 1.1 xml-batik/test-references/samples/tests/spec/scripting/imageraster.png <<Binary file>> 1.1 xml-batik/test-references/samples/tests/spec/scripting/imagesvg.png <<Binary file>> 1.70 +4 -1 xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml Index: samplesRendering.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v retrieving revision 1.69 retrieving revision 1.70 diff -u -r1.69 -r1.70 --- samplesRendering.xml 14 May 2002 21:28:13 -0000 1.69 +++ samplesRendering.xml 25 May 2002 18:08:41 -0000 1.70 @@ -8,7 +8,7 @@ <!-- ========================================================================= --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: samplesRendering.xml,v 1.69 2002/05/14 21:28:13 tkormann Exp $ --> +<!-- @version $Id: samplesRendering.xml,v 1.70 2002/05/25 18:08:41 tkormann Exp $ --> <!-- ========================================================================= --> <testSuite id="samplesRendering" name="samples and samples/test Rendering" class="org.apache.batik.test.svg.SamplesRenderingTest"> @@ -299,6 +299,9 @@ <test id="samples/tests/spec/scripting/text_children2.svg" /> <test id="samples/tests/spec/scripting/text_children3.svg" /> <test id="samples/tests/spec/scripting/tspanProperties.svg" /> + <test id="samples/tests/spec/scripting/image.svg" /> + <test id="samples/tests/spec/scripting/imageraster.svg" /> + <test id="samples/tests/spec/scripting/imagesvg.svg" /> </testGroup> </testSuite> 1.45 +74 -3 xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java Index: SVGImageElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- SVGImageElementBridge.java 27 Apr 2002 22:41:57 -0000 1.44 +++ SVGImageElementBridge.java 25 May 2002 18:08:41 -0000 1.45 @@ -55,7 +55,7 @@ * Bridge class for the <image> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGImageElementBridge.java,v 1.44 2002/04/27 22:41:57 deweese Exp $ + * @version $Id: SVGImageElementBridge.java,v 1.45 2002/05/25 18:08:41 tkormann Exp $ */ public class SVGImageElementBridge extends AbstractGraphicsNodeBridge { @@ -194,9 +194,74 @@ * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ public void handleDOMAttrModifiedEvent(MutationEvent evt) { - super.handleDOMAttrModifiedEvent(evt); - } + String attrName = evt.getAttrName(); + if (attrName.equals(SVG_X_ATTRIBUTE) || + attrName.equals(SVG_Y_ATTRIBUTE) || + attrName.equals(SVG_WIDTH_ATTRIBUTE) || + attrName.equals(SVG_HEIGHT_ATTRIBUTE) || + attrName.equals(SVG_PRESERVE_ASPECT_RATIO_ATTRIBUTE)){ + + //retrieve the new bounds of the image tag + Rectangle2D bounds = getImageBounds(ctx, e); + GraphicsNode imageNode = ((ImageNode)node).getImage(); + float [] vb = null; + + if (((ImageNode)node).getImage() instanceof RasterImageNode) { + //Raster image + Rectangle2D imgBounds = + ((RasterImageNode)imageNode).getImageBounds(); + // create the implicit viewBox for the raster + // image. The viewBox for a raster image is the size + // of the image + vb = new float[4]; + vb[0] = 0; // x + vb[1] = 0; // y + vb[2] = (float)imgBounds.getWidth(); // width + vb[3] = (float)imgBounds.getHeight(); // height + } else { + // svg image need the viewbox of the embedded + String uriStr = XLinkSupport.getXLinkHref(e); + if ( uriStr == null || uriStr.length() == 0 ){ + throw new BridgeException(e, ERR_ATTRIBUTE_MISSING, + new Object[] {"xlink:href"}); + } + // try to load the image as an svg document + SVGDocument svgDoc = (SVGDocument)e.getOwnerDocument(); + // try to load an SVG document + DocumentLoader loader = ctx.getDocumentLoader(); + URIResolver resolver = new URIResolver(svgDoc, loader); + SVGDocument imgDocument = null; + try { + Node n = resolver.getNode(uriStr, e); + if (n.getNodeType() == n.DOCUMENT_NODE) { + imgDocument = (SVGDocument)n; + } + } catch (BridgeException ex) { + throw ex; + } catch (Exception ex) { + /* Nothing to do */ + } + if (imgDocument != null) { + Element svgElement = imgDocument.getRootElement(); + String viewBox = + svgElement.getAttributeNS(null, SVG_VIEW_BOX_ATTRIBUTE); + vb = ViewBox.parseViewBoxAttribute(e, viewBox); + } else { + imageNode = null; + } + } + if (imageNode != null) { + // handles the 'preserveAspectRatio', 'overflow' and + // 'clip' and sets the appropriate AffineTransform to + // the image node + initializeViewport(ctx, e, imageNode, vb, bounds); + } + } else { + super.handleDOMAttrModifiedEvent(evt); + } + } + // convenient methods ////////////////////////////////////////////////// /** @@ -286,9 +351,15 @@ if (ctx.isDynamic()) { EventListener listener = new ForwardEventListener(svgElement, e); EventTarget target = (EventTarget)svgElement; + target.addEventListener(SVG_EVENT_CLICK, listener, false); + ctx.storeEventListener(target, SVG_EVENT_CLICK, listener, false); + target.addEventListener(SVG_EVENT_MOUSEOVER, listener, false); + ctx.storeEventListener(target, SVG_EVENT_MOUSEOVER, listener,false); + target.addEventListener(SVG_EVENT_MOUSEOUT, listener, false); + ctx.storeEventListener(target, SVG_EVENT_MOUSEOUT, listener, false); } return result;
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]