nsochele 2002/09/25 10:20:37
Modified: sources/org/apache/batik/bridge SVGImageElementBridge.java
test-resources/org/apache/batik/test samplesRendering.xml
Added: samples/tests/spec/scripting imageRefUpdate.svg
test-references/samples/tests/spec/scripting
imageRefUpdate.png
Log:
added support for dynamic modifications of 'xlink:href' in image element
added test slide : imageRefUpdate.svg
(RFE #12735)
Revision Changes Path
1.51 +71 -18
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.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- SVGImageElementBridge.java 13 Aug 2002 21:33:16 -0000 1.50
+++ SVGImageElementBridge.java 25 Sep 2002 17:20:31 -0000 1.51
@@ -94,6 +94,40 @@
return null;
}
+ GraphicsNode node = buildImageGraphicsNode(ctx,e);
+
+ if (node == null) {
+ String uriStr = XLinkSupport.getXLinkHref(e);
+ throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
+ new Object[] {uriStr});
+ }
+
+ imageNode.setImage(node);
+
+ // 'image-rendering' and 'color-rendering'
+ RenderingHints hints = CSSUtilities.convertImageRendering(e, null);
+ hints = CSSUtilities.convertColorRendering(e, hints);
+ if (hints != null) {
+ imageNode.setRenderingHints(hints);
+ }
+
+ return imageNode;
+ }
+
+ /**
+ * Create a Graphics node according to the
+ * resource pointed by the href : RasterImageNode
+ * for bitmaps, CompositeGraphicsNode for svg files.
+ *
+ * @param ctx : the bridge context to use
+ * @param e the element that describes the graphics node to build
+ *
+ * @return the graphic node that represent the resource
+ * pointed by the reference
+ */
+ protected GraphicsNode buildImageGraphicsNode
+ (BridgeContext ctx, Element e){
+
// 'xlink:href' attribute - required
String uriStr = XLinkSupport.getXLinkHref(e);
if (uriStr.length() == 0) {
@@ -104,6 +138,7 @@
throw new BridgeException(e, ERR_ATTRIBUTE_VALUE_MALFORMED,
new Object[] {"xlink:href", uriStr});
}
+
GraphicsNode node = null;
// try to load the image as an svg document
SVGDocument svgDoc = (SVGDocument)e.getOwnerDocument();
@@ -137,22 +172,7 @@
// try to load the image as a raster image (JPG or PNG)
node = createRasterImageNode(ctx, e, purl);
}
-
- if (node == null) {
- throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
- new Object[] {uriStr});
- }
-
- imageNode.setImage(node);
-
- // 'image-rendering' and 'color-rendering'
- RenderingHints hints = CSSUtilities.convertImageRendering(e, null);
- hints = CSSUtilities.convertColorRendering(e, hints);
- if (hints != null) {
- imageNode.setRenderingHints(hints);
- }
-
- return imageNode;
+ return node;
}
/**
@@ -201,7 +221,9 @@
*/
public void handleDOMAttrModifiedEvent(MutationEvent evt) {
- String attrName = evt.getAttrName();
+ String attrName = evt.getAttrName();
+ Node evtNode = evt.getRelatedNode();
+
if (attrName.equals(SVG_X_ATTRIBUTE) ||
attrName.equals(SVG_Y_ATTRIBUTE) ||
attrName.equals(SVG_WIDTH_ATTRIBUTE) ||
@@ -238,6 +260,37 @@
// the image node
initializeViewport(ctx, e, imageNode, vb, bounds);
}
+
+ } else if (( XLinkSupport.XLINK_NAMESPACE_URI.equals
+ (evtNode.getNamespaceURI()) )
+ && SVG_HREF_ATTRIBUTE.equals(evtNode.getLocalName()) ){
+ //reference copy of the imgDocument
+ SVGDocument oldSVGDoc = imgDocument;
+
+ //update of the reference of the image.
+ GraphicsNode inode = buildImageGraphicsNode(ctx,e);
+
+ if (inode == null) {
+ String uriStr = XLinkSupport.getXLinkHref(e);
+ throw new BridgeException(e, ERR_URI_IMAGE_INVALID,
+ new Object[] {uriStr});
+ }
+ ImageNode imgNode = (ImageNode)node;
+ //HACK : see 'initializeDynamicSupport'
+ if (imgNode.getImage() instanceof RasterImageNode) {
+ // register the RasterImageNode instead
+ ctx.unbind(e);
+ ctx.bind(e, inode );
+ }
+ else{
+ //it was an svg file referenced
+ //dispose it
+ if ( oldSVGDoc != null ){
+ disposeTree(oldSVGDoc);
+ }
+ }
+ imgNode.setImage(inode);
+
} else {
super.handleDOMAttrModifiedEvent(evt);
}
1.84 +2 -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.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- samplesRendering.xml 6 Sep 2002 07:46:47 -0000 1.83
+++ samplesRendering.xml 25 Sep 2002 17:20:31 -0000 1.84
@@ -322,6 +322,7 @@
<test id="samples/tests/spec/scripting/image.svg" />
<test id="samples/tests/spec/scripting/imageraster.svg" />
<test id="samples/tests/spec/scripting/imagesvg.svg" />
+ <test id="samples/tests/spec/scripting/imageRefUpdate.svg" />
<test id="samples/tests/spec/scripting/gradientsUpdate.svg" />
<test id="samples/tests/spec/scripting/maskClipUpdate.svg" />
<test id="samples/tests/spec/scripting/markerUpdate.svg" />
1.1 xml-batik/samples/tests/spec/scripting/imageRefUpdate.svg
Index: imageRefUpdate.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: imageRefUpdate.svg,v 1.1 2002/09/25 17:20:32 nsochele 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" >
var xlinkNS = "http://www.w3.org/1999/xlink";
function setRef(evt,ref){
var e = evt.target;
e.setAttributeNS(xlinkNS,"href",ref);
}
</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="40" y="-20" width="100" height="40" preserveAspectRatio="none"
xlink:href="../../resources/images/svg.svg" />
<text font-size="10" x="35" y="60">SVG image Reference</text>
</g>
<g transform="translate(230,150)">
<use xlink:href="#Rect1" style="fill:none; stroke:blue; stroke-width:2"/>
<image x="40" y="-20" width="100" height="40" preserveAspectRatio="none"
xlink:href="../../resources/images/svg.svg"
onload="setRef(evt,'../../resources/images/svg3.svg')"
onclick="alert('click supported')" />
<text font-size="10" x="35" y="60">SVG Image changed</text>
</g>
<g transform="translate(70,300)">
<use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/>
<image x="60" y="-60" width="40" height="100" preserveAspectRatio="none"
xlink:href="../../resources/images/svg.png" />
<text font-size="10" x="35" y="60">PNG Image Reference</text>
</g>
<g transform="translate(230,300)">
<use xlink:href="#Rect2" style="fill:none; stroke:blue; stroke-width:2"/>
<image x="60" y="-60" width="40" height="100" preserveAspectRatio="none"
xlink:href="../../resources/images/svg.png"
onload="setRef(evt,'../../resources/images/png.png')"
onclick="alert('clisk supported')" />
<text font-size="10" x="35" y="60">PNG Image changed</text>
</g>
</g>
<!-- ============================================================= -->
<!-- Batik sample mark -->
<!-- ============================================================= -->
<use xlink:href="../../../batikLogo.svg#Batik_Tag_Box" />
</svg>
1.1
xml-batik/test-references/samples/tests/spec/scripting/imageRefUpdate.png
<<Binary file>>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]