deweese 2003/07/04 17:15:08 Modified: . build.xml sources/org/apache/batik/gvt/text GlyphLayout.java sources/org/apache/batik/script/rhino RhinoInterpreter.java test-references/samples/tests/spec/scripting boundsTransformChange.png rectResizeOnClick.png rootSizeChange.png test-resources/org/apache/batik/swing unitTesting.xml test-resources/org/apache/batik/test/svg/resources Messages.properties test-sources/org/apache/batik/test MemoryLeakTest.java test-sources/org/apache/batik/test/svg JSVGRenderingAccuracyTest.java Added: samples/tests/spec/scripting memoryLeak1.svg test-resources/org/apache/batik/swing/resources TestMessages.properties test-sources/org/apache/batik/swing JSVGCanvasHandler.java JSVGMemoryLeakTest.java TestMessages.java Removed: sources/org/apache/batik/bridge RepaintRateManager.java Log: 1) Fixed the handling of kerning attribute. 2) Fixed a serious memory leak with Rhino Interpreter 3) Added a new baseclass for MemoryLeak testing with JSVGCanvas. 4) Reworked JSVGRenderingAccuracyTest so that the JSVGCanvas handling code can be reused for JSVGMemoryLeakTests. 5) Removed RepaintRateManager (it's no longer used for anything). Revision Changes Path 1.131 +2 -1 xml-batik/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/xml-batik/build.xml,v retrieving revision 1.130 retrieving revision 1.131 diff -u -r1.130 -r1.131 --- build.xml 1 Jul 2003 09:43:09 -0000 1.130 +++ build.xml 5 Jul 2003 00:15:07 -0000 1.131 @@ -1074,6 +1074,7 @@ description="Runs test suite whose file or uri is passed as an input"> <java fork="yes" classname="${class-prefix}.test.xml.XMLTestSuiteRunner"> +<!-- <jvmarg value="-Xrunhprof:format=b" /> --> <classpath> <pathelement location="${dest}" /> <path refid="libs-classpath"/> 1.1 xml-batik/samples/tests/spec/scripting/memoryLeak1.svg Index: memoryLeak1.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. --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- Modification of text children --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: memoryLeak1.svg,v 1.1 2003/07/05 00:15:07 deweese Exp $ --> <!-- ====================================================================== --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg id="body" width="450" height="500" viewBox="0 0 450 500"> <title><text> children 'onload'</title> <text x="50%" y="45" class="title"><text> children in 'onload'</text> <script type="text/ecmascript"><![CDATA[ var inRegard=false; function regardStart() { inRegard=true; var elem = document.getElementById("t1"); regardTestInstance.registerObjectDesc(elem, "T1"); elem.parentNode.removeChild(elem); regardTestInstance.scriptDone(); } ]]></script> <g id="test-content"> <g style="font-size:40" > <text id="t1_bg" x="70" y="135" style="fill:gold">The good the bad</text> <text id="t1" x="70" y="135" style="fill:crimson">The good the bad</text> </g> </g> </svg> 1.53 +23 -27 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.52 retrieving revision 1.53 diff -u -r1.52 -r1.53 --- GlyphLayout.java 8 May 2003 11:39:13 -0000 1.52 +++ GlyphLayout.java 5 Jul 2003 00:15:07 -0000 1.53 @@ -1429,6 +1429,7 @@ float dy = 0f; Point2D newPositions[] = new Point2D[numGlyphs+1]; Point2D prevPos = gv.getGlyphPosition(0); + int prevCode = gv.getGlyphCode(0); float x = (float) prevPos.getX(); float y = (float) prevPos.getY(); @@ -1437,32 +1438,38 @@ advance.getY() - (gv.getGlyphPosition(numGlyphs-1).getY() - y)); try { + GVTFont font = gv.getFont(); // do letter spacing first if ((numGlyphs > 1) && (doLetterSpacing || !autoKern)) { for (int i=1; i<=numGlyphs; ++i) { Point2D gpos = gv.getGlyphPosition(i); + int currCode; + currCode = (i == numGlyphs)?-1:gv.getGlyphCode(i); dx = (float)gpos.getX()-(float)prevPos.getX(); dy = (float)gpos.getY()-(float)prevPos.getY(); if (autoKern) { if (vertical) dy += letterSpacingVal; - else dx += letterSpacingVal; + else dx += letterSpacingVal; } else { // apply explicit kerning adjustments, - // discarding any auto-kern dx values + // removing any auto-kern values if (vertical) { - dy = (float) - gv.getGlyphMetrics(i-1).getBounds2D().getHeight()+ - kernVal + letterSpacingVal; + float vKern = 0; + if (currCode != -1) + vKern = font.getVKern(prevCode, currCode); + dy += kernVal - vKern + letterSpacingVal; } else { - dx = (float) - gv.getGlyphMetrics(i-1).getBounds2D().getWidth()+ - kernVal + letterSpacingVal; + float hKern = 0; + if (currCode != -1) + hKern = font.getHKern(prevCode, currCode); + dx += kernVal - hKern + letterSpacingVal; } } x += dx; y += dy; newPositions[i] = new Point2D.Float(x, y); prevPos = gpos; + prevCode = currCode; } for (int i=1; i<=numGlyphs; ++i) { // assign the new positions @@ -1473,26 +1480,15 @@ } // adjust the advance of the last character - if (autoKern) { - if (vertical) { - lastCharAdvance.setLocation(lastCharAdvance.getX(), - lastCharAdvance.getY() + letterSpacingVal); - } else { - lastCharAdvance.setLocation(lastCharAdvance.getX() - + letterSpacingVal, lastCharAdvance.getY()); - } + if (vertical) { + lastCharAdvance.setLocation + (lastCharAdvance.getX(), + lastCharAdvance.getY() + kernVal + letterSpacingVal); } else { - if (vertical) { - lastCharAdvance.setLocation(lastCharAdvance.getX(), - gv.getGlyphMetrics(numGlyphs-2).getBounds2D().getHeight()+ - kernVal + letterSpacingVal); - } else { - lastCharAdvance.setLocation( - gv.getGlyphMetrics(numGlyphs-2).getBounds2D().getWidth()+ - kernVal + letterSpacingVal, lastCharAdvance.getY()); - } + lastCharAdvance.setLocation + (lastCharAdvance.getX() + kernVal + letterSpacingVal, + lastCharAdvance.getY()); } - // now do word spacing dx = 0f; 1.26 +2 -1 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.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- RhinoInterpreter.java 23 Apr 2003 13:07:52 -0000 1.25 +++ RhinoInterpreter.java 5 Jul 2003 00:15:07 -0000 1.26 @@ -174,6 +174,7 @@ if (!contexts.contains(ctx)) { ctx.setWrapFactory(wrapFactory); ctx.setSecurityController(securityController); + ctx.setCachingEnabled(false); contexts.add(ctx); // Hopefully, we are not switching threads too 1.3 +2 -4 xml-batik/test-references/samples/tests/spec/scripting/boundsTransformChange.png <<Binary file>> 1.3 +8 -15 xml-batik/test-references/samples/tests/spec/scripting/rectResizeOnClick.png <<Binary file>> 1.3 +1 -3 xml-batik/test-references/samples/tests/spec/scripting/rootSizeChange.png <<Binary file>> 1.3 +21 -13 xml-batik/test-resources/org/apache/batik/swing/unitTesting.xml Index: unitTesting.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/swing/unitTesting.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- unitTesting.xml 10 Jun 2002 12:11:13 -0000 1.2 +++ unitTesting.xml 5 Jul 2003 00:15:08 -0000 1.3 @@ -1,15 +1,23 @@ -<!-- ========================================================================= --> -<!-- 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. --> -<!-- ========================================================================= --> +<!-- ====================================================================== --> +<!-- 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. --> +<!-- ====================================================================== --> -<!-- ========================================================================= --> -<!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id$ --> -<!-- ========================================================================= --> -<testSuite id="swing.unitTesting" name="org.apache.batik.swing package - Unit Testing"> - <test id="NullURITest" class="org.apache.batik.swing.NullURITest" /> +<!-- ====================================================================== --> +<!-- @author [EMAIL PROTECTED] --> +<!-- @version $Id$ --> +<!-- ====================================================================== --> +<testSuite id="swing.unitTesting" + name="org.apache.batik.swing package - Unit Testing"> + <testGroup id="swing.memoryLeaks" + class="org.apache.batik.swing.JSVGMemoryLeakTest"> + <test id="samples/anne.svg" /> + <test id="samples/tests/spec/scripting/memoryLeak1.svg"/> + </testGroup> + + <test id="NullURITest" + class="org.apache.batik.swing.NullURITest" /> </testSuite> 1.1 xml-batik/test-resources/org/apache/batik/swing/resources/TestMessages.properties Index: TestMessages.properties =================================================================== ############################################################################# # 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. # ############################################################################# # # Keys in the generated TestReport Entries # JSVGCanvasHandler.entry.key.error.description = \ Error Description JSVGCanvasHandler.message.error.could.not.load.svg = \ Could not load SVG file: '{0}' JSVGCanvasHandler.message.error.svg.render.failed = \ Failed to render SVG file: '{0}' JSVGCanvasHandler.message.error.svg.update.failed = \ Failed to handle SVG update: '{0}' 1.6 +3 -9 xml-batik/test-resources/org/apache/batik/test/svg/resources/Messages.properties Index: Messages.properties =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/svg/resources/Messages.properties,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Messages.properties 3 Jul 2003 02:00:00 -0000 1.5 +++ Messages.properties 5 Jul 2003 00:15:08 -0000 1.6 @@ -9,6 +9,9 @@ # # Keys in the generated TestReport Entries # +JSVGCanvasHandler.entry.key.error.description = \ +Error Description + SVGRenderingAccuracyTest.entry.key.error.description = \ Error description @@ -76,15 +79,6 @@ SVGRenderingAccuracyTest.message.error.could.not.load.image = \ Could not load image {0} - -JSVGRenderingAccuracyTest.message.error.could.not.load.svg = \ -Could not load SVG file: '{0}' - -JSVGRenderingAccuracyTest.message.error.svg.render.failed = \ -Failed to render SVG file: '{0}' - -JSVGRenderingAccuracyTest.message.error.svg.update.failed = \ -Failed to handle SVG update: '{0}' JSVGRenderingAccuracyTest.message.error.save.failed = \ Save of new image failed: '{0}' \n\ 1.1 xml-batik/test-sources/org/apache/batik/swing/JSVGCanvasHandler.java Index: JSVGCanvasHandler.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.swing; import java.awt.Dimension; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import javax.swing.JFrame; import org.apache.batik.test.DefaultTestReport; import org.apache.batik.test.Test; import org.apache.batik.test.TestReport; import org.apache.batik.bridge.ScriptingEnvironment; import org.apache.batik.bridge.UpdateManager; import org.apache.batik.bridge.UpdateManagerEvent; import org.apache.batik.bridge.UpdateManagerListener; import org.apache.batik.script.Interpreter; import org.apache.batik.script.InterpreterException; import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; import org.apache.batik.swing.gvt.GVTTreeRendererEvent; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter; import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; /** * One line Class Desc * * Complete Class Desc * * @author <a href="mailto:[EMAIL PROTECTED]>l449433</a> * @version $Id: JSVGCanvasHandler.java,v 1.1 2003/07/05 00:15:08 deweese Exp $ */ public class JSVGCanvasHandler { public interface Delegate { public String getName(); public void canvasInit(JSVGCanvas canvas); public void canvasLoaded(JSVGCanvas canvas); public void canvasRendered(JSVGCanvas canvas); public boolean canvasUpdated(JSVGCanvas canvas); public void canvasDone(JSVGCanvas canvas); public void failure(TestReport report); } public static final String REGARD_TEST_INSTANCE = "regardTestInstance"; public static final String REGARD_START_SCRIPT = "try { regardStart(); } catch (er) {}"; /** * Error when canvas can't load SVG file. * {0} The file/url that could not be loaded. */ public static final String ERROR_CANNOT_LOAD_SVG = "JSVGCanvasHandler.message.error.could.not.load.svg"; /** * Error when canvas can't render SVG file. * {0} The file/url that could not be rendered. */ public static final String ERROR_SVG_RENDER_FAILED = "JSVGCanvasHandler.message.error.svg.render.failed"; /** * Error when canvas can't peform render update SVG file. * {0} The file/url that could not be updated.. */ public static final String ERROR_SVG_UPDATE_FAILED = "JSVGCanvasHandler.message.error.svg.update.failed"; /** * Entry describing the error */ public static final String ENTRY_KEY_ERROR_DESCRIPTION = "JSVGCanvasHandler.entry.key.error.description"; public static String fmt(String key, Object []args) { return TestMessages.formatMessage(key, args); } JFrame frame = null; JSVGCanvas canvas = null; UpdateManager updateManager = null; WindowListener wl = null; InitialRenderListener irl = null; LoadListener ll = null; UpdateRenderListener url = null; boolean renderFailed; boolean loadFailed; boolean abort; Object loadMonitor = new Object(); Object renderMonitor = new Object(); Delegate delegate; Test host; public JSVGCanvasHandler(Test host, Delegate delegate) { this.host = host; this.delegate = delegate; } public JFrame getFrame() { return frame; } public JSVGCanvas getCanvas() { return canvas; } public void runCanvas(String desc) { DefaultTestReport report = new DefaultTestReport(host); loadFailed = true; renderFailed = true; frame = new JFrame(delegate.getName()); canvas = new JSVGCanvas(); frame.getContentPane().add(canvas); frame.setSize(new Dimension(450, 500)); frame.setVisible(true); wl = new WindowAdapter() { public void windowClosing(WindowEvent e) { synchronized (loadMonitor) { abort = true; loadMonitor.notifyAll(); } synchronized (renderMonitor) { abort = true; renderMonitor.notifyAll(); } } }; frame.addWindowListener(wl); irl = new InitialRenderListener(); canvas.addGVTTreeRendererListener(irl); ll = new LoadListener(); canvas.addSVGDocumentLoaderListener(ll); try { delegate.canvasInit(canvas); synchronized (renderMonitor) { synchronized (loadMonitor) { try { loadMonitor.wait(); } catch(InterruptedException ie) { /* nothing */ } if (abort || loadFailed) { report.setErrorCode(ERROR_CANNOT_LOAD_SVG); report.setDescription(new TestReport.Entry[] { new TestReport.Entry (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), fmt(ERROR_CANNOT_LOAD_SVG, new Object[]{desc})) }); report.setPassed(false); delegate.failure(report); return; } delegate.canvasLoaded(canvas); } try { renderMonitor.wait(); } catch(InterruptedException ie) { /* nothing */ } if (abort || renderFailed) { report.setErrorCode(ERROR_SVG_RENDER_FAILED); report.setDescription(new TestReport.Entry[] { new TestReport.Entry (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), fmt(ERROR_SVG_RENDER_FAILED, new Object[]{desc})) }); report.setPassed(false); delegate.failure(report); return; } delegate.canvasRendered(canvas); updateManager = canvas.getUpdateManager(); if (updateManager != null) { url = new UpdateRenderListener(); updateManager.addUpdateManagerListener(url); updateManager.getUpdateRunnableQueue().invokeLater (new Runnable() { UpdateManager um = updateManager; public void run() { ScriptingEnvironment scriptEnv; scriptEnv = um.getScriptingEnvironment(); Interpreter interp; interp = scriptEnv.getInterpreter(); interp.bindObject(REGARD_TEST_INSTANCE, host); try { interp.evaluate(REGARD_START_SCRIPT); } catch (InterpreterException ie) { // Could not wait if no start script. } } }); boolean done = false; while (!done) { try { renderMonitor.wait(); } catch (InterruptedException ie) { /* nothing */ } if (abort || renderFailed) { report.setErrorCode(ERROR_SVG_UPDATE_FAILED); report.setDescription(new TestReport.Entry[] { new TestReport.Entry (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), fmt(ERROR_SVG_UPDATE_FAILED, new Object[]{desc})) }); report.setPassed(false); delegate.failure(report); return; } done = delegate.canvasUpdated(canvas); } } } } finally { delegate.canvasDone(canvas); dispose(); } } public void dispose() { if (frame != null) { frame.removeWindowListener(wl); frame.setVisible(false); } wl = null; if (canvas != null) { canvas.removeGVTTreeRendererListener(irl); irl=null; canvas.removeSVGDocumentLoaderListener(ll); ll=null; canvas.removeUpdateManagerListener(url); url=null; } updateManager = null; canvas = null; frame = null; } class UpdateRenderListener implements UpdateManagerListener { public void updateCompleted(UpdateManagerEvent e) { synchronized(renderMonitor){ renderFailed = false; renderMonitor.notifyAll(); } } public void updateFailed(UpdateManagerEvent e) { synchronized(renderMonitor){ renderFailed = true; renderMonitor.notifyAll(); } } public void managerStarted(UpdateManagerEvent e) { } public void managerSuspended(UpdateManagerEvent e) { } public void managerResumed(UpdateManagerEvent e) { } public void managerStopped(UpdateManagerEvent e) { } public void updateStarted(UpdateManagerEvent e) { } } class InitialRenderListener extends GVTTreeRendererAdapter { public void gvtRenderingCompleted(GVTTreeRendererEvent e) { synchronized(renderMonitor){ renderFailed = false; renderMonitor.notifyAll(); } } public void gvtRenderingCancelled(GVTTreeRendererEvent e) { synchronized(renderMonitor){ renderMonitor.notifyAll(); } } public void gvtRenderingFailed(GVTTreeRendererEvent e) { synchronized(renderMonitor){ renderMonitor.notifyAll(); } } } class LoadListener extends SVGDocumentLoaderAdapter { public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { synchronized(loadMonitor){ loadFailed = false; loadMonitor.notifyAll(); } } public void documentLoadingFailed(SVGDocumentLoaderEvent e) { synchronized(loadMonitor){ loadMonitor.notifyAll(); } } public void documentLoadingCancelled(SVGDocumentLoaderEvent e) { synchronized(loadMonitor){ loadMonitor.notifyAll(); } } } } 1.1 xml-batik/test-sources/org/apache/batik/swing/JSVGMemoryLeakTest.java Index: JSVGMemoryLeakTest.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.swing; import org.apache.batik.test.DefaultTestReport; import org.apache.batik.test.TestReport; import org.apache.batik.test.MemoryLeakTest; import javax.swing.SwingUtilities; import javax.swing.JFrame; import java.io.File; import java.net.MalformedURLException; /** * One line Class Desc * * Complete Class Desc * * @author <a href="mailto:[EMAIL PROTECTED]>l449433</a> * @version $Id: JSVGMemoryLeakTest.java,v 1.1 2003/07/05 00:15:08 deweese Exp $ */ public class JSVGMemoryLeakTest extends MemoryLeakTest implements JSVGCanvasHandler.Delegate { public JSVGMemoryLeakTest() { } public String getName() { return getId(); } TestReport failReport = null; boolean done; JSVGCanvasHandler handler; JFrame theFrame; JSVGCanvas theCanvas; public TestReport doSomething() throws Exception { handler = new JSVGCanvasHandler(this, this); registerObjectDesc(handler, "Handler"); done = false; handler.runCanvas(getId()); SwingUtilities.invokeAndWait( new Runnable() { public void run() { // System.out.println("In Invoke"); theCanvas.stopProcessing(); theFrame.remove(theCanvas); theFrame.removeNotify(); theCanvas.removeNotify(); theFrame=null; theCanvas=null; } }); { // Create a new Frame to take focus for Swing so old one // can be GC'd. javax.swing.JFrame jframe = new javax.swing.JFrame("FocusFrame"); // registerObjectDesc(jframe, "FocusFrame"); jframe.setSize(new java.awt.Dimension(40, 50)); jframe.setVisible(true); jframe.setVisible(false); jframe.removeNotify(); } handler = null; if (failReport != null) return failReport; DefaultTestReport report = new DefaultTestReport(this); report.setPassed(true); return report; } public void scriptDone() { synchronized (this) { done = true; // The canvasUpdate will notify the handler that the // canvas can be shut down. } } /* JSVGCanvasHandler.Delegate Interface */ public void canvasInit(JSVGCanvas canvas) { // System.err.println("In Init"); theCanvas = canvas; theFrame = handler.getFrame(); File f = new File(getId()); try { canvas.setURI(f.toURL().toString()); } catch (MalformedURLException mue) { } registerObjectDesc(canvas, "JSVGCanvas"); registerObjectDesc(handler.getFrame(), "JFrame"); } public void canvasLoaded(JSVGCanvas canvas) { // System.err.println("Loaded"); registerObjectDesc(canvas.getSVGDocument(), "SVG Document"); } public void canvasRendered(JSVGCanvas canvas) { // System.err.println("Rendered"); registerObjectDesc(canvas.getGraphicsNode(), "Graphics Node Tree"); registerObjectDesc(canvas.getUpdateManager(), "Update Manager"); } public boolean canvasUpdated(JSVGCanvas canvas) { // System.err.println("Updated"); synchronized (this) { return done; } } public void canvasDone(final JSVGCanvas canvas) { // System.err.println("Done"); } public void failure(TestReport report) { synchronized (this) { done = true; failReport = report; } } }; 1.1 xml-batik/test-sources/org/apache/batik/swing/TestMessages.java Index: TestMessages.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.swing; import java.util.Locale; import java.util.MissingResourceException; import org.apache.batik.i18n.Localizable; import org.apache.batik.i18n.LocalizableSupport; /** * This class manages the message for the test.svg module. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @version $Id: TestMessages.java,v 1.1 2003/07/05 00:15:08 deweese Exp $ */ public class TestMessages { /** * This class does not need to be instantiated. */ protected TestMessages() { } /** * The error messages bundle class name. */ protected final static String RESOURCES = "org.apache.batik.swing.resources.TestMessages"; /** * The localizable support for the error messages. */ protected static LocalizableSupport localizableSupport = new LocalizableSupport(RESOURCES); /** * Implements [EMAIL PROTECTED] org.apache.batik.i18n.Localizable#setLocale(Locale)}. */ public static void setLocale(Locale l) { localizableSupport.setLocale(l); } /** * Implements [EMAIL PROTECTED] org.apache.batik.i18n.Localizable#getLocale()}. */ public static Locale getLocale() { return localizableSupport.getLocale(); } /** * Implements [EMAIL PROTECTED] * org.apache.batik.i18n.Localizable#formatMessage(String,Object[])}. */ public static String formatMessage(String key, Object[] args) throws MissingResourceException { return localizableSupport.formatMessage(key, args); } } 1.2 +14 -5 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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MemoryLeakTest.java 3 Jul 2003 14:10:05 -0000 1.1 +++ MemoryLeakTest.java 5 Jul 2003 00:15:08 -0000 1.2 @@ -28,7 +28,11 @@ */ public abstract class MemoryLeakTest extends AbstractTest { - final static int NUM_GC=12; + // I know that 60 seems _really_ high but it turns out + // That the GraphicsNodeTree was not being cleared when I + // tested with as high as 36. So I would leave it at 60 + // (why so large I don't know). + final static int NUM_GC=60; final static String ERROR_OBJS_NOT_CLEARED = "MemoryLeakTest.message.error.objs.not.cleared"; @@ -61,8 +65,9 @@ if ((ret != null) && !ret.hasPassed()) return ret; - for (int i=0; i<NUM_GC; i++) + for (int i=0; i<NUM_GC; i++) { System.gc(); + } StringBuffer sb = new StringBuffer(); int count = 0; @@ -73,7 +78,7 @@ Object o = wr.get(); if (o == null) continue; if (count != 0) - sb.append(",\n"); + sb.append(","); sb.append(wr.getDesc()); count++; @@ -85,13 +90,17 @@ report.setPassed(true); return report; } + String objStr = sb.toString(); report.setErrorCode(ERROR_OBJS_NOT_CLEARED); report.setDescription(new TestReport.Entry[] { new TestReport.Entry (fmt(ERROR_DESCRIPTION, null), - fmt(ERROR_OBJS_NOT_CLEARED, new Object[]{sb.toString()})) + fmt(ERROR_OBJS_NOT_CLEARED, new Object[]{objStr})) }); + if (objStr.length() > 40) + objStr = objStr.substring(0,40) + "..." ; + System.err.print(">>>>> Objects not cleared: " + objStr + "\n"); report.setPassed(false); return report; } 1.2 +64 -263 xml-batik/test-sources/org/apache/batik/test/svg/JSVGRenderingAccuracyTest.java Index: JSVGRenderingAccuracyTest.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/svg/JSVGRenderingAccuracyTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JSVGRenderingAccuracyTest.java 3 Jul 2003 02:00:01 -0000 1.1 +++ JSVGRenderingAccuracyTest.java 5 Jul 2003 00:15:08 -0000 1.2 @@ -13,32 +13,16 @@ import java.io.StringWriter; import java.io.PrintWriter; import java.net.URL; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; - -import org.w3c.dom.Document; import org.apache.batik.test.DefaultTestReport; import org.apache.batik.test.TestReport; -import org.apache.batik.bridge.ScriptingEnvironment; -import org.apache.batik.bridge.UpdateManager; -import org.apache.batik.bridge.UpdateManagerEvent; -import org.apache.batik.bridge.UpdateManagerListener; -import org.apache.batik.script.Interpreter; -import org.apache.batik.script.InterpreterException; -import org.apache.batik.swing.gvt.GVTTreeRendererAdapter; -import org.apache.batik.swing.gvt.GVTTreeRendererEvent; +import org.apache.batik.swing.JSVGCanvasHandler; + import org.apache.batik.swing.JSVGCanvas; -import org.apache.batik.swing.svg.SVGDocumentLoaderAdapter; -import org.apache.batik.swing.svg.SVGDocumentLoaderEvent; -import java.awt.Dimension; import java.awt.image.BufferedImage; -import javax.swing.JFrame; - /** * One line Class Desc * @@ -47,32 +31,8 @@ * @author <a href="mailto:[EMAIL PROTECTED]>l449433</a> * @version $Id$ */ -public class JSVGRenderingAccuracyTest extends SamplesRenderingTest { - - public static final String REGARD_TEST_INSTANCE = "regardTestInstance"; - public static final String REGARD_START_SCRIPT = - "try { regardStart(); } catch (er) {}"; - - /** - * Error when canvas can't load SVG file. - * {0} The file/url that could not be loaded. - */ - public static final String ERROR_CANNOT_LOAD_SVG = - "JSVGRenderingAccuracyTest.message.error.could.not.load.svg"; - - /** - * Error when canvas can't render SVG file. - * {0} The file/url that could not be rendered. - */ - public static final String ERROR_SVG_RENDER_FAILED = - "JSVGRenderingAccuracyTest.message.error.svg.render.failed"; - - /** - * Error when canvas can't peform render update SVG file. - * {0} The file/url that could not be updated.. - */ - public static final String ERROR_SVG_UPDATE_FAILED = - "JSVGRenderingAccuracyTest.message.error.svg.update.failed"; +public class JSVGRenderingAccuracyTest extends SamplesRenderingTest + implements JSVGCanvasHandler.Delegate { /** * Error when canvas can't peform render update SVG file. @@ -91,250 +51,91 @@ public JSVGRenderingAccuracyTest(){ } - JFrame frame = null; - JSVGCanvas canvas = null; - UpdateManager updateManager = null; - BufferedImage theImage = null; - WindowListener wl = null; - - boolean renderFailed; - boolean loadFailed; + URL srcURL; + FileOutputStream fos; + TestReport failReport = null; boolean done; - boolean abort; - Object loadMonitor = new Object(); - Object renderMonitor = new Object(); public TestReport encode(URL srcURL, FileOutputStream fos) { + this.srcURL = srcURL; + this.fos = fos; + + JSVGCanvasHandler handler = new JSVGCanvasHandler(this, this); + done = false; + handler.runCanvas(srcURL.toString()); + + if (failReport != null) return failReport; + DefaultTestReport report = new DefaultTestReport(this); - loadFailed = true; - renderFailed = true; - - frame = new JFrame(getName()); - canvas = new JSVGCanvas(); - frame.getContentPane().add(canvas); - frame.setSize(new Dimension(450, 500)); - frame.setVisible(true); - wl = new WindowAdapter() { - public void windowClosing(WindowEvent e) { - synchronized (loadMonitor) { - abort = true; - loadMonitor.notifyAll(); - } - synchronized (renderMonitor) { - abort = true; - renderMonitor.notifyAll(); - } - } - }; - frame.addWindowListener(wl); - - canvas.addGVTTreeRendererListener - (new InitialRenderListener()); - canvas.addSVGDocumentLoaderListener - (new LoadListener()); - try { - - initCanvas(canvas, srcURL); - - synchronized (renderMonitor) { - synchronized (loadMonitor) { - try { loadMonitor.wait(); } - catch(InterruptedException ie) { /* nothing */ } - if (abort || loadFailed) { - report.setErrorCode(ERROR_CANNOT_LOAD_SVG); - report.setDescription(new TestReport.Entry[] { - new TestReport.Entry - (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), - fmt(ERROR_CANNOT_LOAD_SVG, - new Object[]{srcURL.toString()})) - }); - report.setPassed(false); - return report; - } - } - - try { renderMonitor.wait(); } - catch(InterruptedException ie) { /* nothing */ } - if (abort || renderFailed) { - report.setErrorCode(ERROR_SVG_RENDER_FAILED); - report.setDescription(new TestReport.Entry[] { - new TestReport.Entry - (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), - fmt(ERROR_SVG_RENDER_FAILED, - new Object[]{srcURL.toString()})) - }); - report.setPassed(false); - return report; - } - - updateManager = canvas.getUpdateManager(); - if (updateManager == null) { - // Not dynamic? Just use image.. - theImage = copyImage(canvas.getOffScreen()); - } else { - updateManager.addUpdateManagerListener - (new UpdateRenderListener()); - done = false; - updateManager.getUpdateRunnableQueue().invokeLater - (new Runnable() { - UpdateManager um = updateManager; - public void run() { - ScriptingEnvironment scriptEnv; - scriptEnv = um.getScriptingEnvironment(); - Interpreter interp; - interp = scriptEnv.getInterpreter(); - interp.bindObject(REGARD_TEST_INSTANCE, - JSVGRenderingAccuracyTest.this); - try { - interp.evaluate(REGARD_START_SCRIPT); - } catch (InterpreterException ie) { - // Could not wait if no start script. - } - } - }); - - while (theImage == null) { - try { renderMonitor.wait(); } - catch (InterruptedException ie) { /* nothing */ } - if (abort || renderFailed) { - report.setErrorCode(ERROR_SVG_UPDATE_FAILED); - report.setDescription(new TestReport.Entry[] { - new TestReport.Entry - (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), - fmt(ERROR_SVG_UPDATE_FAILED, - new Object[]{srcURL.toString()})) - }); - report.setPassed(false); - return report; - } - } - } - try { - saveImage(theImage, fos); - } catch (IOException ioe) { - StringWriter trace = new StringWriter(); - ioe.printStackTrace(new PrintWriter(trace)); - report.setErrorCode(ERROR_SAVE_FAILED); - report.setDescription(new TestReport.Entry[] { - new TestReport.Entry - (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), - fmt(ERROR_SAVE_FAILED, - new Object[]{ srcURL.toString(), - trace.toString()})) - }); - report.setPassed(false); - return report; - } - } - } finally { - dispose(); - } report.setPassed(true); return report; } - public void dispose() { - frame.removeWindowListener(wl); - wl = null; - if (frame != null) - frame.setVisible(false); - theImage = null; - updateManager = null; - canvas = null; - frame = null; - } - - /** - * Method subclasses can implement to do more sophisticated - * initialization of the canvas. - */ - protected void initCanvas(JSVGCanvas canvas, URL srcURL) { - canvas.setURI(srcURL.toString()); - } - public void scriptDone() { - synchronized (renderMonitor) { + synchronized (this) { done = true; - // Don't notify. The Update Complete will notify - and - // provide us with the 'up to date' image for comparison. + // The canvasUpdate will notify the handler that the + // canvas can be shut down. } } - public static BufferedImage copyImage(BufferedImage bi) { - // Copy off the image just rendered. - BufferedImage ret; - ret = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType()); - bi.copyData(ret.getRaster()); - return ret; + /* JSVGCanvasHandler.Delegate Interface */ + public void canvasInit(JSVGCanvas canvas) { + canvas.setURI(srcURL.toString()); } - class UpdateRenderListener implements UpdateManagerListener { - public void updateCompleted(UpdateManagerEvent e) { - synchronized(renderMonitor){ - renderFailed = false; - if (done) { - theImage = copyImage(e.getImage()); - } - renderMonitor.notifyAll(); - } - } - public void updateFailed(UpdateManagerEvent e) { - synchronized(renderMonitor){ - renderFailed = true; - renderMonitor.notifyAll(); - } - } - public void managerStarted(UpdateManagerEvent e) { } - public void managerSuspended(UpdateManagerEvent e) { } - public void managerResumed(UpdateManagerEvent e) { } - public void managerStopped(UpdateManagerEvent e) { } - public void updateStarted(UpdateManagerEvent e) { } + public void canvasLoaded(JSVGCanvas canvas) { } - class InitialRenderListener extends GVTTreeRendererAdapter { - public void gvtRenderingCompleted(GVTTreeRendererEvent e) { - synchronized(renderMonitor){ - renderFailed = false; - if (done) { - theImage = copyImage(e.getImage()); - } - renderMonitor.notifyAll(); - } - } - - - public void gvtRenderingCancelled(GVTTreeRendererEvent e) { - synchronized(renderMonitor){ - renderMonitor.notifyAll(); - } - } + public void canvasRendered(JSVGCanvas canvas) { + } - public void gvtRenderingFailed(GVTTreeRendererEvent e) { - synchronized(renderMonitor){ - renderMonitor.notifyAll(); - } + public boolean canvasUpdated(JSVGCanvas canvas) { + synchronized (this) { + return done; } } - class LoadListener extends SVGDocumentLoaderAdapter { - public void documentLoadingCompleted(SVGDocumentLoaderEvent e) { - synchronized(loadMonitor){ - loadFailed = false; - loadMonitor.notifyAll(); - } - } + public void canvasDone(JSVGCanvas canvas) { + synchronized (this) { + done = true; + if (failReport != null) + return; - public void documentLoadingFailed(SVGDocumentLoaderEvent e) { - synchronized(loadMonitor){ - loadMonitor.notifyAll(); + try { + BufferedImage theImage = copyImage(canvas.getOffScreen()); + saveImage(theImage, fos); + } catch (IOException ioe) { + StringWriter trace = new StringWriter(); + ioe.printStackTrace(new PrintWriter(trace)); + DefaultTestReport report = new DefaultTestReport(this); + report.setErrorCode(ERROR_SAVE_FAILED); + report.setDescription(new TestReport.Entry[] { + new TestReport.Entry + (fmt(ENTRY_KEY_ERROR_DESCRIPTION, null), + fmt(ERROR_SAVE_FAILED, + new Object[]{ srcURL.toString(), + trace.toString()})) + }); + report.setPassed(false); + failReport = report; } } + } - public void documentLoadingCancelled(SVGDocumentLoaderEvent e) { - synchronized(loadMonitor){ - loadMonitor.notifyAll(); - } + public void failure(TestReport report) { + synchronized (this) { + done = true; + failReport = report; } } + public static BufferedImage copyImage(BufferedImage bi) { + // Copy off the image just rendered. + BufferedImage ret; + ret = new BufferedImage(bi.getWidth(), bi.getHeight(), bi.getType()); + bi.copyData(ret.getRaster()); + return ret; + } }; +
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]