deweese 2003/07/08 19:10:12 Modified: samples/tests/spec/scripting memoryLeak1.svg samples/tests/spec/text textOnPath2.svg textOnPath3.svg sources/org/apache/batik/bridge BridgeContext.java sources/org/apache/batik/css/dom CSSOMSVGPaint.java sources/org/apache/batik/css/engine CSSEngine.java sources/org/apache/batik/dom AbstractParentNode.java sources/org/apache/batik/dom/svg SVGStylableElement.java sources/org/apache/batik/gvt/renderer StrokingTextPainter.java sources/org/apache/batik/gvt/text GlyphLayout.java sources/org/apache/batik/script/rhino EventTargetWrapper.java RhinoInterpreter.java WindowWrapper.java sources/org/apache/batik/swing/gvt JGVTComponent.java sources/org/apache/batik/swing/svg JSVGComponent.java sources/org/apache/batik/transcoder SVGAbstractTranscoder.java test-references/samples/tests/spec/text textOnPath2.png textOnPath3.png test-resources/org/apache/batik/test interactiveSamples.xml samplesRendering.xml test-resources/org/apache/batik/transcoder/image unitTesting.xml test-sources/org/apache/batik/swing JSVGCanvasHandler.java JSVGMemoryLeakTest.java NullSetSVGDocumentTest.java test-sources/org/apache/batik/test MemoryLeakTest.java test-sources/org/apache/batik/transcoder TranscoderInputTest.java Added: samples/tests/spec/scripting setProperty.svg samples/tests/spec/text textDecoration2.svg test-references/samples/tests/spec/scripting setProperty.png test-references/samples/tests/spec/text textDecoration2.png test-sources/org/apache/batik/transcoder/image GenericDocumentTest.java Log: 1) Text-decoration is now much more conformant. Decorations are now always vertically aligned with the the underline at the start of a text chunk. 2) The end of a text-path now forms a new text chunk. 3) Fixed a bug in handling absolute x/y attributes in non-text progression direction. 4) The CSS Dom interface SVGPaint now properly implements uriChanged and paintChanged methods. 5) AbstractParentNode insertNode, removeNode, replaceNode are now much faster for Parents with many children. 6) Setting uri CSS properties from the CSS DOM now works properly. 7) New fix to the Rhino Interpreter memory leak that does not depend on shutting off caching. Global state is now 'stored' in a subclass of Context - this avoids static references to 'global' objects. 8) Transcoders will now accept any Document and convert to a Batik implementation if needed. 9) Improved the NullSetSVGDocument test (closed race condition). PR: 21362, 14789, 9994 Revision Changes Path 1.3 +3 -3 xml-batik/samples/tests/spec/scripting/memoryLeak1.svg Index: memoryLeak1.svg =================================================================== RCS file: /home/cvs/xml-batik/samples/tests/spec/scripting/memoryLeak1.svg,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- memoryLeak1.svg 8 Jul 2003 00:16:56 -0000 1.2 +++ memoryLeak1.svg 9 Jul 2003 02:10:10 -0000 1.3 @@ -50,8 +50,8 @@ <g id="test-content"> <g style="font-size:20" > <text id="t1_bg" x="5" y="135" fill="purple" >Simple Text</text> - <text id="t2" x="155" y="135" fill="gold" >Simple Text</text> - <text id="t1" x="305" y="135" fill="crimson">Simple Text</text> + <text id="t2" x="155" y="135" fill="crimson">Simple Text</text> + <text id="t1" x="305" y="135" fill="gold" >Simple Text</text> </g> <g> 1.1 xml-batik/samples/tests/spec/scripting/setProperty.svg Index: setProperty.svg =================================================================== <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20000802//EN" "http://www.w3.org/TR/2000/CR-SVG-20000802/DTD/svg-20000802.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. --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- Testing calls to CSSStlyeDeclaration.setProperty --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: setProperty.svg,v 1.1 2003/07/09 02:10:10 deweese Exp $ --> <!-- ====================================================================== --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg id="body" width="450" height="500" viewBox="0 0 450 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Testing CSS DOM with setProperty.</title> <script><![CDATA[ function regardStart(){ setTimeout("test()", 20); } function test() { var e, style; e = document.getElementById("r1"); style = e.getStyle(); style.setProperty("fill","url(#lg)",""); e = document.getElementById("r2"); style = e.getStyle(); var paint = style.getPropertyCSSValue("fill"); paint.setPaint(SVGPaint.SVG_PAINTTYPE_URI, "#lg", "", ""); if (paint.getPaintType() != SVGPaint.SVG_PAINTTYPE_URI) throw ("Wrong paint type: " + paint.getPaintType()); if (regardTestInstance != null) regardTestInstance.scriptDone(); } ]]></script> <linearGradient id="lg" x1="25%" x2="75%" y1="75%" y2="25%"> <stop offset=".0" stop-color="gold" /> <stop offset="1" stop-color="crimson" /> </linearGradient> <g> <title>Setting CSS properties through CSS DOM</title> <text class="title" x="50%" y="40" >Setting CSS properties through CSS DOM</text> <rect id="r1" x="10" y="150" width="100" height="50" fill="green"/> <rect id="r2" x="120" y="150" width="100" height="50" style="fill:purple"/> </g> </svg> 1.3 +1 -1 xml-batik/samples/tests/spec/text/textOnPath2.svg Index: textOnPath2.svg =================================================================== RCS file: /home/cvs/xml-batik/samples/tests/spec/text/textOnPath2.svg,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- textOnPath2.svg 4 Mar 2003 12:11:57 -0000 1.2 +++ textOnPath2.svg 9 Jul 2003 02:10:10 -0000 1.3 @@ -67,7 +67,7 @@ <use xlink:href="#path"/> <text x="10" y="0" fill="black">This is simple<textPath fill="crimson" xlink:href="#path" - startOffset="75%" text-anchor="middle" + startOffset="50%" text-anchor="middle" >text on a path<tspan fill="orange" dy="-10" >with nested</tspan><tspan fill="green" dy="10" > tspan</tspan></textPath 1.2 +2 -1 xml-batik/samples/tests/spec/text/textOnPath3.svg Index: textOnPath3.svg =================================================================== RCS file: /home/cvs/xml-batik/samples/tests/spec/text/textOnPath3.svg,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- textOnPath3.svg 4 Mar 2003 12:11:57 -0000 1.1 +++ textOnPath3.svg 9 Jul 2003 02:10:10 -0000 1.2 @@ -66,7 +66,8 @@ <use xlink:href="#path" /> <text x="-100" y="10" fill="black"><textPath fill="crimson" xlink:href="#path" startOffset="50%" - text-anchor="middle">Text on a path for text w/ 'x'.</textPath + text-anchor="middle">Text on a <tspan x="50" + >path for text w/ 'x'.</tspan></textPath ></text> </g> </svg> 1.1 xml-batik/samples/tests/spec/text/textDecoration2.svg Index: textDecoration2.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. --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- Test the handling of text decoration, especially in the presence of --> <!-- of dx, dy attributes. --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: textDecoration2.svg,v 1.1 2003/07/09 02:10:10 deweese Exp $ --> <!-- ====================================================================== --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg id="body" width="450" height="500" viewBox="0 0 450 500" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>Text Decoration with dx,dy Tests</title> <text class="title" x="50%" y="40" >Text Decoration with dx, dy tests</text> <!-- <rect x="0" y="0" width="100%" height="100%" fill="lightgrey"/> --> <g transform="translate(0, 50)" fill="rgb(0,0,0)" font-family="Lucida Sans Typewriter" font-size="15.0"> <text x="31.0" y="24.0" text-decoration="underline" >This is a text<tspan x="31.0" dy="1.2em" >that covers multiple</tspan><tspan x="31.0" dy="1.2em" >lines</tspan></text> <text x="231.0" y="24" text-decoration="underline" >This is a text<tspan x="231.0" y="41" >that covers multiple</tspan><tspan x="231" y="60" >lines</tspan></text> <text x="31.0" y="100" text-decoration="line-through" >Text <tspan dy="-5">that</tspan> <tspan dy="10">shifts</tspan></text> <text x="31.0" y="130" >Text <tspan dy="-5" text-decoration="line-through" >that</tspan> <tspan dy="10">shifts</tspan></text> <text x="31.0" y="160" >Text <tspan dy="-5">that</tspan> <tspan dy="10" text-decoration="line-through">shifts</tspan></text> <text x="31.0" y="200" >Text <tspan dy="-5">that</tspan> <tspan dy="-5" text-decoration="line-through">shifts</tspan></text> <text x="231.0" y="100" text-decoration="overline" >Text <tspan dy="-5">that</tspan> <tspan dy="10">shifts</tspan></text> <text x="231.0" y="130" >Text <tspan dy="-5" text-decoration="overline" >that</tspan> <tspan dy="10">shifts</tspan></text> <text x="231.0" y="160" >Text <tspan dy="-5">that</tspan> <tspan dy="10" text-decoration="overline">shifts</tspan></text> <text x="231.0" y="200" >Text <tspan dy="-5">that</tspan> <tspan dy="-5" text-decoration="overline">shifts</tspan></text> <text x="31.0" y="240" text-decoration="underline" >Text <tspan dy="-5">that</tspan> <tspan dy="10">shifts</tspan></text> <text x="31.0" y="270" >Text <tspan dy="-5" text-decoration="underline" >that</tspan> <tspan dy="10">shifts</tspan></text> <text x="31.0" y="300" >Text <tspan dy="-5">that</tspan> <tspan dy="10" text-decoration="underline">shifts</tspan></text> <text x="31.0" y="330" >Text <tspan dy="-5">that</tspan> <tspan dy="-5" text-decoration="underline">shifts</tspan></text> <text x="231.0" y="240" text-decoration="underline" fill="blue" ><tspan fill="black" stroke="none" >Text <tspan dy="-5">that</tspan> <tspan dy="10" >shifts</tspan></tspan></text> <text x="231.0" y="270" text-decoration="underline" fill="blue" ><tspan fill="black" >Text <tspan dy="-5" text-decoration="line-through" fill="red" ><tspan fill="black">that</tspan></tspan> <tspan dy="10" >shifts</tspan></tspan></text> <text x="231.0" y="300" text-decoration="underline" fill="blue" ><tspan fill="black" >Text <tspan dy="-5">that</tspan> <tspan dy="10" text-decoration="underline" fill="red"> <tspan fill="black">shifts</tspan></tspan></tspan></text> <text x="231.0" y="330" text-decoration="underline" fill="blue" ><tspan fill="black" >Text <tspan dy="-5" text-decoration="line-through" fill="red" ><tspan fill="black" >that <tspan dy="10" text-decoration="overline" fill="green" ><tspan fill="black" >shifts</tspan></tspan></tspan></tspan></tspan></text> <text x="131.0" y="370" text-decoration="underline" fill="blue" ><tspan fill="black">Text <tspan y="360">that</tspan> <tspan y="375" >shifts</tspan></tspan></text> </g> </svg> 1.66 +5 -3 xml-batik/sources/org/apache/batik/bridge/BridgeContext.java Index: BridgeContext.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeContext.java,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- BridgeContext.java 8 Jul 2003 00:16:56 -0000 1.65 +++ BridgeContext.java 9 Jul 2003 02:10:10 -0000 1.66 @@ -35,6 +35,7 @@ import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.dom.svg.SVGOMDocument; import org.apache.batik.dom.svg.SVGOMElement; +import org.apache.batik.dom.svg.SVGStylableElement; import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.TextPainter; import org.apache.batik.script.Interpreter; @@ -1176,10 +1177,11 @@ // No cache needed since the default font family is asked only // one time on the root element (only if it does not have its // own font-family). - SVGOMDocument doc = (SVGOMDocument)document; + SVGOMDocument doc = (SVGOMDocument)document; + SVGStylableElement root = (SVGStylableElement)doc.getRootElement(); String str = userAgent.getDefaultFontFamily(); return doc.getCSSEngine().parsePropertyValue - (SVGConstants.CSS_FONT_FAMILY_PROPERTY, str); + (root,SVGConstants.CSS_FONT_FAMILY_PROPERTY, str); } /** 1.3 +8 -22 xml-batik/sources/org/apache/batik/css/dom/CSSOMSVGPaint.java Index: CSSOMSVGPaint.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/dom/CSSOMSVGPaint.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CSSOMSVGPaint.java 11 Apr 2003 13:55:19 -0000 1.2 +++ CSSOMSVGPaint.java 9 Jul 2003 02:10:10 -0000 1.3 @@ -818,25 +818,8 @@ /** * Called when the URI has been modified. */ - public void uriChanged(String uri) { - switch (getPaintType()) { - case SVG_PAINTTYPE_URI_NONE: - case SVG_PAINTTYPE_URI_CURRENTCOLOR: - case SVG_PAINTTYPE_URI_RGBCOLOR: - textChanged("url(" + uri + ") " + - getValue().item(1).getCssText()); - break; - - case SVG_PAINTTYPE_URI_RGBCOLOR_ICCCOLOR: - textChanged("url(" + uri + ") " + - getValue().item(1).getCssText() + " " + - getValue().item(2).getCssText()); - break; - - default: - throw new DOMException - (DOMException.NO_MODIFICATION_ALLOWED_ERR, ""); - } + public void uriChanged(String uri) { + textChanged("url(" + uri + ") none"); } /** @@ -844,7 +827,7 @@ */ public void paintChanged(short type, String uri, String rgb, String icc) { - switch (getPaintType()) { + switch (type) { case SVG_PAINTTYPE_NONE: textChanged("none"); break; @@ -861,6 +844,10 @@ textChanged(rgb + " " + icc); break; + case SVG_PAINTTYPE_URI: + textChanged("url(" + uri + ")"); + break; + case SVG_PAINTTYPE_URI_NONE: textChanged("url(" + uri + ") none"); break; @@ -877,7 +864,6 @@ textChanged("url(" + uri + ") " + rgb + " " + icc); } } - } } 1.22 +7 -2 xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java Index: CSSEngine.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- CSSEngine.java 11 Jun 2003 22:07:27 -0000 1.21 +++ CSSEngine.java 9 Jul 2003 02:10:10 -0000 1.22 @@ -856,8 +856,10 @@ * @param prop The property name. * @param value The property value. */ - public Value parsePropertyValue(String prop, String value) { + public Value parsePropertyValue(CSSStylableElement elt, + String prop, String value) { try { + element = elt; LexicalUnit lu; int idx = getPropertyIndex(prop); lu = parser.parsePropertyValue(value); @@ -872,7 +874,10 @@ value, (m == null) ? "" : m }); throw new DOMException(DOMException.SYNTAX_ERR, s); + } finally { + element = null; } + } /** 1.19 +49 -43 xml-batik/sources/org/apache/batik/dom/AbstractParentNode.java Index: AbstractParentNode.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/AbstractParentNode.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- AbstractParentNode.java 11 Apr 2003 13:56:01 -0000 1.18 +++ AbstractParentNode.java 9 Jul 2003 02:10:10 -0000 1.19 @@ -755,20 +755,27 @@ children++; return n; } + if (r == lastChild) { + ExtendedNode ps = (ExtendedNode)r.getPreviousSibling(); + ps.setNextSibling(n); + r.setPreviousSibling(n); + n.setNextSibling(r); + n.setPreviousSibling(ps); + children++; + return n; + } + + ExtendedNode ps = (ExtendedNode)r.getPreviousSibling(); + if ((ps.getNextSibling() == r) && + (ps.getParentNode() == r.getParentNode())) { + ps.setNextSibling(n); + n.setPreviousSibling(ps); + n.setNextSibling(r); + r.setPreviousSibling(n); + children++; + return n; + } - ExtendedNode o = firstChild; - while (o != null) { - if (o == r) { - ExtendedNode ps = (ExtendedNode)r.getPreviousSibling(); - ps.setNextSibling(n); - r.setPreviousSibling(n); - n.setNextSibling(r); - n.setPreviousSibling(ps); - children++; - return n; - } - o = (ExtendedNode)o.getNextSibling(); - } throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", @@ -802,21 +809,21 @@ return o; } - ExtendedNode cn = firstChild; - while (cn != null) { - if (cn == o) { - ExtendedNode t = (ExtendedNode)o.getPreviousSibling(); - n.setPreviousSibling(t); - t.setNextSibling(n); - t = (ExtendedNode)o.getNextSibling(); - n.setNextSibling(t); - t.setPreviousSibling(n); - o.setPreviousSibling(null); - o.setNextSibling(null); - return o; - } - cn = (ExtendedNode)cn.getNextSibling(); - } + ExtendedNode ps = (ExtendedNode)o.getPreviousSibling(); + ExtendedNode ns = (ExtendedNode)o.getNextSibling(); + if ((ps.getNextSibling() == o) && + (ns.getPreviousSibling() == o) && + (ps.getParentNode() == o.getParentNode()) && + (ns.getParentNode() == o.getParentNode())) { + + ps.setNextSibling(n); + n.setPreviousSibling(ps); + n.setNextSibling(ns); + ns.setPreviousSibling(n); + o.setPreviousSibling(null); + o.setNextSibling(null); + return o; + } throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", @@ -850,20 +857,19 @@ return n; } - ExtendedNode o = firstChild; - while (o != null) { - if (o == n) { - ExtendedNode ps = (ExtendedNode)n.getPreviousSibling(); - ExtendedNode ns = (ExtendedNode)n.getNextSibling(); - ps.setNextSibling(ns); - ns.setPreviousSibling(ps); - n.setPreviousSibling(null); - n.setNextSibling(null); - children--; - return n; - } - o = (ExtendedNode)o.getNextSibling(); - } + ExtendedNode ps = (ExtendedNode)n.getPreviousSibling(); + ExtendedNode ns = (ExtendedNode)n.getNextSibling(); + if ((ps.getNextSibling() == n) && + (ns.getPreviousSibling() == n) && + (ps.getParentNode() == n.getParentNode()) && + (ns.getParentNode() == n.getParentNode())) { + ps.setNextSibling(ns); + ns.setPreviousSibling(ps); + n.setPreviousSibling(null); + n.setNextSibling(null); + children--; + return n; + } throw createDOMException (DOMException.NOT_FOUND_ERR, "child.missing", 1.8 +29 -15 xml-batik/sources/org/apache/batik/dom/svg/SVGStylableElement.java Index: SVGStylableElement.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGStylableElement.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SVGStylableElement.java 11 Apr 2003 13:56:17 -0000 1.7 +++ SVGStylableElement.java 9 Jul 2003 02:10:10 -0000 1.8 @@ -227,7 +227,8 @@ return PresentationAttributeValue.this.getValue(); } public void textChanged(String text) throws DOMException { - value = cssEngine.parsePropertyValue(property, text); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, text); mutate = true; setAttributeNS(null, property, text); mutate = false; @@ -239,7 +240,8 @@ Attr attr = getAttributeNodeNS(null, prop); if (attr != null) { - value = cssEngine.parsePropertyValue(prop, attr.getValue()); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, prop, attr.getValue()); } } @@ -262,7 +264,8 @@ */ public void attrAdded(Attr node, String newv) { if (!mutate) { - value = cssEngine.parsePropertyValue(property, newv); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, newv); } } @@ -271,7 +274,8 @@ */ public void attrModified(Attr node, String oldv, String newv) { if (!mutate) { - value = cssEngine.parsePropertyValue(property, newv); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, newv); } } @@ -324,7 +328,8 @@ return PresentationAttributeColorValue.this.getValue(); } public void textChanged(String text) throws DOMException { - value = cssEngine.parsePropertyValue(property, text); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, text); mutate = true; setAttributeNS(null, property, text); mutate = false; @@ -336,7 +341,8 @@ Attr attr = getAttributeNodeNS(null, prop); if (attr != null) { - value = cssEngine.parsePropertyValue(prop, attr.getValue()); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, prop, attr.getValue()); } } @@ -359,7 +365,8 @@ */ public void attrAdded(Attr node, String newv) { if (!mutate) { - value = cssEngine.parsePropertyValue(property, newv); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, newv); } } @@ -368,7 +375,8 @@ */ public void attrModified(Attr node, String oldv, String newv) { if (!mutate) { - value = cssEngine.parsePropertyValue(property, newv); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, newv); } } @@ -421,7 +429,8 @@ return PresentationAttributePaintValue.this.getValue(); } public void textChanged(String text) throws DOMException { - value = cssEngine.parsePropertyValue(property, text); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, text); mutate = true; setAttributeNS(null, property, text); mutate = false; @@ -434,7 +443,8 @@ Attr attr = getAttributeNodeNS(null, prop); if (attr != null) { - value = cssEngine.parsePropertyValue(prop, attr.getValue()); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, prop, attr.getValue()); } } @@ -457,7 +467,8 @@ */ public void attrAdded(Attr node, String newv) { if (!mutate) { - value = cssEngine.parsePropertyValue(property, newv); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, newv); } } @@ -466,7 +477,8 @@ */ public void attrModified(Attr node, String oldv, String newv) { if (!mutate) { - value = cssEngine.parsePropertyValue(property, newv); + value = cssEngine.parsePropertyValue + (SVGStylableElement.this, property, newv); } } @@ -627,7 +639,8 @@ int idx = cssEngine.getPropertyIndex(name); for (int i = 0; i < declaration.size(); i++) { if (idx == declaration.getIndex(i)) { - Value v = cssEngine.parsePropertyValue(name, value); + Value v = cssEngine.parsePropertyValue + (SVGStylableElement.this, name, value); declaration.put(i, v, idx, prio.length() > 0); mutate = true; setAttributeNS(null, SVG_STYLE_ATTRIBUTE, @@ -636,7 +649,8 @@ return; } } - Value v = cssEngine.parsePropertyValue(name, value); + Value v = cssEngine.parsePropertyValue + (SVGStylableElement.this, name, value); declaration.append(v, idx, prio.length() > 0); mutate = true; setAttributeNS(null, SVG_STYLE_ATTRIBUTE, 1.45 +113 -48 xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java Index: StrokingTextPainter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- StrokingTextPainter.java 8 May 2003 11:39:12 -0000 1.44 +++ StrokingTextPainter.java 9 Jul 2003 02:10:10 -0000 1.45 @@ -285,6 +285,9 @@ if (start != chunkStartIndex) { // If we aren't the first composite in a chunck see // if we need to form a new TextChunk... + // We only create new chunks when given an absolute + // location in progression direction [Spec says + // to do it for either but this doesn't make sense]. if (vertical) { Float runY = (Float) aci.getAttribute(YPOS); // Check for absolute location in layout direction. @@ -297,9 +300,15 @@ break; // If so end of chunk... } - // do additional check for the start of a textPath + // Do additional check for the start of a textPath if ((prevTextPath == null) && (textPath != null)) break; // If so end of chunk. + + // Form a new chunk at the end of a text path. + // [ This is not mentioned in the spec but makes + // sense]. + if ((prevTextPath != null) && (textPath == null)) + break; } prevTextPath = textPath; @@ -792,7 +801,8 @@ float tpShiftX = 0; float tpShiftY = 0; - // Of course X and Y override that, but they don't apply for text on a path. + // Of course X and Y override that, but they don't apply for + // text on a path. if ((runX != null) && (!runX.isNaN())) { absX = runX.floatValue(); tpShiftX = absX; @@ -824,6 +834,17 @@ runaci = r.getACI(); runaci.first(); textPath = (TextPath) runaci.getAttribute(TEXTPATH); + if (vertical) { + runX = (Float) runaci.getAttribute(XPOS); + if ((runX != null) && (!runX.isNaN())) { + absX = runX.floatValue(); + } + } else { + runY = (Float) runaci.getAttribute(YPOS); + if ((runY != null) && (!runY.isNaN())) { + absY = runY.floatValue(); + } + } if (textPath == null) { layout.setOffset(new Point2D.Float(absX, absY)); @@ -852,12 +873,12 @@ private void paintDecorations(List textRuns, Graphics2D g2d, int decorationType) { - Paint prevPaint = null; Paint prevStrokePaint = null; Stroke prevStroke = null; Rectangle2D decorationRect = null; - + double yLoc = 0, height = 0; + for (int i = 0; i < textRuns.size(); i++) { TextRun textRun = (TextRun)textRuns.get(i); AttributedCharacterIterator runaci = textRun.getACI(); @@ -894,9 +915,18 @@ return; } - if (textRun.isFirstRunInChunk() || paint != prevPaint - || stroke != prevStroke || strokePaint != prevStrokePaint) { - + if (textRun.isFirstRunInChunk()) { + Shape s = textRun.getLayout().getDecorationOutline + (decorationType); + Rectangle2D r2d = s.getBounds2D(); + yLoc = r2d.getY(); + height = r2d.getHeight(); + } + + if (textRun.isFirstRunInChunk() || + (paint != prevPaint) || + (stroke != prevStroke) || + (strokePaint != prevStrokePaint)) { // if there is a current decoration, draw it now if (decorationRect != null) { @@ -919,18 +949,26 @@ && !textRun.getLayout().isVertical() && !textRun.getLayout().isOnATextPath()) { - // this text run should be decorated with the specified decoration type - // note: decorations are only supported for plain horizontal layouts + // this text run should be decorated with the + // specified decoration type + // NOTE: decorations are only supported for plain + // horizontal layouts - Shape decorationShape = textRun.getLayout().getDecorationOutline(decorationType); + Shape decorationShape = + textRun.getLayout().getDecorationOutline(decorationType); if (decorationRect == null) { // create a new one - decorationRect = decorationShape.getBounds2D(); + Rectangle2D r2d = decorationShape.getBounds2D(); + decorationRect = new Rectangle2D.Double + (r2d.getX(), yLoc, r2d.getWidth(), height); } else { // extend the current one Rectangle2D bounds = decorationShape.getBounds2D(); - decorationRect.setRect(decorationRect.getMinX(), decorationRect.getMinY(), - bounds.getMaxX() - decorationRect.getMinX(), decorationRect.getHeight()); + double minX = Math.min(decorationRect.getX(), + bounds.getX()); + double maxX = Math.max(decorationRect.getMaxX(), + bounds.getMaxX()); + decorationRect.setRect(minX, yLoc, maxX-minX, height); } } prevPaint = paint; @@ -1123,6 +1161,7 @@ Paint prevStrokePaint = null; Stroke prevStroke = null; Rectangle2D decorationRect = null; + double yLoc = 0, height = 0; for (int i = 0; i < textRuns.size(); i++) { TextRun textRun = (TextRun)textRuns.get(i); @@ -1153,6 +1192,14 @@ return null; } + if (textRun.isFirstRunInChunk()) { + Shape s = textRun.getLayout().getDecorationOutline + (decorationType); + Rectangle2D r2d = s.getBounds2D(); + yLoc = r2d.getY(); + height = r2d.getHeight(); + } + if (textRun.isFirstRunInChunk() || paint != prevPaint || stroke != prevStroke || @@ -1180,18 +1227,19 @@ Shape decorationShape = textRun.getLayout().getDecorationOutline(decorationType); - if (decorationRect == null) { // create a new one - decorationRect = decorationShape.getBounds2D(); + Rectangle2D r2d = decorationShape.getBounds2D(); + decorationRect = new Rectangle2D.Double + (r2d.getX(), yLoc, r2d.getWidth(), height); } else { // extend the current one Rectangle2D bounds = decorationShape.getBounds2D(); - decorationRect.setRect - (decorationRect.getMinX(), - decorationRect.getMinY(), - bounds.getMaxX() - decorationRect.getMinX(), - decorationRect.getHeight()); + double minX = Math.min(decorationRect.getX(), + bounds.getX()); + double maxX = Math.max(decorationRect.getMaxX(), + bounds.getMaxX()); + decorationRect.setRect(minX, yLoc, maxX-minX, height); } } @@ -1213,7 +1261,8 @@ } /** - * Returns the stroke outline of the specified decoration type. + * Returns the strokeed outline of the specified decoration type. + * If the decoration has no stroke it will return the fill outline * * @param textRuns The list of text runs to get the decoration outline for. * @param decoratonType Indicates the type of decoration required. @@ -1230,6 +1279,7 @@ Paint prevStrokePaint = null; Stroke prevStroke = null; Rectangle2D decorationRect = null; + double yLoc = 0, height = 0; for (int i = 0; i < textRuns.size(); i++) { @@ -1261,6 +1311,14 @@ return null; } + if (textRun.isFirstRunInChunk()) { + Shape s = textRun.getLayout().getDecorationOutline + (decorationType); + Rectangle2D r2d = s.getBounds2D(); + yLoc = r2d.getY(); + height = r2d.getHeight(); + } + if (textRun.isFirstRunInChunk() || paint != prevPaint || stroke != prevStroke || @@ -1268,16 +1326,19 @@ // if there is a current decoration, added it to the overall // outline - if (decorationRect != null && - prevStroke != null && - prevStrokePaint != null) { - - if (outline == null) { - outline = new GeneralPath - (prevStroke.createStrokedShape(decorationRect)); - } else { - outline.append(prevStroke.createStrokedShape - (decorationRect), false); + if (decorationRect != null) { + + Shape s = null; + if (prevStroke != null && + prevStrokePaint != null) + s = prevStroke.createStrokedShape(decorationRect); + else if (prevPaint != null) + s = decorationRect; + if (s != null) { + if (outline == null) + outline = new GeneralPath(s); + else + outline.append(s, false); } decorationRect = null; } @@ -1296,15 +1357,17 @@ if (decorationRect == null) { // create a new one - decorationRect = decorationShape.getBounds2D(); + Rectangle2D r2d = decorationShape.getBounds2D(); + decorationRect = new Rectangle2D.Double + (r2d.getX(), yLoc, r2d.getWidth(), height); } else { // extend the current one Rectangle2D bounds = decorationShape.getBounds2D(); - decorationRect.setRect - (decorationRect.getMinX(), - decorationRect.getMinY(), - bounds.getMaxX() - decorationRect.getMinX(), - decorationRect.getHeight()); + double minX = Math.min(decorationRect.getX(), + bounds.getX()); + double maxX = Math.max(decorationRect.getMaxX(), + bounds.getMaxX()); + decorationRect.setRect(minX, yLoc, maxX-minX, height); } } @@ -1315,16 +1378,18 @@ // if there is a decoration rect that hasn't been added to the overall // outline - if (decorationRect != null && - prevStroke != null && - prevStrokePaint != null) { - - if (outline == null) { - outline = new GeneralPath(prevStroke.createStrokedShape - (decorationRect)); - } else { - outline.append - (prevStroke.createStrokedShape(decorationRect), false); + if (decorationRect != null) { + Shape s = null; + if (prevStroke != null && + prevStrokePaint != null) + s = prevStroke.createStrokedShape(decorationRect); + else if (prevPaint != null) + s = decorationRect; + if (s != null) { + if (outline == null) + outline = new GeneralPath(s); + else + outline.append(s, false); } } 1.54 +13 -13 xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java Index: GlyphLayout.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java,v retrieving revision 1.53 retrieving revision 1.54 diff -u -r1.53 -r1.54 --- GlyphLayout.java 5 Jul 2003 00:15:07 -0000 1.53 +++ GlyphLayout.java 9 Jul 2003 02:10:11 -0000 1.54 @@ -982,10 +982,10 @@ y += overlineThickness; // Not certain what should be done here... - // aci.first(); - // Float dy = (Float) aci.getAttribute(DY); - // if (dy != null) - // y += dy.floatValue(); + aci.first(); + Float dy = (Float) aci.getAttribute(DY); + if (dy != null) + y += dy.floatValue(); Stroke overlineStroke = new BasicStroke(overlineThickness); @@ -1013,10 +1013,10 @@ new BasicStroke(underlineThickness); // Not certain what should be done here... - // aci.first(); - // Float dy = (Float) aci.getAttribute(DY); - // if (dy != null) - // y += dy.floatValue(); + aci.first(); + Float dy = (Float) aci.getAttribute(DY); + if (dy != null) + y += dy.floatValue(); Rectangle2D logicalBounds = gv.getLogicalBounds(); @@ -1037,10 +1037,10 @@ new BasicStroke(strikethroughThickness); // Not certain what should be done here... - // aci.first(); - // Float dy = (Float) aci.getAttribute(DY); - // if (dy != null) - // y += dy.floatValue(); + aci.first(); + Float dy = (Float) aci.getAttribute(DY); + if (dy != null) + y += dy.floatValue(); Rectangle2D logicalBounds = gv.getLogicalBounds(); return strikethroughStroke.createStrokedShape( 1.9 +105 -95 xml-batik/sources/org/apache/batik/script/rhino/EventTargetWrapper.java Index: EventTargetWrapper.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/rhino/EventTargetWrapper.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- EventTargetWrapper.java 1 Jul 2003 12:09:11 -0000 1.8 +++ EventTargetWrapper.java 9 Jul 2003 02:10:11 -0000 1.9 @@ -9,6 +9,7 @@ package org.apache.batik.script.rhino; import java.lang.reflect.Method; +import java.util.Map; import java.util.HashMap; import org.mozilla.javascript.Context; @@ -16,6 +17,7 @@ import org.mozilla.javascript.JavaScriptException; import org.mozilla.javascript.NativeJavaMethod; import org.mozilla.javascript.NativeJavaObject; +import org.mozilla.javascript.NativeObject; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.Undefined; @@ -41,11 +43,12 @@ /** * The Java function object calling the Rhino function. */ - class FunctionEventListener implements EventListener { + static class FunctionEventListener implements EventListener { private Function function; - - FunctionEventListener(Function f) { + private RhinoInterpreter interpreter; + FunctionEventListener(Function f, RhinoInterpreter i) { function = f; + interpreter = i; } public void handleEvent(Event evt) { try { @@ -83,113 +86,124 @@ } } - class RhinoNativeJavaMethod extends NativeJavaMethod { - RhinoNativeJavaMethod(Method method, String name) { + class RhinoNativeJavaAddMethod extends NativeJavaMethod { + Map listenerMap; + RhinoNativeJavaAddMethod(Method method, String name, + Map listenerMap) { + super(method, name); + this.listenerMap = listenerMap; + } + + public Object call(Context ctx, Scriptable scope, + Scriptable thisObj, Object[] args) + throws JavaScriptException { + NativeJavaObject njo = (NativeJavaObject)thisObj; + if (args[1] instanceof Function) { + + EventListener evtListener = new FunctionEventListener + ((Function)args[1], + ((RhinoInterpreter.ExtendedContext)ctx).getInterpreter()); + listenerMap.put(args[1], evtListener); + // we need to marshall args + Class[] paramTypes = { String.class, Function.class, + Boolean.TYPE }; + for (int i = 0; i < args.length; i++) + args[i] = Context.toType(args[i], paramTypes[i]); + + + ((EventTarget)njo.unwrap()).addEventListener + ((String)args[0], evtListener, + ((Boolean)args[2]).booleanValue()); + return Undefined.instance; + } + if (args[1] instanceof NativeObject) { + EventListener evtListener = + new HandleEventListener((Scriptable)args[1]); + listenerMap.put(args[1], evtListener); + // we need to marshall args + Class[] paramTypes = { String.class, Scriptable.class, + Boolean.TYPE }; + for (int i = 0; i < args.length; i++) + args[i] = Context.toType(args[i], paramTypes[i]); + + ((EventTarget)njo.unwrap()).addEventListener + ((String)args[0], evtListener, + ((Boolean)args[2]).booleanValue()); + return Undefined.instance; + } + + return super.call(ctx, scope, thisObj, args); + } + } + + static class RhinoNativeJavaRemoveMethod extends NativeJavaMethod { + Map listenerMap; + RhinoNativeJavaRemoveMethod(Method method, String name, + Map listenerMap) { super(method, name); + this.listenerMap = listenerMap; } public Object call(Context ctx, Scriptable scope, Scriptable thisObj, Object[] args) throws JavaScriptException { + NativeJavaObject njo = (NativeJavaObject)thisObj; if (args[1] instanceof Function) { - if (this.get(NAME, this).equals(ADD_NAME)) { - EventListener evtListener = - new FunctionEventListener((Function)args[1]); - if (listenerMap == null) - listenerMap = new HashMap(2); - listenerMap.put(args[1], evtListener); - // we need to marshall args - Class[] paramTypes = { String.class, Function.class, - Boolean.TYPE }; - for (int i = 0; i < args.length; i++) - args[i] = Context.toType(args[i], paramTypes[i]); - ((EventTarget)unwrap()). - addEventListener((String)args[0], - evtListener, - ((Boolean)args[2]).booleanValue()); + EventListener el; + el = (EventListener)listenerMap.remove(args[1]); + if (el == null) return Undefined.instance; - } else { - if (listenerMap != null) { - // we need to marshall args - Class[] paramTypes = { String.class, Function.class, - Boolean.TYPE }; - for (int i = 0; i < args.length; i++) - args[i] = Context.toType(args[i], paramTypes[i]); - ((EventTarget)unwrap()). - removeEventListener((String)args[0], - (EventListener)listenerMap. - remove(args[1]), - ((Boolean)args[2]). - booleanValue()); - } + + // we need to marshall args + Class[] paramTypes = { String.class, Function.class, + Boolean.TYPE }; + for (int i = 0; i < args.length; i++) + args[i] = Context.toType(args[i], paramTypes[i]); + + ((EventTarget)njo.unwrap()).removeEventListener + ((String)args[0], el, ((Boolean)args[2]).booleanValue()); + return Undefined.instance; + } + + if (args[1] instanceof NativeObject) { + EventListener el; + el = (EventListener)listenerMap.remove(args[1]); + if (el == null) return Undefined.instance; - } - } else { - if (args[1] instanceof org.mozilla.javascript.NativeObject) { - if (this.get(NAME, this).equals(ADD_NAME)) { - EventListener evtListener = - new HandleEventListener((Scriptable)args[1]); - if (listenerMap == null) - listenerMap = new HashMap(2); - listenerMap.put(args[1], evtListener); - // we need to marshall args - Class[] paramTypes = { String.class, Scriptable.class, - Boolean.TYPE }; - for (int i = 0; i < args.length; i++) - args[i] = Context.toType(args[i], paramTypes[i]); - ((EventTarget)unwrap()). - addEventListener((String)args[0], - evtListener, - ((Boolean)args[2]).booleanValue()); - return Undefined.instance; - } else { - if (listenerMap != null) { - // we need to marshall args - Class[] paramTypes = { String.class, Scriptable.class, - Boolean.TYPE }; - for (int i = 0; i < args.length; i++) - args[i] = Context.toType(args[i], paramTypes[i]); - ((EventTarget)unwrap()). - removeEventListener((String)args[0], - (EventListener)listenerMap. - remove(args[1]), - ((Boolean)args[2]). - booleanValue()); - } - return Undefined.instance; - } - } + + // we need to marshall args + Class[] paramTypes = { String.class, Scriptable.class, + Boolean.TYPE }; + for (int i = 0; i < args.length; i++) + args[i] = Context.toType(args[i], paramTypes[i]); + + ((EventTarget)njo.unwrap()).removeEventListener + ((String)args[0], el, ((Boolean)args[2]).booleanValue()); + return Undefined.instance; } return super.call(ctx, scope, thisObj, args); } } - private RhinoInterpreter interpreter; private NativeJavaMethod methodadd; private NativeJavaMethod methodremove; - private HashMap listenerMap; - private final static String ADD_NAME = "addEventListener"; + private final static String ADD_NAME = "addEventListener"; private final static String REMOVE_NAME = "removeEventListener"; private final static Class[] ARGS_TYPE = { String.class, EventListener.class, Boolean.TYPE }; private final static String NAME = "name"; - EventTargetWrapper(Scriptable scope, EventTarget object, - RhinoInterpreter interp) { + EventTargetWrapper(Scriptable scope, EventTarget object) { super(scope, object, (Class)null); - interpreter = interp; try { - methodadd = - new RhinoNativeJavaMethod(object.getClass(). - getMethod(ADD_NAME, - ARGS_TYPE), - ADD_NAME); - methodremove = - new RhinoNativeJavaMethod(object.getClass(). - getMethod(REMOVE_NAME, - ARGS_TYPE), - REMOVE_NAME); + HashMap listenerMap = new HashMap(2);; + methodadd = new RhinoNativeJavaAddMethod + (object.getClass().getMethod(ADD_NAME,ARGS_TYPE), + ADD_NAME, listenerMap); + methodremove = new RhinoNativeJavaRemoveMethod + (object.getClass().getMethod(REMOVE_NAME,ARGS_TYPE), + REMOVE_NAME, listenerMap); } catch (NoSuchMethodException e) { // should not happened // we are sure the method are there as we @@ -201,14 +215,10 @@ * Overriden Rhino method. */ public Object get(String name, Scriptable start) { - Object method = null; if (name.equals(ADD_NAME)) - method = methodadd; - else - if (name.equals(REMOVE_NAME)) - method = methodremove; - else - method = super.get(name, start); - return method; + return methodadd; + if (name.equals(REMOVE_NAME)) + return methodremove; + return super.get(name, start); } } 1.28 +93 -39 xml-batik/sources/org/apache/batik/script/rhino/RhinoInterpreter.java Index: RhinoInterpreter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/rhino/RhinoInterpreter.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- RhinoInterpreter.java 8 Jul 2003 00:16:57 -0000 1.27 +++ RhinoInterpreter.java 9 Jul 2003 02:10:11 -0000 1.28 @@ -12,6 +12,7 @@ import java.io.Reader; import java.io.StringReader; import java.io.Writer; +import java.lang.reflect.Method; import java.net.URL; import java.security.AccessControlContext; import java.security.AccessController; @@ -20,6 +21,8 @@ import java.util.LinkedList; import java.util.Locale; import java.util.Vector; +import java.util.Map; +import java.util.HashMap; import org.apache.batik.script.Interpreter; import org.apache.batik.script.InterpreterException; @@ -28,6 +31,7 @@ import org.mozilla.javascript.Function; import org.mozilla.javascript.JavaScriptException; import org.mozilla.javascript.NativeJavaPackage; +import org.mozilla.javascript.PropertyException; import org.mozilla.javascript.Script; import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.ScriptableObject; @@ -54,6 +58,16 @@ "org.w3c.dom.views" }; + /** + * The window object + */ + protected Window window; + + public Window getWindow() { + return window; + } + + private static class Entry { String str; Script script; @@ -99,18 +113,6 @@ = new BatikSecurityController(); /** - * Default Context for scripts. This is used only for efficiency - * reason. - */ - protected Context defaultContext; - - /** - * Context vector, to make sure we are not - * setting the security context too many times - */ - protected Vector contexts = new Vector(); - - /** * Build a <code>Interpreter</code> for ECMAScript using Rhino. * * @param documentURL the URL for the document which references @@ -121,8 +123,6 @@ public RhinoInterpreter(URL documentURL) { rhinoClassLoader = new RhinoClassLoader(documentURL, getClass().getClassLoader()); - Context.setCachingEnabled(false); // reset the cache - Context.setCachingEnabled(true); // enable caching again // entering a context Context ctx = enterContext(); try { @@ -167,23 +167,14 @@ * on the context. */ public Context enterContext(){ - Context ctx = Context.enter(); - if (ctx != defaultContext){ - // Set the SecurityController the Context should - // use. - if (!contexts.contains(ctx)) { - ctx.setWrapFactory(wrapFactory); - ctx.setSecurityController(securityController); - // This prevents a serious memory leak where - // all the SVG document state is preserved. - ctx.setCachingEnabled(false); - contexts.add(ctx); - - // Hopefully, we are not switching threads too - // often .... - defaultContext = ctx; - } + Context ctx = Context.getCurrentContext(); + if (ctx == null) { + ctx = new ExtendedContext(); + ctx.setWrapFactory(wrapFactory); + ctx.setSecurityController(securityController); } + ctx = Context.enter(ctx); + return ctx; } @@ -222,10 +213,10 @@ final Context ctx = enterContext(); try { - rv = ctx.evaluateReader(globalObject, - scriptreader, - description, - 1, rhinoClassLoader); + rv = ctx.evaluateReader(globalObject, + scriptreader, + description, + 1, rhinoClassLoader); } catch (JavaScriptException e) { // exception from JavaScript (possibly wrapping a Java Ex) if (e.getValue() instanceof Exception) { @@ -355,16 +346,61 @@ try { if (name.equals(BIND_NAME_WINDOW) && object instanceof Window) { - ((WindowWrapper)globalObject).window = (Window)object; + window = (Window)object; } else { - Scriptable jsObject = Context.toObject(object, globalObject); - globalObject.put(name, globalObject, jsObject); + try { + Scriptable jsObject; + jsObject = Context.toObject(object, globalObject); + objects.put(name, jsObject); + if (ScriptableObject.getProperty(globalObject, name) == + ScriptableObject.NOT_FOUND) + globalObject.defineProperty + (name, new RhinoGetDelegate(name), + rhinoGetter, null, ScriptableObject.READONLY); + } catch (PropertyException pe) { + pe.printStackTrace(); + } } } finally { Context.exit(); } } + /** + * HashTable to store properties bounds on the global object. + * So they don't end up in the JavaMethods static table. + */ + Map objects = new HashMap(4); + + /** + * Class to act as 'get' delegate for Rhino. This uses the + * currentContext to get the current Interpreter object which + * allows it to lookup the object requested. This gets around the + * fact that the global object gets referenced from a static + * context but the Context does not. + */ + public static class RhinoGetDelegate { + String name; + RhinoGetDelegate(String name) { + this.name = name; + } + public Object get(ScriptableObject so) { + Context ctx = Context.getCurrentContext(); + if (ctx == null ) return null; + return ((ExtendedContext)ctx).getInterpreter().objects.get(name); + } + } + // The method to use for getting the value from the + // RhinoGetDelegate. + static Method rhinoGetter; + static { + try { + Class [] getterArgs = { ScriptableObject.class }; + rhinoGetter = RhinoGetDelegate.class.getDeclaredMethod + ("get", getterArgs); + } catch (NoSuchMethodException nsm) { } + } + /** * To be used by <code>EventTargetWrapper</code>. @@ -440,7 +476,7 @@ * Build the wrapper for objects implement <code>EventTarget</code>. */ Scriptable buildEventTargetWrapper(EventTarget obj) { - return new EventTargetWrapper(globalObject, obj, this); + return new EventTargetWrapper(globalObject, obj); } /** @@ -485,5 +521,23 @@ */ public String formatMessage(String key, Object[] args) { return null; + } + + public class ExtendedContext extends Context { + public ExtendedContext() { + super(); + } + + public RhinoInterpreter getInterpreter() { + return RhinoInterpreter.this; + } + + public Window getWindow() { + return RhinoInterpreter.this.getWindow(); + } + + public ScriptableObject getGlobalObject() { + return RhinoInterpreter.this.getGlobalObject(); + } } } 1.15 +48 -66 xml-batik/sources/org/apache/batik/script/rhino/WindowWrapper.java Index: WindowWrapper.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/script/rhino/WindowWrapper.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- WindowWrapper.java 1 Jul 2003 12:09:11 -0000 1.14 +++ WindowWrapper.java 9 Jul 2003 02:10:11 -0000 1.15 @@ -41,16 +41,6 @@ private final static Object[] EMPTY_ARGUMENTS = new Object[0]; /** - * The rhino interpreter. - */ - protected RhinoInterpreter interpreter; - - /** - * The wrapped window. - */ - protected Window window; - - /** * Creates a new WindowWrapper. */ public WindowWrapper(Context context) { @@ -82,8 +72,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len < 2) { throw Context.reportRuntimeError("invalid argument count"); } @@ -110,8 +99,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len < 2) { throw Context.reportRuntimeError("invalid argument count"); } @@ -138,8 +126,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len >= 1) { window.clearInterval(Context.toType(args[0], Object.class)); } @@ -154,8 +141,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len >= 1) { window.clearTimeout(Context.toType(args[0], Object.class)); } @@ -170,8 +156,8 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - final Window window = ww.window; + final Window window = + ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len < 2) { throw Context.reportRuntimeError("invalid argument count"); } @@ -197,8 +183,8 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - final Window window = ww.window; + final Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); + final ScriptableObject go = ((RhinoInterpreter.ExtendedContext)cx).getGlobalObject(); if (len < 2) { throw Context.reportRuntimeError("invalid argument count"); } @@ -207,9 +193,11 @@ final String uri = (String)Context.toType(args[0], String.class); Window.GetURLHandler urlHandler = null; if (args[1] instanceof Function) { - urlHandler = new GetURLFunctionWrapper(interp, (Function)args[1], ww); + urlHandler = new GetURLFunctionWrapper + (interp, (Function)args[1], go); } else { - urlHandler = new GetURLObjectWrapper(interp, (NativeObject)args[1], ww); + urlHandler = new GetURLObjectWrapper + (interp, (NativeObject)args[1], go); } final Window.GetURLHandler fw = urlHandler; @@ -244,8 +232,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len >= 1) { String message = (String)Context.toType(args[0], String.class); @@ -262,8 +249,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); if (len >= 1) { String message = (String)Context.toType(args[0], String.class); @@ -281,8 +267,7 @@ Function funObj) throws JavaScriptException { int len = args.length; - WindowWrapper ww = (WindowWrapper)thisObj; - Window window = ww.window; + Window window = ((RhinoInterpreter.ExtendedContext)cx).getWindow(); switch (len) { case 0: return ""; @@ -361,18 +346,18 @@ protected Function function; /** - * The WindowWrapper. + * The Scope for callback */ - protected WindowWrapper windowWrapper; + protected ScriptableObject scope; /** * Creates a wrapper. */ public GetURLFunctionWrapper(RhinoInterpreter ri, Function fct, - WindowWrapper ww) { + ScriptableObject sc) { interpreter = ri; function = fct; - windowWrapper = ww; + scope = sc; } /** @@ -398,13 +383,11 @@ Boolean.TRUE : Boolean.FALSE); if (mime != null) { so.put("contentType", so, - Context.toObject(mime, - windowWrapper)); + Context.toObject(mime, scope)); } if (content != null) { so.put("content", so, - Context.toObject(content, - windowWrapper)); + Context.toObject(content, scope)); } arguments[0] = so; return arguments; @@ -438,9 +421,9 @@ private ScriptableObject object; /** - * The WindowWrapper. + * The Scope for the callback. */ - private WindowWrapper windowWrapper; + private ScriptableObject scope; private Object[] array = new Object[1]; private static final String COMPLETE = "operationComplete"; @@ -450,10 +433,10 @@ */ public GetURLObjectWrapper(RhinoInterpreter ri, ScriptableObject obj, - WindowWrapper ww) { + ScriptableObject sc) { interpreter = ri; object = obj; - windowWrapper = ww; + scope = sc; } /** @@ -466,29 +449,28 @@ final String mime, final String content) { try { - interpreter.callMethod(object, COMPLETE, - new RhinoInterpreter.ArgumentsBuilder() { - public Object[] buildArguments() { - Object[] arguments = new Object[1]; - ScriptableObject so = - new NativeObject(); - so.put("success", so, - (success) ? - Boolean.TRUE : Boolean.FALSE); - if (mime != null) { - so.put("contentType", so, - Context.toObject(mime, - windowWrapper)); - } - if (content != null) { - so.put("content", so, - Context.toObject(content, - windowWrapper)); - } - arguments[0] = so; - return arguments; - } - }); + interpreter.callMethod + (object, COMPLETE, + new RhinoInterpreter.ArgumentsBuilder() { + public Object[] buildArguments() { + Object[] arguments = new Object[1]; + ScriptableObject so = + new NativeObject(); + so.put("success", so, + (success) ? + Boolean.TRUE : Boolean.FALSE); + if (mime != null) { + so.put("contentType", so, + Context.toObject(mime, scope)); + } + if (content != null) { + so.put("content", so, + Context.toObject(content, scope)); + } + arguments[0] = so; + return arguments; + } + }); } catch (JavaScriptException e) { Context.exit(); throw new WrappedException(e); 1.35 +2 -1 xml-batik/sources/org/apache/batik/swing/gvt/JGVTComponent.java Index: JGVTComponent.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/gvt/JGVTComponent.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- JGVTComponent.java 8 Jul 2003 00:16:57 -0000 1.34 +++ JGVTComponent.java 9 Jul 2003 02:10:11 -0000 1.35 @@ -633,6 +633,7 @@ if (eventDispatcher != null) { eventDispatcher.setRootNode(null); } + gvtTreeRenderer.start(); } 1.73 +4 -3 xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java Index: JSVGComponent.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v retrieving revision 1.72 retrieving revision 1.73 diff -u -r1.72 -r1.73 --- JSVGComponent.java 8 Jul 2003 00:16:57 -0000 1.72 +++ JSVGComponent.java 9 Jul 2003 02:10:11 -0000 1.73 @@ -490,8 +490,6 @@ * interface. */ public void setSVGDocument(SVGDocument doc) { - stopProcessing(); - if ((doc != null) && !(doc.getImplementation() instanceof SVGDOMImplementation)) { DOMImplementation impl; @@ -501,6 +499,8 @@ } if (updateManager == null) { + stopProcessing(); + // No update manager just install new document. installSVGDocument(doc); } else { @@ -529,6 +529,7 @@ public void updateCompleted(UpdateManagerEvent e) { } public void updateFailed(UpdateManagerEvent e) { } }); + stopProcessing(); } } 1.9 +17 -4 xml-batik/sources/org/apache/batik/transcoder/SVGAbstractTranscoder.java Index: SVGAbstractTranscoder.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/transcoder/SVGAbstractTranscoder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SVGAbstractTranscoder.java 11 Jun 2003 22:07:28 -0000 1.8 +++ SVGAbstractTranscoder.java 9 Jul 2003 02:10:11 -0000 1.9 @@ -12,6 +12,8 @@ import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; +import java.net.URL; +import java.net.MalformedURLException; import java.util.StringTokenizer; import java.util.Vector; @@ -28,8 +30,10 @@ import org.apache.batik.bridge.ViewBox; import org.apache.batik.dom.svg.ExtensibleSVGDOMImplementation; import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.dom.svg.SVGOMDocument; import org.apache.batik.dom.util.DocumentFactory; +import org.apache.batik.dom.util.DOMUtilities; import org.apache.batik.gvt.CanvasGraphicsNode; import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.gvt.GraphicsNode; @@ -150,9 +154,18 @@ TranscoderOutput output) throws TranscoderException { - if (!(document instanceof SVGOMDocument)) { - throw new TranscoderException( - Messages.formatMessage("notsvg", null)); + if ((document != null) && + !(document.getImplementation() instanceof SVGDOMImplementation)) { + DOMImplementation impl; + impl = SVGDOMImplementation.getDOMImplementation(); + document = DOMUtilities.deepCloneDocument(document, impl); + if (uri != null) { + try { + URL url = new URL(uri); + ((SVGOMDocument)document).setURLObject(url); + } catch (MalformedURLException mue) { + } + } } ctx = new BridgeContext(userAgent); 1.1 xml-batik/test-references/samples/tests/spec/scripting/setProperty.png <<Binary file>> 1.2 +60 -87 xml-batik/test-references/samples/tests/spec/text/textOnPath2.png <<Binary file>> 1.2 +123 -125 xml-batik/test-references/samples/tests/spec/text/textOnPath3.png <<Binary file>> 1.1 xml-batik/test-references/samples/tests/spec/text/textDecoration2.png <<Binary file>> 1.3 +2 -2 xml-batik/test-resources/org/apache/batik/test/interactiveSamples.xml Index: interactiveSamples.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/interactiveSamples.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- interactiveSamples.xml 8 Jul 2003 10:00:17 -0000 1.2 +++ interactiveSamples.xml 9 Jul 2003 02:10:12 -0000 1.3 @@ -36,7 +36,7 @@ <test id="samples/tests/spec/scripting/imageUpdate.svg" /> <test id="samples/tests/spec/scripting/markerUpdate.svg" /> <test id="samples/tests/spec/scripting/maskClipUpdate.svg" /> - <!-- <test id="samples/tests/spec/scripting/removeLast.svg" /> --> + <test id="samples/tests/spec/scripting/removeLast.svg" /> <test id="samples/tests/spec/scripting/svg.svg" /> <test id="samples/tests/spec/scripting/svg2.svg" /> <test id="samples/tests/spec/scripting/use.svg" /> 1.105 +3 -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.104 retrieving revision 1.105 diff -u -r1.104 -r1.105 --- samplesRendering.xml 8 Jul 2003 10:00:18 -0000 1.104 +++ samplesRendering.xml 9 Jul 2003 02:10:12 -0000 1.105 @@ -282,6 +282,7 @@ <test id="samples/tests/spec/text/textAnchor3.svg" /> <test id="samples/tests/spec/text/textBiDi.svg" /> <test id="samples/tests/spec/text/textDecoration.svg" /> + <test id="samples/tests/spec/text/textDecoration2.svg" /> <test id="samples/tests/spec/text/textEffect.svg" /> <test id="samples/tests/spec/text/textEffect2.svg" /> <test id="samples/tests/spec/text/textEffect3.svg" /> @@ -367,5 +368,6 @@ <test id="samples/tests/spec/scripting/boundsTransformChange.svg" /> <test id="samples/tests/spec/scripting/rootSizeChange.svg" /> <test id="samples/tests/spec/scripting/rectResizeOnClick.svg" /> + <test id="samples/tests/spec/scripting/setProperty.svg" /> </testGroup> </testSuite> 1.4 +6 -1 xml-batik/test-resources/org/apache/batik/transcoder/image/unitTesting.xml Index: unitTesting.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/transcoder/image/unitTesting.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- unitTesting.xml 18 Sep 2002 09:23:12 -0000 1.3 +++ unitTesting.xml 9 Jul 2003 02:10:12 -0000 1.4 @@ -27,6 +27,11 @@ <arg class="java.lang.String" value="test-references/samples/anne.png" /> </test> +<test id="transcoder.image.genericdocument" class="org.apache.batik.transcoder.image.GenericDocumentTest" > + <arg class="java.lang.String" value="samples/anne.svg" /> + <arg class="java.lang.String" value="test-references/samples/anne.png" /> +</test> + <test id="transcoder.image.reader" class="org.apache.batik.transcoder.image.ReaderTest" > <arg class="java.lang.String" value="samples/anne.svg" /> <arg class="java.lang.String" value="test-references/samples/anne.png" /> 1.3 +4 -2 xml-batik/test-sources/org/apache/batik/swing/JSVGCanvasHandler.java Index: JSVGCanvasHandler.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/swing/JSVGCanvasHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JSVGCanvasHandler.java 8 Jul 2003 00:16:58 -0000 1.2 +++ JSVGCanvasHandler.java 9 Jul 2003 02:10:12 -0000 1.3 @@ -118,13 +118,15 @@ public JFrame getFrame() { return frame; } public JSVGCanvas getCanvas() { return canvas; } + public JSVGCanvas createCanvas() { return new JSVGCanvas(); } + public void runCanvas(String desc) { this.desc = desc; try { EventQueue.invokeAndWait(new Runnable() { public void run() { frame = new JFrame(delegate.getName()); - canvas = new JSVGCanvas(); + canvas = createCanvas(); frame.getContentPane().add(canvas); frame.setSize(new Dimension(450, 500)); wl = new WindowAdapter() { 1.3 +6 -2 xml-batik/test-sources/org/apache/batik/swing/JSVGMemoryLeakTest.java Index: JSVGMemoryLeakTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/swing/JSVGMemoryLeakTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JSVGMemoryLeakTest.java 8 Jul 2003 00:16:58 -0000 1.2 +++ JSVGMemoryLeakTest.java 9 Jul 2003 02:10:12 -0000 1.3 @@ -50,8 +50,12 @@ return TestMessages.formatMessage(key, args); } + public JSVGCanvasHandler createHandler() { + return new JSVGCanvasHandler(this, this); + } + public TestReport doSomething() throws Exception { - handler = new JSVGCanvasHandler(this, this); + handler = createHandler(); registerObjectDesc(handler, "Handler"); done = false; handler.runCanvas(getId()); 1.2 +22 -4 xml-batik/test-sources/org/apache/batik/swing/NullSetSVGDocumentTest.java Index: NullSetSVGDocumentTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/swing/NullSetSVGDocumentTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NullSetSVGDocumentTest.java 8 Jul 2003 00:16:58 -0000 1.1 +++ NullSetSVGDocumentTest.java 9 Jul 2003 02:10:12 -0000 1.2 @@ -21,6 +21,7 @@ import org.w3c.dom.Document; import org.w3c.dom.DOMImplementation; import org.w3c.dom.Element; +import org.w3c.dom.svg.SVGDocument; /** * Test setDocument on JSVGComponent with non-Batik SVGOMDocument. @@ -54,6 +55,20 @@ public static final String ERROR_ON_SET = "NullSetSVGDocumentTest.message.error.on.set"; + public JSVGCanvasHandler createHandler() { + return new JSVGCanvasHandler(this, this) { + public JSVGCanvas createCanvas() { + return new JSVGCanvas() { + protected void installSVGDocument(SVGDocument doc){ + super.installSVGDocument(doc); + if (doc != null) return; + handler.scriptDone(); + } + }; + } + }; + } + /* JSVGCanvasHandler.Delegate Interface */ public boolean canvasInit(JSVGCanvas canvas) { theCanvas = canvas; @@ -76,6 +91,7 @@ c.setSVGDocument(null); }}); } catch (Throwable t) { + t.printStackTrace(); StringWriter trace = new StringWriter(); t.printStackTrace(new PrintWriter(trace)); DefaultTestReport report = new DefaultTestReport(this); @@ -88,8 +104,6 @@ report.setPassed(false); failReport = report; } - // Check that the original SVG Document and GVT tree are cleared. - checkObjects(new String[] { "SVGDoc", "GVT", "updateManager" }); } public boolean canvasUpdated(JSVGCanvas canvas) { @@ -99,9 +113,13 @@ public void canvasDone(JSVGCanvas canvas) { synchronized (this) { + // Check that the original SVG + // Document and GVT tree are cleared. + checkObjects(new String[] { "SVGDoc", "GVT", "updateManager" }); + if (canvas.getOffScreen() == null) return; - + System.err.println(">>>>>>> Canvas not cleared"); DefaultTestReport report = new DefaultTestReport(this); report.setErrorCode(ERROR_IMAGE_NOT_CLEARED); // It would be great to provide the image here 1.4 +2 -1 xml-batik/test-sources/org/apache/batik/test/MemoryLeakTest.java Index: MemoryLeakTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/MemoryLeakTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- MemoryLeakTest.java 8 Jul 2003 00:16:58 -0000 1.3 +++ MemoryLeakTest.java 9 Jul 2003 02:10:12 -0000 1.4 @@ -85,6 +85,7 @@ } } if (passed) return true; + Thread.yield(); } StringBuffer sb = new StringBuffer(); 1.2 +62 -36 xml-batik/test-sources/org/apache/batik/transcoder/TranscoderInputTest.java Index: TranscoderInputTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/transcoder/TranscoderInputTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TranscoderInputTest.java 8 Jul 2003 08:57:16 -0000 1.1 +++ TranscoderInputTest.java 9 Jul 2003 02:10:12 -0000 1.2 @@ -27,11 +27,14 @@ import org.w3c.dom.Document; +import org.w3c.dom.DOMImplementation; -import org.apache.batik.dom.svg.SAXSVGDocumentFactory; -import org.apache.batik.util.XMLResourceDescriptor; +import org.apache.batik.dom.GenericDOMImplementation; import org.apache.batik.dom.svg.ExtensibleSVGDOMImplementation; +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; +import org.apache.batik.dom.util.SAXDocumentFactory; import org.apache.batik.util.SVGConstants; +import org.apache.batik.util.XMLResourceDescriptor; /** * This test validates that the various configurations of TranscoderInput @@ -49,46 +52,69 @@ TranscoderOutput out = new TranscoderOutput(new StringWriter()); // XMLReader - XMLReader xmlReader = XMLReaderFactory.createXMLReader(); - TranscoderInput ti = new TranscoderInput(xmlReader); - ti.setURI(TEST_URI); - t.transcode(ti, out); - assertTrue(t.passed); + { + XMLReader xmlReader = XMLReaderFactory.createXMLReader(); + TranscoderInput ti = new TranscoderInput(xmlReader); + ti.setURI(TEST_URI); + t.transcode(ti, out); + assertTrue(t.passed); + } // Input Stream - URL uri = new URL(TEST_URI); - InputStream is = uri.openStream(); - ti = new TranscoderInput(is); - ti.setURI(TEST_URI); - t = new TestTranscoder(); - t.transcode(ti, out); - assertTrue(t.passed); + { + URL uri = new URL(TEST_URI); + InputStream is = uri.openStream(); + TranscoderInput ti = new TranscoderInput(is); + ti.setURI(TEST_URI); + t = new TestTranscoder(); + t.transcode(ti, out); + assertTrue(t.passed); + } // Reader - uri = new URL(TEST_URI); - is = uri.openStream(); - Reader r = new InputStreamReader(is); - ti = new TranscoderInput(r); - ti.setURI(TEST_URI); - t = new TestTranscoder(); - t.transcode(ti, out); - assertTrue(t.passed); - + { + URL uri = new URL(TEST_URI); + InputStream is = uri.openStream(); + Reader r = new InputStreamReader(is); + TranscoderInput ti = new TranscoderInput(r); + ti.setURI(TEST_URI); + t = new TestTranscoder(); + t.transcode(ti, out); + assertTrue(t.passed); + } // Document - String parser = XMLResourceDescriptor.getXMLParserClassName(); - SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); - Document doc = f.createDocument(TEST_URI); - ti = new TranscoderInput(doc); - ti.setURI(TEST_URI); - t = new TestTranscoder(); - t.transcode(ti, out); - assertTrue(t.passed); + { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser); + Document doc = f.createDocument(TEST_URI); + TranscoderInput ti = new TranscoderInput(doc); + ti.setURI(TEST_URI); + t = new TestTranscoder(); + t.transcode(ti, out); + assertTrue(t.passed); + } + + // Generic Document + { + String parser = XMLResourceDescriptor.getXMLParserClassName(); + DOMImplementation impl = + GenericDOMImplementation.getDOMImplementation(); + SAXDocumentFactory f = new SAXDocumentFactory(impl, parser); + Document doc = f.createDocument(TEST_URI); + TranscoderInput ti = new TranscoderInput(doc); + ti.setURI(TEST_URI); + t = new TestTranscoder(); + t.transcode(ti, out); + assertTrue(t.passed); + } // URI only - ti = new TranscoderInput(TEST_URI); - t = new TestTranscoder(); - t.transcode(ti, out); - assertTrue(t.passed); + { + TranscoderInput ti = new TranscoderInput(TEST_URI); + t = new TestTranscoder(); + t.transcode(ti, out); + assertTrue(t.passed); + } return reportSuccess(); } 1.1 xml-batik/test-sources/org/apache/batik/transcoder/image/GenericDocumentTest.java Index: GenericDocumentTest.java =================================================================== /***************************************************************************** * 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. * *****************************************************************************/ package org.apache.batik.transcoder.image; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.w3c.dom.Document; import org.w3c.dom.DOMImplementation; import org.apache.batik.dom.GenericDOMImplementation; import org.apache.batik.dom.util.SAXDocumentFactory; import org.apache.batik.util.XMLResourceDescriptor; /** * Test the ImageTranscoder input with a GenericDocument. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @version $Id: GenericDocumentTest.java,v 1.1 2003/07/09 02:10:12 deweese Exp $ */ public class GenericDocumentTest extends AbstractImageTranscoderTest { /** The URI of the input image. */ protected String inputURI; /** The URI of the reference image. */ protected String refImageURI; /** * Constructs a new <tt>GenericDocumentTest</tt>. * * @param inputURI the URI of the input image * @param the URI of the reference image */ public GenericDocumentTest(String inputURI, String refImageURI) { this.inputURI = inputURI; this.refImageURI = refImageURI; } /** * Creates the <tt>TranscoderInput</tt>. */ protected TranscoderInput createTranscoderInput() { try { URL url = resolveURL(inputURI); String parser = XMLResourceDescriptor.getXMLParserClassName(); DOMImplementation impl = GenericDOMImplementation.getDOMImplementation(); SAXDocumentFactory f = new SAXDocumentFactory(impl, parser); Document doc = f.createDocument(url.toString()); TranscoderInput input = new TranscoderInput(doc); input.setURI(url.toString()); // Needed for external resources return input; } catch (IOException ex) { ex.printStackTrace(); throw new IllegalArgumentException(inputURI); } } /** * Returns the reference image for this test. */ protected byte [] getReferenceImageData() { return createBufferedImageData(resolveURL(refImageURI)); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]