deweese 2003/02/24 10:25:54 Modified: sources/org/apache/batik/bridge AbstractGraphicsNodeBridge.java BridgeContext.java SVGSVGElementBridge.java SVGTextElementBridge.java UpdateManager.java UserAgent.java UserAgentAdapter.java UserAgentViewport.java sources/org/apache/batik/dom/svg SVGContext.java SVGLocatableSupport.java SVGOMSVGElement.java SVGTextContent.java sources/org/apache/batik/gvt AbstractGraphicsNode.java CanvasGraphicsNode.java sources/org/apache/batik/gvt/event AWTEventDispatcher.java sources/org/apache/batik/swing JSVGCanvas.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-resources/org/apache/batik/test samplesRendering.xml Added: samples/tests/spec/scripting currentScaleTranslate.svg sources/org/apache/batik/dom/svg SVGOMPoint.java SVGOMRect.java Log: 1) Implemented currentScale/Translate 2) Implemented getScreenCTM, fixed getCTM 3) 1&2 work with Transcoders as well (if -onload is given). 4) Fixed clientX/Y values in MouseEvents. 5) JSVGComponent no longer redraws/cancels/redraws for most cases Revision Changes Path 1.1 xml-batik/samples/tests/spec/scripting/currentScaleTranslate.svg Index: currentScaleTranslate.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. --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- append child test --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: currentScaleTranslate.svg,v 1.1 2003/02/24 18:25:52 deweese Exp $ --> <!-- ====================================================================== --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg id="body" width="450" height="500" viewBox="0 0 450 500" onload="setScaleTrans(2, 50, 50), update()" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <title>svg current scale/translate modification</title> <script type="text/ecmascript"><![CDATA[ var count = 1; function setScaleTrans(scale, newX, newY) { document.getRootElement().currentScale = scale; var pt = document.getRootElement().currentTranslate; pt.x = newX; pt.y = newX; } function update() { if ((count%10) == 0) { var scale = 1+((count/10)%10)/4; document.getRootElement().currentScale = scale; } var t; var mat; t = document.getElementById('cnt'); t.firstChild.data = ("Count: " + count); mat = t.getScreenCTM(); t = document.getElementById('foo'); t.firstChild.data = "The ScrnCTM is: (" + mat.a +","+ mat.b +","+ mat.c +","+ mat.d +","+ mat.e +","+ mat.f +")"; mat = t.getCTM(); t = document.getElementById('bar'); t.firstChild.data = "The CTM is: (" + mat.a +","+ mat.b +","+ mat.c +","+ mat.d +","+ mat.e +","+ mat.f +")"; var scale = document.getRootElement().currentScale; t = document.getElementById('baz'); t.firstChild.data = "The Scale is: "+scale; var trans = document.getRootElement().currentTranslate; t = document.getElementById('bat'); t.firstChild.data = "The Trans is ["+trans.x+", " +trans.y+"]"; t = document.getElementById('vp'); var vp = document.rootElement.viewport; t.firstChild.data = ("Viewport: ["+ vp.x+", " +vp.y+", " + vp.width+", " +vp.height+"]"); count++; setTimeout('update()', 1000); } function mouseOver(evt) { t = document.getElementById('rec'); var x = evt.getClientX(); var y = evt.getClientY(); mat = t.getScreenCTM(); imat = mat.inverse(); var pt = document.getRootElement().createSVGPoint(); pt.x = x; pt.y = y; pt = pt.matrixTransform(imat); t.firstChild.data = ("Loc: [" + evt.getClientX() + ", " + evt.getClientY() + "] [" + pt.x + ", " + pt.y + "]"); } ]]></script> <g id="test-content"> <rect x="0" y="0" width="450" height="500" fill="lightgrey" stroke="black" onmousemove="mouseOver(evt)"/> <text id="cnt" x="10" y=" 80">test</text> <text id="foo" x="10" y="100">test</text> <text id="bar" x="10" y="120">test</text> <text id="baz" x="10" y="140">test</text> <text id="bat" x="10" y="160">test</text> <text id="vp" x="10" y="180">test</text> <text id="rec" x="10" y="200">test</text> </g> </svg> 1.28 +34 -7 xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java Index: AbstractGraphicsNodeBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractGraphicsNodeBridge.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- AbstractGraphicsNodeBridge.java 12 Jun 2002 08:20:34 -0000 1.27 +++ AbstractGraphicsNodeBridge.java 24 Feb 2003 18:25:52 -0000 1.28 @@ -17,8 +17,11 @@ import org.apache.batik.dom.svg.SVGContext; import org.apache.batik.dom.svg.SVGOMElement; -import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.CompositeGraphicsNode; +import org.apache.batik.gvt.CanvasGraphicsNode; +import org.apache.batik.gvt.GraphicsNode; +import org.apache.batik.gvt.RootGraphicsNode; + import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -312,17 +315,41 @@ AffineTransform ctm = new AffineTransform(); Element elt = e; while (elt != null) { + if (elt instanceof SVGFitToViewBox) { + AffineTransform at; + if (gn instanceof CanvasGraphicsNode) { + at = ((CanvasGraphicsNode)gn).getViewingTransform(); + } else { + at = gn.getTransform(); + } + if (at != null) { + ctm.preConcatenate(at); + } + break; + } + AffineTransform at = gn.getTransform(); - if (at != null) { + if (at != null) ctm.preConcatenate(at); - } + elt = SVGCSSEngine.getParentCSSStylableElement(elt); gn = gn.getParent(); - if (elt instanceof SVGFitToViewBox) { - break; - } } return ctm; + } + + /** + * Returns the display transform. + */ + public AffineTransform getScreenTransform() { + return ctx.getUserAgent().getTransform(); + } + + /** + * Returns the display transform. + */ + public void setScreenTransform(AffineTransform at) { + ctx.getUserAgent().setTransform(at); } /** 1.56 +5 -1 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.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- BridgeContext.java 14 Nov 2002 19:44:49 -0000 1.55 +++ BridgeContext.java 24 Feb 2003 18:25:52 -0000 1.56 @@ -519,6 +519,10 @@ viewportStack.add(0, viewport); } + public void removeViewport(Element e) { + viewportMap.remove(e); + } + /** * Closes the viewport associated to the specified element. * @param e the element that closes its viewport 1.31 +25 -14 xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java Index: SVGSVGElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGSVGElementBridge.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- SVGSVGElementBridge.java 4 Jul 2002 07:19:02 -0000 1.30 +++ SVGSVGElementBridge.java 24 Feb 2003 18:25:52 -0000 1.31 @@ -70,7 +70,7 @@ return null; } - CanvasGraphicsNode gn = new CanvasGraphicsNode(); + CanvasGraphicsNode cgn = new CanvasGraphicsNode(); UnitProcessor.Context uctx = UnitProcessor.createContext(ctx, e); String s; @@ -111,28 +111,29 @@ (s, SVG_HEIGHT_ATTRIBUTE, uctx); // 'visibility' - gn.setVisible(CSSUtilities.convertVisibility(e)); + cgn.setVisible(CSSUtilities.convertVisibility(e)); // 'viewBox' and "preserveAspectRatio' attributes - AffineTransform at = + AffineTransform viewingTransform = ViewBox.getPreserveAspectRatioTransform(e, w, h); float actualWidth = w; float actualHeight = h; try { - AffineTransform atInv = at.createInverse(); - actualWidth = (float) (w*atInv.getScaleX()); - actualHeight = (float) (h*atInv.getScaleY()); + AffineTransform vtInv = viewingTransform.createInverse(); + actualWidth = (float) (w*vtInv.getScaleX()); + actualHeight = (float) (h*vtInv.getScaleY()); } catch (NoninvertibleTransformException ex) {} - at.preConcatenate(AffineTransform.getTranslateInstance(x, y)); - + AffineTransform positionTransform = + AffineTransform.getTranslateInstance(x, y); // 'overflow' and 'clip' // The outermost preserveAspectRatio matrix is set by the user // agent, so we don't need to set the transform for outermost svg Shape clip = null; if (!isOutermost) { - gn.setTransform(at); + cgn.setPositionTransform(positionTransform); + cgn.setViewingTransform(viewingTransform); } else { // <!> FIXME: hack to compute the original document's size if (ctx.getDocumentSize() == null) { @@ -158,24 +159,26 @@ if (clip != null) { try { + AffineTransform at = new AffineTransform(positionTransform); + at.concatenate(viewingTransform); at = at.createInverse(); // clip in user space clip = at.createTransformedShape(clip); - Filter filter = gn.getGraphicsNodeRable(true); - gn.setClip(new ClipRable8Bit(filter, clip)); + Filter filter = cgn.getGraphicsNodeRable(true); + cgn.setClip(new ClipRable8Bit(filter, clip)); } catch (NoninvertibleTransformException ex) {} } // 'enable-background' Rectangle2D r = CSSUtilities.convertEnableBackground(e); if (r != null) { - gn.setBackgroundEnable(r); + cgn.setBackgroundEnable(r); } ctx.openViewport (e, new SVGSVGElementViewport((SVGSVGElement)e, actualWidth, actualHeight)); - return gn; + return cgn; } /** @@ -199,6 +202,14 @@ } // BridgeUpdateHandler implementation ////////////////////////////////// + + /** + * Disposes this BridgeUpdateHandler and releases all resources. + */ + public void dispose() { + ctx.removeViewport(e); + super.dispose(); + } /** * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. 1.74 +19 -1 xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java Index: SVGTextElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGTextElementBridge.java,v retrieving revision 1.73 retrieving revision 1.74 diff -u -r1.73 -r1.74 --- SVGTextElementBridge.java 19 Feb 2003 02:50:56 -0000 1.73 +++ SVGTextElementBridge.java 24 Feb 2003 18:25:52 -0000 1.74 @@ -1901,6 +1901,24 @@ } /** + * Returns the transformation matrix from the userspace of + * the root element to the screen. + */ + public AffineTransform getScreenTransform() { + //return node.getScreenTransform(); + return null; + } + + /** + * Sets the transformation matrix to be used from the + * userspace of the root element to the screen. + */ + public void setScreenTransform(AffineTransform at) { + //return node.setScreenTransform(at); + return; + } + + /** * Returns the width of the viewport which directly contains the * given element. */ 1.19 +1 -2 xml-batik/sources/org/apache/batik/bridge/UpdateManager.java Index: UpdateManager.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UpdateManager.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- UpdateManager.java 25 Sep 2002 11:59:59 -0000 1.18 +++ UpdateManager.java 24 Feb 2003 18:25:52 -0000 1.19 @@ -150,7 +150,6 @@ throws InterruptedException { scriptingEnvironment.loadScripts(); scriptingEnvironment.dispatchSVGLoadEvent(); - } /** 1.25 +7 -1 xml-batik/sources/org/apache/batik/bridge/UserAgent.java Index: UserAgent.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UserAgent.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- UserAgent.java 5 Sep 2002 12:58:18 -0000 1.24 +++ UserAgent.java 24 Feb 2003 18:25:52 -0000 1.25 @@ -143,6 +143,12 @@ AffineTransform getTransform(); /** + * Sets the <code>AffineTransform</code> currently + * applied to the drawing by the UserAgent. + */ + void setTransform(AffineTransform at); + + /** * Returns this user agent's CSS media. */ String getMedia(); 1.12 +8 -1 xml-batik/sources/org/apache/batik/bridge/UserAgentAdapter.java Index: UserAgentAdapter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UserAgentAdapter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- UserAgentAdapter.java 5 Sep 2002 12:58:18 -0000 1.11 +++ UserAgentAdapter.java 24 Feb 2003 18:25:52 -0000 1.12 @@ -223,6 +223,13 @@ /** * Unsupported operation. */ + public void setTransform(AffineTransform at) { + // Do nothing. + } + + /** + * Unsupported operation. + */ public Point getClientAreaLocationOnScreen() { return new Point(); } 1.3 +5 -7 xml-batik/sources/org/apache/batik/bridge/UserAgentViewport.java Index: UserAgentViewport.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/UserAgentViewport.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- UserAgentViewport.java 8 Mar 2001 12:39:31 -0000 1.2 +++ UserAgentViewport.java 24 Feb 2003 18:25:52 -0000 1.3 @@ -16,29 +16,27 @@ */ public class UserAgentViewport implements Viewport { - private float width; - private float height; + private UserAgent userAgent; /** * Constructs a new viewport for the specified user agent. * @param userAgent the user agent that defines the viewport */ public UserAgentViewport(UserAgent userAgent) { - width = (float) userAgent.getViewportSize().getWidth(); - height = (float) userAgent.getViewportSize().getHeight(); + this.userAgent = userAgent; } /** * Returns the width of this viewport. */ public float getWidth() { - return width; + return (float) userAgent.getViewportSize().getWidth(); } /** * Returns the height of this viewport. */ public float getHeight() { - return height; + return (float) userAgent.getViewportSize().getHeight(); } } 1.10 +11 -1 xml-batik/sources/org/apache/batik/dom/svg/SVGContext.java Index: SVGContext.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGContext.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SVGContext.java 5 Jun 2002 21:14:48 -0000 1.9 +++ SVGContext.java 24 Feb 2003 18:25:53 -0000 1.10 @@ -40,6 +40,16 @@ Rectangle2D getBBox(); /** + * Returns the transform from the global transform space to pixels. + */ + AffineTransform getScreenTransform(); + + /** + * Sets the transform to be used from the global transform space to pixels. + */ + void setScreenTransform(AffineTransform at); + + /** * Returns the transformation matrix from current user units * (i.e., after application of the transform attribute, if any) to * the viewport coordinate system for the nearestViewportElement. 1.6 +12 -2 xml-batik/sources/org/apache/batik/dom/svg/SVGLocatableSupport.java Index: SVGLocatableSupport.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGLocatableSupport.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SVGLocatableSupport.java 24 Apr 2002 13:01:26 -0000 1.5 +++ SVGLocatableSupport.java 24 Feb 2003 18:25:53 -0000 1.6 @@ -118,7 +118,17 @@ * org.w3c.dom.svg.SVGLocatable#getScreenCTM()}. */ public static SVGMatrix getScreenCTM(Element elt) { - throw new RuntimeException(" !!! TODO: getScreenCTM()"); + final SVGOMElement svgelt = (SVGOMElement)elt; + return new AbstractSVGMatrix() { + protected AffineTransform getAffineTransform() { + SVGContext context = svgelt.getSVGContext(); + AffineTransform ret = context.getGlobalTransform(); + AffineTransform scrnTrans = context.getScreenTransform(); + if (scrnTrans != null) + ret.preConcatenate(scrnTrans); + return ret; + } + }; } /** 1.20 +77 -34 xml-batik/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java Index: SVGOMSVGElement.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGOMSVGElement.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- SVGOMSVGElement.java 14 Aug 2002 14:12:22 -0000 1.19 +++ SVGOMSVGElement.java 24 Feb 2003 18:25:53 -0000 1.20 @@ -8,6 +8,8 @@ package org.apache.batik.dom.svg; +import java.awt.geom.AffineTransform; + import org.apache.batik.dom.AbstractDocument; import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.dom.util.XMLSupport; @@ -178,8 +180,10 @@ * <b>DOM</b>: Implements [EMAIL PROTECTED] SVGSVGElement#getViewport()}. */ public SVGRect getViewport() { - throw new RuntimeException(" !!! TODO: getViewport()"); - } + SVGContext ctx = getSVGContext(); + return new SVGOMRect(0, 0, ctx.getViewportWidth(), + ctx.getViewportHeight()); + } public float getPixelUnitToMillimeterX( ) { throw new Error(); @@ -204,15 +208,72 @@ throw new Error(); } public float getCurrentScale( ) { - throw new Error(); - } - public void setCurrentScale( float currentScale ) - throws DOMException { - throw new Error(); + AffineTransform scrnTrans = getSVGContext().getScreenTransform(); + if (scrnTrans != null) + return (float)Math.sqrt(scrnTrans.getDeterminant()); + return 1; + } + public void setCurrentScale( float currentScale ) throws DOMException { + SVGContext context = getSVGContext(); + AffineTransform scrnTrans = context.getScreenTransform(); + float scale = 1; + if (scrnTrans != null) + scale = (float)Math.sqrt(scrnTrans.getDeterminant()); + float delta = currentScale/scale; + // The way currentScale, currentTranslate are defined + // changing scale has no effect on translate. + scrnTrans = new AffineTransform + (scrnTrans.getScaleX()*delta, scrnTrans.getShearY()*delta, + scrnTrans.getShearX()*delta, scrnTrans.getScaleY()*delta, + scrnTrans.getTranslateX(), scrnTrans.getTranslateY()); + context.setScreenTransform(scrnTrans); } + public SVGPoint getCurrentTranslate( ) { - throw new Error(); + final SVGOMElement svgelt = this; + return new SVGPoint() { + AffineTransform getScreenTransform() { + SVGContext context = svgelt.getSVGContext(); + return context.getScreenTransform(); + } + + public float getX() { + AffineTransform scrnTrans = getScreenTransform(); + return (float)scrnTrans.getTranslateX(); + } + public float getY() { + AffineTransform scrnTrans = getScreenTransform(); + return (float)scrnTrans.getTranslateY(); + } + public void setX(float newX) { + SVGContext context = svgelt.getSVGContext(); + AffineTransform scrnTrans = context.getScreenTransform(); + scrnTrans = new AffineTransform + (scrnTrans.getScaleX(), scrnTrans.getShearY(), + scrnTrans.getShearX(), scrnTrans.getScaleY(), + newX, scrnTrans.getTranslateY()); + context.setScreenTransform(scrnTrans); + } + public void setY(float newY) { + SVGContext context = svgelt.getSVGContext(); + AffineTransform scrnTrans = context.getScreenTransform(); + scrnTrans = new AffineTransform + (scrnTrans.getScaleX(), scrnTrans.getShearY(), + scrnTrans.getShearX(), scrnTrans.getScaleY(), + scrnTrans.getTranslateX(), newY); + context.setScreenTransform(scrnTrans); + } + public SVGPoint matrixTransform ( SVGMatrix mat ) { + AffineTransform scrnTrans = getScreenTransform(); + float x = (float)scrnTrans.getTranslateX(); + float y = (float)scrnTrans.getTranslateY(); + float newX = mat.getA()*x + mat.getC()*y + mat.getE(); + float newY = mat.getB()*x + mat.getD()*y + mat.getF(); + return new SVGOMPoint(newX, newY); + } + }; } + public int suspendRedraw ( int max_wait_milliseconds ) { throw new Error(); } @@ -290,32 +351,17 @@ * <b>DOM</b>: Implements [EMAIL PROTECTED] SVGSVGElement#createSVGPoint()}. */ public SVGPoint createSVGPoint() { - return new SVGPoint() { - float x; - float y; - public float getX() { - return x; - } - public void setX(float x) throws DOMException { - this.x = x; - } - public float getY() { - return y; - } - public void setY(float y) throws DOMException { - this.y = y; - } - public SVGPoint matrixTransform(SVGMatrix matrix) { - throw new RuntimeException("!!! TODO: matrixTransform()"); - } - }; + return new SVGOMPoint(0, 0); } public SVGMatrix createSVGMatrix ( ) { - throw new Error(); + return new AbstractSVGMatrix() { + AffineTransform at = new AffineTransform(); + protected AffineTransform getAffineTransform() { return at; } + }; } public SVGRect createSVGRect ( ) { - throw new Error(); + return new SVGOMRect(0,0,0,0); } public SVGTransform createSVGTransform ( ) { throw new Error(); @@ -323,11 +369,8 @@ public SVGTransform createSVGTransformFromMatrix ( SVGMatrix matrix ) { throw new Error(); } - public String createSVGString ( ) { - throw new Error(); - } public Element getElementById ( String elementId ) { - throw new Error(); + return ((SVGOMDocument)getDocument()).getElementById(elementId); } // SVGLocatable /////////////////////////////////////////////////////// 1.2 +1 -141 xml-batik/sources/org/apache/batik/dom/svg/SVGTextContent.java Index: SVGTextContent.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/dom/svg/SVGTextContent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SVGTextContent.java 19 Feb 2003 02:50:57 -0000 1.1 +++ SVGTextContent.java 24 Feb 2003 18:25:53 -0000 1.2 @@ -1,141 +1 @@ -/***************************************************************************** - * 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.dom.svg; - -import java.awt.geom.Rectangle2D; -import java.awt.geom.Point2D; - -import org.w3c.dom.DOMException; - -/** - * This class provides the interface for the SVGTextContentElement - * for the bridge to implement. - * - * @author [EMAIL PROTECTED] - * @version $Id$ - */ -public interface SVGTextContent -{ - /** - * Returns the total number of characters to be - * rendered within the current element. - * Includes characters which are included - * via a <tref> reference. - * - * @return Total number of characters. - */ - public int getNumberOfChars(); - - /** - * Returns a tightest rectangle which defines the - * minimum and maximum X and Y values in the user - * coordinate system for rendering the glyph(s) - * that correspond to the specified character. - * The calculations assume that all glyphs occupy - * the full standard glyph cell for the font. If - * multiple consecutive characters are rendered - * inseparably (e.g., as a single glyph or a - * sequence of glyphs), then each of the inseparable - * characters will return the same extent. - * - * @param charnum The index of the character, where the - * first character has an index of 0. - * @return The rectangle which encloses all of - * the rendered glyph(s). - */ - public Rectangle2D getExtentOfChar(int charnum ); - - /** - * Returns the current text position before rendering - * the character in the user coordinate system for - * rendering the glyph(s) that correspond to the - * specified character. The current text position has - * already taken into account the effects of any inter- - * character adjustments due to properties 'kerning', - * 'letter-spacing' and 'word-spacing' and adjustments - * due to attributes x, y, dx and dy. If multiple - * consecutive characters are rendered inseparably - * (e.g., as a single glyph or a sequence of glyphs), - * then each of the inseparable characters will return - * the start position for the first glyph. - * - * @param charnum The index of the character, where the - * first character has an index of 0. - * @return The character's start position. - */ - public Point2D getStartPositionOfChar(int charnum); - - /** - * Returns the current text position after rendering - * the character in the user coordinate system for - * rendering the glyph(s) that correspond to the - * specified character. This current text position - * does not take into account the effects of any inter- - * character adjustments to prepare for the next - * character, such as properties 'kerning', - * 'letter-spacing' and 'word-spacing' and adjustments - * due to attributes x, y, dx and dy. If multiple - * consecutive characters are rendered inseparably - * (e.g., as a single glyph or a sequence of glyphs), - * then each of the inseparable characters will return - * the end position for the last glyph. - * - * @param charnum The index of the character, where the - * first character has an index of 0. - * @return The character's end position. - */ - public Point2D getEndPositionOfChar(int charnum); - - /** - * Returns the rotation value relative to the current - * user coordinate system used to render the glyph(s) - * corresponding to the specified character. If - * multiple glyph(s) are used to render the given - * character and the glyphs each have different - * rotations (e.g., due to text-on-a-path), the user - * agent shall return an average value (e.g., the - * rotation angle at the midpoint along the path for - * all glyphs used to render this character). The - * rotation value represents the rotation that is - * supplemental to any rotation due to properties - * 'glyph-orientation-horizontal' and - * 'glyph-orientation-vertical'; thus, any glyph - * rotations due to these properties are not included - * into the returned rotation value. If multiple - * consecutive characters are rendered inseparably - * (e.g., as a single glyph or a sequence of glyphs), - * then each of the inseparable characters will - * return the same rotation value. - * - * @param charnum The index of the character, where the - * first character has an index of 0. - * @return The character's rotation angle. - */ - public float getRotationOfChar(int charnum); - /** - * Causes the specified substring to be selected - * just as if the user selected the substring interactively. - * - * @param charnum : The index of the start character - * which is at the given point, where the first - * character has an index of 0. - * @param nchars : The number of characters in the - * substring. If nchars specifies more characters - * than are available, then the substring will - * consist of all characters starting with charnum - * until the end of the list of characters. - */ - public void selectSubString(int charnum, int nchars); - - public float getComputedTextLength(); - - public float getSubStringLength(int charnum, int nchars); - - public int getCharNumAtPosition(float x, float y); -} +/*****************************************************************************
* 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.dom.svg; import java.awt.geom.Rectangle2D; import java.awt.geom.Point2D; import org.w3c.dom.DOMException; /** * This class provides the interface for the SVGTextContentElement * for the bridge to implement. * * @author [EMAIL PROTECTED] * @version $Id$ */ public interface SVGTextContent { /** * Returns the total number of characters to be * rendered within the current element. * Includes characters which are included * via a <tref> reference. * * @return Total number of characters. */ public int getNumberOfChars(); /** * Returns a tightest rectangle which defines the * minimum and maximum X and Y values in the user * coordinate system for rendering the glyph(s) * that correspond to the specified character. * The calculations assume that all glyphs occupy * the full standard glyph cell for the font. If * multiple consecutive characters are rendered * inseparably (e.g., as a single glyph or a * sequence of glyphs), then each of the inseparable * characters will return the same extent. * * @param charnum The index of the character, where the * first character has an index of 0. * @return The rectangle which encloses all of * the rendered glyph(s). */ public Rectangle2D getExtentOfChar(int charnum ); /** * Returns the current text position before rendering * the character in the user coordinate system for * rendering the glyph(s) that correspond to the * specified character. The current text position has * already taken into account the effects of any inter- * character adjustments due to properties 'kerning', * 'letter-spacing' and 'word-spacing' and adjustments * due to attributes x, y, dx and dy. If multiple * consecutive characters are rendered inseparably * (e.g., as a single glyph or a sequence of glyphs), * then each of the inseparable characters will return * the start position for the first glyph. * * @param charnum The index of the character, where the * first character has an index of 0. * @return The character's start position. */ public Point2D getStartPositionOfChar(int charnum); /** * Returns the current text position after rendering * the character in the user coordinate system for * rendering the glyph(s) that correspond to the * specified character. This current text position * does not take into account the effects of any inter- * character adjustments to prepare for the next * character, such as properties 'kerning', * 'letter-spacing' and 'word-spacing' and adjustments * due to attributes x, y, dx and dy. If multiple * consecutive characters are rendered inseparably * (e.g., as a single glyph or a sequence of glyphs), * then each of the inseparable characters will return * the end position for the last glyph. * * @param charnum The index of the character, where the * first character has an index of 0. * @return The character's end position. */ public Point2D getEndPositionOfChar(int charnum); /** * Returns the rotation value relative to the current * user coordinate system used to render the glyph(s) * corresponding to the specified character. If * multiple glyph(s) are used to render the given * character and the glyphs each have different * rotations (e.g., due to text-on-a-path), the user * agent shall return an average value (e.g., the * rotation angle at the midpoint along the path for * all glyphs used to render this character). The * rotation value represents the rotation that is * supplemental to any rotation due to properties * 'glyph-orientation-horizontal' and * 'glyph-orientation-vertical'; thus, any glyph * rotations due to these properties are not included * into the returned rotation value. If multiple * consecutive characters are rendered inseparably * (e.g., as a single glyph or a sequence of glyphs), * then each of the inseparable characters will * return the same rotation value. * * @param charnum The index of the character, where the * first character has an index of 0. * @return The character's rotation angle. */ public float getRotationOfChar(int charnum); /** * Causes the specified substring to be selected * just as if the user selected the substring interactively. * * @param charnum : The index of the start character * which is at the given point, where the first * character has an index of 0. * @param nchars : The number of characters in the * substring. If nchars specifies more characters * than are available, then the substring will * consist of all characters starting with charnum * until the end of the list of characters. */ public void selectSubString(int charnum, int nchars); public float getComputedTextLength(); public float getSubStringLength(int charnum, int nchars); public int getCharNumAtPosition(float x, float y); } \ No newline at end of file 1.1 xml-batik/sources/org/apache/batik/dom/svg/SVGOMPoint.java Index: SVGOMPoint.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.dom.svg; import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import org.w3c.dom.DOMException; import org.w3c.dom.svg.SVGMatrix; import org.w3c.dom.svg.SVGPoint; /** * This class provides an abstract implementation of the [EMAIL PROTECTED] SVGMatrix} * interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> * @version $Id: SVGOMPoint.java,v 1.1 2003/02/24 18:25:53 deweese Exp $ */ public class SVGOMPoint implements SVGPoint { float x, y; public SVGOMPoint() { x=0; y=0; } public SVGOMPoint(float x, float y) { this.x = x; this.y = y; } public float getX( ) { return x; } public void setX( float x ) throws DOMException { this.x = x; } public float getY( ) { return y; } public void setY( float y ) throws DOMException { this.y = y; } public SVGPoint matrixTransform ( SVGMatrix matrix ) { float newX = matrix.getA()*x + matrix.getC()*y + matrix.getE(); float newY = matrix.getB()*x + matrix.getD()*y + matrix.getF(); return new SVGOMPoint(newX, newY); } } 1.3 +18 -181 xml-batik/sources/org/apache/batik/dom/svg/SVGOMRect.java 1.45 +1 -6 xml-batik/sources/org/apache/batik/gvt/AbstractGraphicsNode.java Index: AbstractGraphicsNode.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/AbstractGraphicsNode.java,v retrieving revision 1.44 retrieving revision 1.45 diff -u -r1.44 -r1.45 --- AbstractGraphicsNode.java 25 Jul 2002 21:42:42 -0000 1.44 +++ AbstractGraphicsNode.java 24 Feb 2003 18:25:53 -0000 1.45 @@ -37,13 +37,8 @@ import org.apache.batik.ext.awt.image.PadMode; import org.apache.batik.ext.awt.image.renderable.ClipRable; import org.apache.batik.ext.awt.image.renderable.Filter; -import org.apache.batik.gvt.event.GraphicsNodeEvent; import org.apache.batik.gvt.event.GraphicsNodeChangeEvent; import org.apache.batik.gvt.event.GraphicsNodeChangeListener; -import org.apache.batik.gvt.event.GraphicsNodeKeyEvent; -import org.apache.batik.gvt.event.GraphicsNodeKeyListener; -import org.apache.batik.gvt.event.GraphicsNodeMouseEvent; -import org.apache.batik.gvt.event.GraphicsNodeMouseListener; import org.apache.batik.gvt.filter.Mask; import org.apache.batik.gvt.filter.GraphicsNodeRable; import org.apache.batik.gvt.filter.GraphicsNodeRable8Bit; 1.6 +83 -1 xml-batik/sources/org/apache/batik/gvt/CanvasGraphicsNode.java Index: CanvasGraphicsNode.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/CanvasGraphicsNode.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- CanvasGraphicsNode.java 18 Sep 2001 21:18:59 -0000 1.5 +++ CanvasGraphicsNode.java 24 Feb 2003 18:25:53 -0000 1.6 @@ -12,6 +12,8 @@ import java.awt.Rectangle; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.NoninvertibleTransformException; /** * The graphics node container with a background color. @@ -21,6 +23,21 @@ */ public class CanvasGraphicsNode extends CompositeGraphicsNode { + /** + * This is the position transform for this graphics node. + * This is needed because getCTM returns the transform + * to the viewport coordinate system which is after viewing but + * before positioning. + */ + protected AffineTransform positionTransform; + /** + * This is the viewing transform for this graphics node. + * This is needed because getCTM returns the transform + * to the viewport coordinate system which is after viewing but + * before positioning. + */ + protected AffineTransform viewingTransform; + /** * The background of this canvas graphics node. */ @@ -51,6 +68,71 @@ return backgroundPaint; } + public void setPositionTransform(AffineTransform at) { + fireGraphicsNodeChangeStarted(); + invalidateGeometryCache(); + this.positionTransform = at; + if (positionTransform != null) { + transform = new AffineTransform(positionTransform); + if (viewingTransform != null) + transform.concatenate(viewingTransform); + } else if (viewingTransform != null) + transform = new AffineTransform(viewingTransform); + else + transform = new AffineTransform(); + + if (transform.getDeterminant() != 0){ + try{ + inverseTransform = transform.createInverse(); + }catch(NoninvertibleTransformException e){ + // Should never happen. + throw new Error(); + } + } + else{ + // The transform is not invertible. Use the same + // transform. + inverseTransform = transform; + } + fireGraphicsNodeChangeCompleted(); + } + + public AffineTransform getPositionTransform() { + return positionTransform; + } + + public void setViewingTransform(AffineTransform at) { + fireGraphicsNodeChangeStarted(); + invalidateGeometryCache(); + this.viewingTransform = at; + if (positionTransform != null) { + transform = new AffineTransform(positionTransform); + if (viewingTransform != null) + transform.concatenate(viewingTransform); + } else if (viewingTransform != null) + transform = new AffineTransform(viewingTransform); + else + transform = new AffineTransform(); + + if(transform.getDeterminant() != 0){ + try{ + inverseTransform = transform.createInverse(); + }catch(NoninvertibleTransformException e){ + // Should never happen. + throw new Error(); + } + } + else{ + // The transform is not invertible. Use the same + // transform. + inverseTransform = transform; + } + fireGraphicsNodeChangeCompleted(); + } + + public AffineTransform getViewingTransform() { + return viewingTransform; + } // // Drawing methods // 1.11 +4 -3 xml-batik/sources/org/apache/batik/gvt/event/AWTEventDispatcher.java Index: AWTEventDispatcher.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/event/AWTEventDispatcher.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- AWTEventDispatcher.java 28 Jun 2002 15:02:02 -0000 1.10 +++ AWTEventDispatcher.java 24 Feb 2003 18:25:53 -0000 1.11 @@ -338,11 +338,12 @@ protected void dispatchMouseEvent(MouseEvent evt) { GraphicsNodeMouseEvent gvtevt; Point2D p = new Point2D.Float(evt.getX(), evt.getY()); + Point2D gnp = p; if (baseTransform != null) { - p = baseTransform.transform(p, null); + gnp = baseTransform.transform(p, null); } - GraphicsNode node = root.nodeHitAt(p); + GraphicsNode node = root.nodeHitAt(gnp); // If the receiving node has changed, send a notification // check if we enter a new node 1.36 +2 -2 xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java Index: JSVGCanvas.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- JSVGCanvas.java 11 Nov 2002 14:38:37 -0000 1.35 +++ JSVGCanvas.java 24 Feb 2003 18:25:54 -0000 1.36 @@ -517,7 +517,7 @@ */ protected class ResetTransformAction extends AbstractAction { public void actionPerformed(ActionEvent evt) { - setFragmentIdentifier(null); + fragmentIdentifier = null; resetRenderingTransform(); } } 1.30 +25 -10 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.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- JGVTComponent.java 2 Aug 2002 00:18:35 -0000 1.29 +++ JGVTComponent.java 24 Feb 2003 18:25:54 -0000 1.30 @@ -113,12 +113,12 @@ /** * The initial rendering transform. */ - protected AffineTransform initialTransform; + protected AffineTransform initialTransform = new AffineTransform(); /** * The transform used for rendering. */ - protected AffineTransform renderingTransform; + protected AffineTransform renderingTransform = new AffineTransform(); /** * The transform used for painting. @@ -206,8 +206,8 @@ addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { - updateRenderingTransform(); - scheduleGVTRendering(); + if (updateRenderingTransform()) + scheduleGVTRendering(); } }); @@ -264,6 +264,9 @@ */ public void setGraphicsNode(GraphicsNode gn) { setGraphicsNode(gn, true); + initialTransform = new AffineTransform(); + updateRenderingTransform(); + setRenderingTransform(initialTransform, true); } /** @@ -277,7 +280,6 @@ if (eventDispatcher != null) { eventDispatcher.setRootNode(gn); } - computeRenderingTransform(); } /** @@ -483,6 +485,11 @@ * Calling this method causes a rendering to be performed. */ public void setRenderingTransform(AffineTransform at) { + setRenderingTransform(at, true); + } + + public void setRenderingTransform(AffineTransform at, + boolean performRedraw) { renderingTransform = at; suspendInteractions = true; if (eventDispatcher != null) { @@ -493,7 +500,8 @@ handleException(e); } } - scheduleGVTRendering(); + if (performRedraw) + scheduleGVTRendering(); } /** @@ -611,17 +619,24 @@ /** * Computes the initial value of the transform used for rendering. + * Return true if a repaint is required, otherwise false. */ - protected void computeRenderingTransform() { + protected boolean computeRenderingTransform() { initialTransform = new AffineTransform(); - setRenderingTransform(initialTransform); + if (initialTransform != renderingTransform) { + setRenderingTransform(initialTransform, false); + return true; + } + return false; } /** * Updates the value of the transform used for rendering. + * Return true if a repaint is required, otherwise false. */ - protected void updateRenderingTransform() { + protected boolean updateRenderingTransform() { // Do nothing. + return false; } /** 1.62 +128 -23 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.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- JSVGComponent.java 14 Nov 2002 19:44:49 -0000 1.61 +++ JSVGComponent.java 24 Feb 2003 18:25:54 -0000 1.62 @@ -8,6 +8,7 @@ package org.apache.batik.swing.svg; +import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; import java.awt.EventQueue; @@ -15,6 +16,7 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.Shape; +import java.awt.Window; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; @@ -58,6 +60,8 @@ import org.apache.batik.ext.awt.image.spi.ImageTagRegistry; import org.apache.batik.gvt.GraphicsNode; +import org.apache.batik.gvt.CanvasGraphicsNode; +import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.gvt.event.EventDispatcher; @@ -538,7 +542,8 @@ */ public void setFragmentIdentifier(String fi) { fragmentIdentifier = fi; - computeRenderingTransform(); + if (computeRenderingTransform()) + scheduleGVTRendering(); } /** @@ -593,33 +598,81 @@ } } + public CanvasGraphicsNode getCanvasGraphicsNode() { + return getCanvasGraphicsNode(gvtRoot); + + } + + protected CanvasGraphicsNode getCanvasGraphicsNode(GraphicsNode gn) { + if (!(gn instanceof CompositeGraphicsNode)) + return null; + CompositeGraphicsNode cgn = (CompositeGraphicsNode)gn; + gn = (GraphicsNode)cgn.getChildren().get(0); + if (!(gn instanceof CanvasGraphicsNode)) + return null; + return (CanvasGraphicsNode)gn; + } + /** * Computes the transform used for rendering. + * Returns true if the component needs to be repainted. */ - protected void computeRenderingTransform() { + protected boolean computeRenderingTransform() { + if ((svgDocument == null) || (gvtRoot == null)) + return false; + + boolean ret = false; try { - if (svgDocument != null) { - SVGSVGElement elt = svgDocument.getRootElement(); - Dimension d = getSize(); - if (d.width < 1) d.width = 1; - if (d.height < 1) d.height = 1; - setRenderingTransform - (ViewBox.getViewTransform - (fragmentIdentifier, elt, d.width, d.height)); - initialTransform = renderingTransform; + SVGSVGElement elt = svgDocument.getRootElement(); + Dimension d = getSize(); + if (d.width < 1) d.width = 1; + if (d.height < 1) d.height = 1; + AffineTransform at = ViewBox.getViewTransform + (fragmentIdentifier, elt, d.width, d.height); + CanvasGraphicsNode cgn = getCanvasGraphicsNode(); + if (!at.equals(cgn.getViewingTransform())) { + cgn.setViewingTransform(at); + if (renderer != null) + renderer.setTree(gvtRoot); + ret = true; + } + + initialTransform = new AffineTransform(); + if (!initialTransform.equals(getRenderingTransform())) { + setRenderingTransform(initialTransform, false); + ret = true; } } catch (BridgeException e) { userAgent.displayError(e); } + return ret; } /** * Updates the value of the transform used for rendering. + * Return true if a repaint is required, otherwise false. */ - protected void updateRenderingTransform() { - if (initialTransform == renderingTransform) { - computeRenderingTransform(); + protected boolean updateRenderingTransform() { + if ((svgDocument == null) || (gvtRoot == null)) + return false; + try { + SVGSVGElement elt = svgDocument.getRootElement(); + Dimension d = getSize(); + if (d.width < 1) d.width = 1; + if (d.height < 1) d.height = 1; + AffineTransform at = ViewBox.getViewTransform + (fragmentIdentifier, elt, d.width, d.height); + CanvasGraphicsNode cgn = getCanvasGraphicsNode(); + if (!at.equals(cgn.getViewingTransform())) { + cgn.setViewingTransform(at); + if (renderer != null) + renderer.setTree(gvtRoot); + return true; + } + } catch (BridgeException e) { + userAgent.displayError(e); } + return false; } /** @@ -866,7 +919,6 @@ * The data of the event is initialized to the old document. */ public void gvtBuildStarted(GVTTreeBuilderEvent e) { - computeRenderingTransform(); } /** @@ -885,16 +937,39 @@ return; } + Dimension2D dim = bridgeContext.getDocumentSize(); + setMySize(new Dimension((int)dim.getWidth(), + (int)dim.getHeight())); + SVGSVGElement elt = svgDocument.getRootElement(); + Dimension sz = getSize(); + if (sz.width < 1) sz.width = 1; + if (sz.height < 1) sz.height = 1; + AffineTransform vt = ViewBox.getViewTransform + (fragmentIdentifier, elt, sz.width, sz.height); + CanvasGraphicsNode cgn = getCanvasGraphicsNode(e.getGVTRoot()); + cgn.setViewingTransform(vt); + gvtRoot = null; if (isDynamicDocument && JSVGComponent.this.eventsEnabled) { startSVGLoadEventDispatcher(e.getGVTRoot()); } else { JSVGComponent.this.setGraphicsNode(e.getGVTRoot(), false); + scheduleGVTRendering(); } - Dimension2D dim = bridgeContext.getDocumentSize(); - setPreferredSize(new Dimension((int)dim.getWidth(), - (int)dim.getHeight())); + } + + public void setMySize(Dimension d) { + setPreferredSize(d); invalidate(); + Container p = getParent(); + while (p != null) { + if (p instanceof Window) { + Window w = (Window) p; + w.pack(); + break; + } + p = p.getParent(); + } } /** @@ -938,10 +1013,10 @@ JSVGComponent.this.image = null; repaint(); } else { + setMySize(new Dimension((int)dim.getWidth(), + (int)dim.getHeight())); JSVGComponent.this.setGraphicsNode(gn, false); - setPreferredSize(new Dimension((int)dim.getWidth(), - (int)dim.getHeight())); - invalidate(); + computeRenderingTransform(); } userAgent.displayError(((GVTTreeBuilder)e.getSource()) .getException()); @@ -980,6 +1055,7 @@ } JSVGComponent.this.setGraphicsNode(e.getGVTRoot(), false); + scheduleGVTRendering(); } /** @@ -1030,6 +1106,7 @@ repaint(); } else { JSVGComponent.this.setGraphicsNode(gn, false); + computeRenderingTransform(); } userAgent.displayError(((SVGLoadEventDispatcher)e.getSource()) .getException()); @@ -1945,6 +2022,25 @@ } /** + * Sets the <code>AffineTransform</code> to be + * applied to the drawing by the UserAgent. + */ + public void setTransform(AffineTransform at) { + if (EventQueue.isDispatchThread()) { + userAgent.setTransform(at); + } else { + final AffineTransform affine = at; + class Query implements Runnable { + public void run() { + userAgent.setTransform(affine); + } + } + Query q = new Query(); + invokeAndWait(q); + } + } + + /** * Returns this user agent's CSS media. */ public String getMedia() { @@ -2497,7 +2593,8 @@ ((s == null) || (!s.equals(fragmentIdentifier)))) { // It is, so update rendering transform. fragmentIdentifier = s; - computeRenderingTransform(); + if (computeRenderingTransform()) + scheduleGVTRendering(); } // Let every one know the link fired (but don't // load doc, it's already loaded.). @@ -2567,6 +2664,14 @@ */ public AffineTransform getTransform() { return JSVGComponent.this.renderingTransform; + } + + /** + * Sets the <code>AffineTransform</code> to be + * applied to the drawing by the UserAgent. + */ + public void setTransform(AffineTransform at) { + JSVGComponent.this.setRenderingTransform(at); } /** 1.4 +55 -10 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.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SVGAbstractTranscoder.java 18 Sep 2002 09:23:12 -0000 1.3 +++ SVGAbstractTranscoder.java 24 Feb 2003 18:25:54 -0000 1.4 @@ -22,6 +22,8 @@ import org.apache.batik.dom.util.DocumentFactory; import org.apache.batik.gvt.GraphicsNode; +import org.apache.batik.gvt.CanvasGraphicsNode; +import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.bridge.BaseScriptingEnvironment; import org.apache.batik.bridge.BridgeContext; @@ -165,19 +167,12 @@ GraphicsNode gvtRoot; try { gvtRoot = builder.build(ctx, svgDoc); - // dispatch an 'onload' event if needed - if (ctx.isDynamic()) { - BaseScriptingEnvironment se = new BaseScriptingEnvironment(ctx); - se.loadScripts(); - se.dispatchSVGLoadEvent(); - } } catch (BridgeException ex) { throw new TranscoderException(ex); } // get the 'width' and 'height' attributes of the SVG document float docWidth = (float)ctx.getDocumentSize().getWidth(); float docHeight = (float)ctx.getDocumentSize().getHeight(); - ctx = null; builder = null; setImageSize(docWidth, docHeight); @@ -188,6 +183,7 @@ try { Px = ViewBox.getViewTransform(ref, root, width, height); + } catch (BridgeException ex) { throw new TranscoderException(ex); } @@ -219,10 +215,42 @@ } else { curAOI = new Rectangle2D.Float(0, 0, width, height); } - curTxf = Px; + + CanvasGraphicsNode cgn = getCanvasGraphicsNode(gvtRoot); + if (cgn != null) { + cgn.setViewingTransform(Px); + curTxf = new AffineTransform(); + } else { + curTxf = Px; + } + + try { + // dispatch an 'onload' event if needed + if (ctx.isDynamic()) { + BaseScriptingEnvironment se; + se = new BaseScriptingEnvironment(ctx); + se.loadScripts(); + se.dispatchSVGLoadEvent(); + } + } catch (BridgeException ex) { + throw new TranscoderException(ex); + } + ctx = null; + + this.root = gvtRoot; } + protected CanvasGraphicsNode getCanvasGraphicsNode(GraphicsNode gn) { + if (!(gn instanceof CompositeGraphicsNode)) + return null; + CompositeGraphicsNode cgn = (CompositeGraphicsNode)gn; + gn = (GraphicsNode)cgn.getChildren().get(0); + if (!(gn instanceof CanvasGraphicsNode)) + return null; + return (CanvasGraphicsNode)gn; + } + /** * Sets document size according to the hints. * Global variables width and height are modified. @@ -678,10 +706,26 @@ } /** + * Return the rendering transform. + */ + public AffineTransform getTransform() { + return SVGAbstractTranscoder.this.curTxf; + } + + /** + * Return the rendering transform. + */ + public void setTransform(AffineTransform at) { + SVGAbstractTranscoder.this.curTxf = at; + } + + /** * Returns the default size of this user agent (400x400). */ public Dimension2D getViewportSize() { - return new Dimension(400, 400); + return new Dimension + ((int)SVGAbstractTranscoder.this.width, + (int)SVGAbstractTranscoder.this.height); } /** @@ -701,6 +745,7 @@ */ public void displayError(Exception e) { try { + e.printStackTrace(); SVGAbstractTranscoder.this.handler.error (new TranscoderException(e)); } catch (TranscoderException ex) { 1.91 +24 -23 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.90 retrieving revision 1.91 diff -u -r1.90 -r1.91 --- samplesRendering.xml 8 Feb 2003 13:25:12 -0000 1.90 +++ samplesRendering.xml 24 Feb 2003 18:25:54 -0000 1.91 @@ -303,9 +303,22 @@ <testGroup id="tests.spec.scripting"> <test id="samples/tests/spec/scripting/add.svg" /> + <test id="samples/tests/spec/scripting/bug12933.svg" /> <test id="samples/tests/spec/scripting/circle.svg" /> + <test id="samples/tests/spec/scripting/currentScaleTranslate.svg" /> <test id="samples/tests/spec/scripting/ellipse.svg" /> + <test id="samples/tests/spec/scripting/fill.svg" /> + <test id="samples/tests/spec/scripting/filterPatternUpdate.svg" /> + <test id="samples/tests/spec/scripting/gradientsUpdate.svg" /> + <test id="samples/tests/spec/scripting/image.svg" /> + <test id="samples/tests/spec/scripting/imageRefUpdate.svg" /> + <test id="samples/tests/spec/scripting/imageUpdate.svg" /> + <test id="samples/tests/spec/scripting/imageraster.svg" /> + <test id="samples/tests/spec/scripting/imagesvg.svg" /> <test id="samples/tests/spec/scripting/line.svg" /> + <test id="samples/tests/spec/scripting/markerUpdate.svg" /> + <test id="samples/tests/spec/scripting/maskClipUpdate.svg" /> + <test id="samples/tests/spec/scripting/nestedsvg.svg" /> <test id="samples/tests/spec/scripting/path.svg" /> <test id="samples/tests/spec/scripting/polygon.svg" /> <test id="samples/tests/spec/scripting/polyline.svg" /> @@ -313,35 +326,23 @@ <test id="samples/tests/spec/scripting/remove.svg" /> <test id="samples/tests/spec/scripting/removeLast.svg" /> <test id="samples/tests/spec/scripting/removeOnclick.svg" /> - <test id="samples/tests/spec/scripting/transform.svg" /> - <test id="samples/tests/spec/scripting/transform2.svg" /> - <test id="samples/tests/spec/scripting/xyModifOnLoad.svg" /> - <test id="samples/tests/spec/scripting/fill.svg" /> - <test id="samples/tests/spec/scripting/visibility.svg" /> - <test id="samples/tests/spec/scripting/textProperties.svg" /> - <test id="samples/tests/spec/scripting/nestedsvg.svg" /> + <test id="samples/tests/spec/scripting/svg.svg" /> + <test id="samples/tests/spec/scripting/svg2.svg" /> <test id="samples/tests/spec/scripting/text.svg" /> <test id="samples/tests/spec/scripting/textAllProperties.svg" /> - <test id="samples/tests/spec/scripting/textpathProperties.svg" /> - <test id="samples/tests/spec/scripting/trefProperties.svg" /> - <test id="samples/tests/spec/scripting/tspan.svg" /> + <test id="samples/tests/spec/scripting/textProperties.svg" /> <test id="samples/tests/spec/scripting/text_children1.svg" /> <test id="samples/tests/spec/scripting/text_children2.svg" /> <test id="samples/tests/spec/scripting/text_children3.svg" /> + <test id="samples/tests/spec/scripting/textpathProperties.svg" /> + <test id="samples/tests/spec/scripting/transform.svg" /> + <test id="samples/tests/spec/scripting/transform2.svg" /> + <test id="samples/tests/spec/scripting/trefProperties.svg" /> + <test id="samples/tests/spec/scripting/tspan.svg" /> <test id="samples/tests/spec/scripting/tspanProperties.svg" /> - <test id="samples/tests/spec/scripting/image.svg" /> - <test id="samples/tests/spec/scripting/imageraster.svg" /> - <test id="samples/tests/spec/scripting/imagesvg.svg" /> - <test id="samples/tests/spec/scripting/imageRefUpdate.svg" /> - <test id="samples/tests/spec/scripting/imageUpdate.svg" /> - <test id="samples/tests/spec/scripting/gradientsUpdate.svg" /> - <test id="samples/tests/spec/scripting/maskClipUpdate.svg" /> - <test id="samples/tests/spec/scripting/markerUpdate.svg" /> - <test id="samples/tests/spec/scripting/filterPatternUpdate.svg" /> <test id="samples/tests/spec/scripting/use.svg" /> - <test id="samples/tests/spec/scripting/svg.svg" /> - <test id="samples/tests/spec/scripting/svg2.svg" /> - <test id="samples/tests/spec/scripting/bug12933.svg" /> + <test id="samples/tests/spec/scripting/visibility.svg" /> + <test id="samples/tests/spec/scripting/xyModifOnLoad.svg" /> </testGroup> </testSuite> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]