tkormann 02/03/20 08:34:44 Modified: sources/org/apache/batik/bridge AbstractGraphicsNodeBridge.java AbstractSVGBridge.java AbstractSVGGradientElementBridge.java Bridge.java BridgeContext.java BridgeUpdateHandler.java GVTBuilder.java PaintServer.java SVGCircleElementBridge.java SVGEllipseElementBridge.java SVGGElementBridge.java SVGImageElementBridge.java SVGLineElementBridge.java SVGLinearGradientElementBridge.java SVGPathElementBridge.java SVGPolygonElementBridge.java SVGPolylineElementBridge.java SVGRadialGradientElementBridge.java SVGRectElementBridge.java SVGSVGElementBridge.java SVGShapeElementBridge.java SVGTextElementBridge.java SVGUseElementBridge.java sources/org/apache/batik/css/engine CSSEngine.java sources/org/apache/batik/gvt AbstractGraphicsNode.java test-references/samples/tests/spec/text smallFonts.png textFeatures.png Removed: sources/org/apache/batik/bridge BridgeUpdateEvent.java Log: Bridge cleanup and new features: - merge all GraphicsNodeBridge. They are all not a subclass of AbstractGraphicsNodeBridge - fix a bug on text ('opacity' was ignored) - remove support of dynamic gradients (need futher investigation) - add dynamic support for CSS via a global listener on CSS engine 'visibility' on elements 'fill, stroke...' on shapes - add/remove elements is now clean (references/listeners are removed) - lightweight implementation of DOM Attr changed listener (no more one listener per Element). - add SVGContext on the SVG DOM - implementation of getBounds() in SVGContext, so that we will be able to implement getBBox soon - add two new simple tests (fill.svg and visibility.svg) - add/remove child now works on both <g> and <svg> (relative values with units or percentages are not handled yet) Revision Changes Path 1.17 +113 -70 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.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- AbstractGraphicsNodeBridge.java 18 Mar 2002 10:28:19 -0000 1.16 +++ AbstractGraphicsNodeBridge.java 20 Mar 2002 16:34:43 -0000 1.17 @@ -9,15 +9,19 @@ package org.apache.batik.bridge; import java.awt.geom.AffineTransform; +import java.awt.geom.Rectangle2D; + +import org.apache.batik.css.engine.CSSEngineEvent; +import org.apache.batik.css.engine.SVGCSSEngine; + +import org.apache.batik.dom.svg.SVGContext; +import org.apache.batik.dom.svg.SVGOMElement; -import org.apache.batik.gvt.CompositeGraphicsNode; import org.apache.batik.gvt.GraphicsNode; -import org.apache.batik.parser.ParseException; +import org.apache.batik.gvt.CompositeGraphicsNode; import org.w3c.dom.Element; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; +import org.w3c.dom.Node; import org.w3c.dom.events.MutationEvent; /** @@ -39,10 +43,13 @@ * </ul> * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: AbstractGraphicsNodeBridge.java,v 1.16 2002/03/18 10:28:19 hillion Exp $ + * @version $Id: AbstractGraphicsNodeBridge.java,v 1.17 2002/03/20 16:34:43 tkormann Exp $ */ public abstract class AbstractGraphicsNodeBridge extends AbstractSVGBridge - implements BridgeUpdateHandler, GraphicsNodeBridge, ErrorConstants { + implements SVGContext, + BridgeUpdateHandler, + GraphicsNodeBridge, + ErrorConstants { /** * The element that has been handled by this bridge. @@ -106,12 +113,6 @@ public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) { - - // push 'this' as the current BridgeUpdateHandler for subbridges - if (ctx.isDynamic()) { - ctx.pushBridgeUpdateHandler(this); - } - // 'opacity' node.setComposite(CSSUtilities.convertOpacity(e)); // 'filter' @@ -124,64 +125,36 @@ node.setPointerEventType(CSSUtilities.convertPointerEvents(e)); if (ctx.isDynamic()) { - this.e = e; - this.node = node; - this.ctx = ctx; - initializeDynamicSupport(); - // 'this' is no more the current BridgeUpdateHandler - ctx.popBridgeUpdateHandler(); + initializeDynamicSupport(ctx, e, node); } - // Handle children elements such as <title> SVGUtilities.bridgeChildren(ctx, e); } - // dynamic support - /** * This method is invoked during the build phase if the document * is dynamic. The responsability of this method is to ensure that * any dynamic modifications of the element this bridge is * dedicated to, happen on its associated GVT product. */ - protected void initializeDynamicSupport() { - ((EventTarget)e).addEventListener("DOMAttrModified", - new DOMAttrModifiedEventListener(), - false); + protected void initializeDynamicSupport(BridgeContext ctx, + Element e, + GraphicsNode node) { + this.e = e; + this.node = node; + this.ctx = ctx; ctx.bind(e, node); + ((SVGOMElement)e).setSVGContext(this); } - /** - * Invoked when a bridge update is starting. - * - * @param evt the evt that describes the incoming update - */ - public void bridgeUpdateStarting(BridgeUpdateEvent evt) { - System.out.println("("+e.getLocalName()+" "+node+") update started "+ - evt.getHandlerKey()); - } - - /** - * Invoked when a bridge update is completed. - * - * @param evt the evt that describes the update - */ - public void bridgeUpdateCompleted(BridgeUpdateEvent evt) { - System.out.println("("+e.getLocalName()+" "+node+") update completed "+ - evt.getHandlerKey()); - } + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_TRANSFORM_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); - String s = evt.getNewValue(); AffineTransform at = GraphicsNode.IDENTITY; if (s.length() != 0) { @@ -189,30 +162,100 @@ (e, SVG_TRANSFORM_ATTRIBUTE, s); } node.setTransform(at); - fireBridgeUpdateCompleted(be); - } else { - System.out.println("Unsupported attribute modification: "+attrName+ - " on "+e.getLocalName()); } } /** - * The listener class for 'DOMAttrModified' event. + * Invoked when an MutationEvent of type 'DOMNodeInserted' is fired. */ - protected class DOMAttrModifiedEventListener implements EventListener { + public void handleDOMNodeInsertedEvent(MutationEvent evt) { + // never called. The global listener on the document will + // invoke this method on the parent element. + } - /** - * Handles 'DOMAttrModfied' events and deleguates to the - * 'handleDOMAttrModifiedEvent' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - if (evt.getTarget() != e) { - return; - } - handleDOMAttrModifiedEvent((MutationEvent)evt); + /** + * Invoked when an MutationEvent of type 'DOMNodeRemoved' is fired. + */ + public void handleDOMNodeRemovedEvent(MutationEvent evt) { + CompositeGraphicsNode gn = node.getParent(); + gn.remove(node); + disposeTree(e); + } + + /** + * Disposes all resources related to the specified node and its subtree + */ + protected void disposeTree(Node node) { + if (node instanceof SVGOMElement) { + ((SVGOMElement)node).setSVGContext(null); + ctx.unbind((Element)node); + } + for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) { + disposeTree(n); + } + } + + /** + * Invoked when an CSSEngineEvent is fired. + */ + public void handleCSSEngineEvent(CSSEngineEvent evt) { + int [] properties = evt.getProperties(); + for (int i=0; i < properties.length; ++i) { + handleCSSPropertyChanged(properties[i]); + } + } + + /** + * Invoked for each CSS property that has changed. + */ + protected void handleCSSPropertyChanged(int property) { + switch(property) { + case SVGCSSEngine.VISIBILITY_INDEX: + node.setVisible(CSSUtilities.convertVisibility(e)); + break; + case SVGCSSEngine.OPACITY_INDEX: + node.setComposite(CSSUtilities.convertOpacity(e)); + break; + case SVGCSSEngine.FILTER_INDEX: + node.setFilter(CSSUtilities.convertFilter(e, node, ctx)); + break; + case SVGCSSEngine.MASK_INDEX: + node.setMask(CSSUtilities.convertMask(e, node, ctx)); + break; + case SVGCSSEngine.CLIP_PATH_INDEX: + node.setClip(CSSUtilities.convertClipPath(e, node, ctx)); + break; + case SVGCSSEngine.POINTER_EVENTS_INDEX: + node.setPointerEventType(CSSUtilities.convertPointerEvents(e)); + break; } + } + + // SVGContext implementation /////////////////////////////////////////// + + /** + * Return the pixel to millimeters factor. + */ + public float getPixelToMM() { + return ctx.getUserAgent().getPixelToMM(); + } + + /** + * Returns the tight bounding box in current user space (i.e., + * after application of the transform attribute, if any) on the + * geometry of all contained graphics elements, exclusive of + * stroke-width and filter effects). + */ + public Rectangle2D getBBox() { + return node.getTransformedPrimitiveBounds(null); + } + + /** + * 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. + */ + public AffineTransform getCTM() { + throw new Error("Not yet implemented"); } } 1.3 +1 -59 xml-batik/sources/org/apache/batik/bridge/AbstractSVGBridge.java Index: AbstractSVGBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractSVGBridge.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- AbstractSVGBridge.java 12 Feb 2002 15:14:37 -0000 1.2 +++ AbstractSVGBridge.java 20 Mar 2002 16:34:43 -0000 1.3 @@ -14,22 +14,11 @@ * The base bridge class for SVG elements. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: AbstractSVGBridge.java,v 1.2 2002/02/12 15:14:37 tkormann Exp $ + * @version $Id: AbstractSVGBridge.java,v 1.3 2002/03/20 16:34:43 tkormann Exp $ */ public abstract class AbstractSVGBridge implements Bridge, SVGConstants { /** - * The update handler to notify each time the GVT product - * associated to this bridge changes. - */ - protected BridgeUpdateHandler handler; - - /** - * The private key of the update handler. - */ - protected int handlerKey; - - /** * Constructs a new abstract bridge for SVG elements. */ protected AbstractSVGBridge() {} @@ -48,52 +37,5 @@ // <!> FIXME: temporary fix for progressive implementation //System.out.println("use static bridge for: "+getLocalName()); return this; - } - - /** - * Returns the handler that is called each time this bridge - * updates its GVT product. - */ - public BridgeUpdateHandler getBridgeUpdateHandler() { - return handler; - } - - /** - * Sets the handler that is used to track each update of this - * bridge's GVT product. - * - * @param handler the handler to call - * @param handlerKey a private key the handler might use when it registers - */ - public void setBridgeUpdateHandler(BridgeUpdateHandler handler, - int handlerKey) { - this.handler = handler; - this.handlerKey = handlerKey; - } - - /** - * Notifies the BridgeUpdateHandler using the specified event that - * an update is starting. - * - * @param evt the BridgeUpdateHandler event - */ - protected void fireBridgeUpdateStarting(BridgeUpdateEvent evt) { - if (handler != null) { - evt.setHandlerKey(handlerKey); - handler.bridgeUpdateStarting(evt); - } - } - - /** - * Notifies the BridgeUpdateHandler using the specified event that - * an update is complete. - * - * @param evt the BridgeUpdateHandler event - */ - protected void fireBridgeUpdateCompleted(BridgeUpdateEvent evt) { - if (handler != null) { - evt.setHandlerKey(handlerKey); - handler.bridgeUpdateCompleted(evt); - } } } 1.8 +1 -81 xml-batik/sources/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java Index: AbstractSVGGradientElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/AbstractSVGGradientElementBridge.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- AbstractSVGGradientElementBridge.java 7 Mar 2002 16:56:52 -0000 1.7 +++ AbstractSVGGradientElementBridge.java 20 Mar 2002 16:34:43 -0000 1.8 @@ -33,23 +33,11 @@ * Bridge class for vending gradients. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: AbstractSVGGradientElementBridge.java,v 1.7 2002/03/07 16:56:52 tkormann Exp $ + * @version $Id: AbstractSVGGradientElementBridge.java,v 1.8 2002/03/20 16:34:43 tkormann Exp $ */ public abstract class AbstractSVGGradientElementBridge extends AbstractSVGBridge implements PaintBridge, ErrorConstants { - protected BridgeContext ctx; - - protected Element paintElement; - - protected Element paintedElement; - - protected GraphicsNode paintedNode; - - protected float opacity; - - protected Paint paint; - /** * Constructs a new AbstractSVGGradientElementBridge. */ @@ -125,26 +113,6 @@ colors, offsets, ctx); - - if (ctx.isDynamic()) { - if (handler == null) { // quick hack to fix dynamic - this.handler = ctx.getCurrentBridgeUpdateHandler(); - this.handlerKey = ctx.getCurrentBridgeUpdateHandlerKey(); - - this.ctx = ctx; - this.paintElement = paintElement; - this.paintedElement = paintedElement; - this.paintedNode = paintedNode; - this.opacity = opacity; - - ((EventTarget)paintElement).addEventListener - ("DOMAttrModified", - new DOMAttrModifiedEventListener(), - false); - } - this.paint = paint; - } - return paint; } @@ -171,54 +139,6 @@ Color [] colors, float [] offsets, BridgeContext ctx); - // dynamic support - - /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - if (attrName.equals(SVG_GRADIENT_TRANSFORM_ATTRIBUTE) || - attrName.equals(SVG_OFFSET_ATTRIBUTE) || // <stop> attribute - attrName.equals(SVG_SPREAD_METHOD_ATTRIBUTE)) { - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - be.setOldValue(paint); - fireBridgeUpdateStarting(be); - this.paint = createPaint - (ctx, paintElement, paintedElement, paintedNode, opacity); - be.setNewValue(paint); - fireBridgeUpdateCompleted(be); - } else { - System.out.println("Unsupported attribute modification: "+attrName+ - " on "+paintElement.getLocalName()); - } - } - - /** - * The listener class for 'DOMAttrModified' event. - */ - protected class DOMAttrModifiedEventListener implements EventListener { - - /** - * Handles 'DOMAttrModfied' events and deleguates to the - * 'handleDOMAttrModifiedEvent' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - Element e = (Element)evt.getTarget(); - // <!> FIXME: need to check if e is a stop - // check if an attribute has changed on the gradient or on a stop - if (e != paintElement && e.getParentNode() != paintElement) { - return; - } - handleDOMAttrModifiedEvent((MutationEvent)evt); - } - } // convenient methods 1.6 +1 -17 xml-batik/sources/org/apache/batik/bridge/Bridge.java Index: Bridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/Bridge.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Bridge.java 12 Feb 2002 15:14:37 -0000 1.5 +++ Bridge.java 20 Mar 2002 16:34:43 -0000 1.6 @@ -14,7 +14,7 @@ * according to an Element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: Bridge.java,v 1.5 2002/02/12 15:14:37 tkormann Exp $ + * @version $Id: Bridge.java,v 1.6 2002/03/20 16:34:43 tkormann Exp $ */ public interface Bridge { @@ -34,20 +34,4 @@ * Returns a new instance of this bridge. */ Bridge getInstance(); - - /** - * Returns the handler that is called each time this bridge - * updates its GVT product. - */ - BridgeUpdateHandler getBridgeUpdateHandler(); - - /** - * Sets the handler that is used to track each update of this - * bridge's GVT product. - * - * @param handler the handler to call - * @param handlerKey a private key the handler might use when it registers - */ - void setBridgeUpdateHandler(BridgeUpdateHandler handler, int handlerKey); - } 1.42 +135 -29 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.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- BridgeContext.java 18 Mar 2002 10:28:19 -0000 1.41 +++ BridgeContext.java 20 Mar 2002 16:34:43 -0000 1.42 @@ -26,11 +26,15 @@ import org.apache.batik.css.engine.CSSContext; import org.apache.batik.css.engine.CSSEngine; +import org.apache.batik.css.engine.CSSEngineEvent; +import org.apache.batik.css.engine.CSSEngineListener; import org.apache.batik.css.engine.SystemColorSupport; import org.apache.batik.css.engine.value.Value; +import org.apache.batik.dom.svg.SVGContext; import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.dom.svg.SVGOMDocument; +import org.apache.batik.dom.svg.SVGOMElement; import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.TextPainter; @@ -41,6 +45,11 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.events.Event; +import org.w3c.dom.events.EventListener; +import org.w3c.dom.events.EventTarget; +import org.w3c.dom.events.MutationEvent; import org.w3c.dom.svg.SVGDocument; import org.apache.batik.gvt.filter.GraphicsNodeRableFactory; @@ -57,7 +66,7 @@ * a SVG DOM tree such as the current viewport or the user agent. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: BridgeContext.java,v 1.41 2002/03/18 10:28:19 hillion Exp $ + * @version $Id: BridgeContext.java,v 1.42 2002/03/20 16:34:43 tkormann Exp $ */ public class BridgeContext implements ErrorConstants, CSSContext { @@ -98,11 +107,6 @@ protected List viewportStack = new LinkedList(); /** - * The BridgeUpdateHandler stack. Used in building time. - */ - protected List bridgeUpdateHandlerStack = new LinkedList(); - - /** * The user agent. */ protected UserAgent userAgent; @@ -704,45 +708,147 @@ } } - // dynamic support + // dynamic support ///////////////////////////////////////////////////////// - public void pushBridgeUpdateHandler(BridgeUpdateHandler handler) { - bridgeUpdateHandlerStack.add(0, new BridgeUpdateHandlerInfo(handler)); + protected EventListener domAttrModifiedEventListener; + protected EventListener domNodeInsertedEventListener; + protected EventListener domNodeRemovedEventListener; + protected CSSEngineListener cssPropertiesChangedListener; + + /** + * Adds EventListeners to the DOM and CSSEngineListener to the + * CSSEngine to handle any modifications on the DOM tree or style + * properties and update the GVT tree in response. + */ + public void addDOMListeners() { + domAttrModifiedEventListener = new DOMAttrModifiedEventListener(); + EventTarget evtTarget = (EventTarget)document; + evtTarget.addEventListener("DOMAttrModified", + domAttrModifiedEventListener, + true); + domNodeInsertedEventListener = new DOMNodeInsertedEventListener(); + evtTarget.addEventListener("DOMNodeInserted", + domNodeInsertedEventListener, + true); + domNodeRemovedEventListener = new DOMNodeRemovedEventListener(); + evtTarget.addEventListener("DOMNodeRemoved", + domNodeRemovedEventListener, + true); + SVGOMDocument svgDocument = (SVGOMDocument)document; + CSSEngine cssEngine = svgDocument.getCSSEngine(); + cssPropertiesChangedListener = new CSSPropertiesChangedListener(); + cssEngine.addCSSEngineListener(cssPropertiesChangedListener); } - public void setCurrentBridgeUpdateHandlerKey(int handlerKey) { - BridgeUpdateHandlerInfo info = - (BridgeUpdateHandlerInfo)bridgeUpdateHandlerStack.get(0); - info.handlerKey = handlerKey; + /** + * Disposes this BridgeContext. + */ + public void dispose() { + EventTarget evtTarget = (EventTarget)document; + evtTarget.removeEventListener("DOMAttrModified", + domAttrModifiedEventListener, + true); + evtTarget.removeEventListener("DOMNodeInserted", + domNodeInsertedEventListener, + true); + evtTarget.removeEventListener("DOMNodeRemoved", + domNodeRemovedEventListener, + true); + + SVGOMDocument svgDocument = (SVGOMDocument)document; + CSSEngine cssEngine = svgDocument.getCSSEngine(); + cssEngine.removeCSSEngineListener(cssPropertiesChangedListener); } - public BridgeUpdateHandler getCurrentBridgeUpdateHandler() { - BridgeUpdateHandlerInfo info = - (BridgeUpdateHandlerInfo)bridgeUpdateHandlerStack.get(0); - return info.handler; + /** + * Returns the SVGContext associated to the specified Node or null if any. + */ + protected static SVGContext getSVGContext(Node node) { + if (node instanceof SVGOMElement) { + return ((SVGOMElement)node).getSVGContext(); + } else { + return null; + } } - public int getCurrentBridgeUpdateHandlerKey() { - BridgeUpdateHandlerInfo info = - (BridgeUpdateHandlerInfo)bridgeUpdateHandlerStack.get(0); - return info.handlerKey; + /** + * Returns the SVGContext associated to the specified Node or null if any. + */ + protected static BridgeUpdateHandler getBridgeUpdateHandler(Node node) { + SVGContext ctx = getSVGContext(node); + return (ctx == null) ? null : (BridgeUpdateHandler)ctx; } - public void popBridgeUpdateHandler() { - bridgeUpdateHandlerStack.remove(0); + /** + * The DOM EventListener invoked when an attribute is modified. + */ + protected class DOMAttrModifiedEventListener implements EventListener { + + /** + * Handles 'DOMAttrModified' event type. + */ + public void handleEvent(Event evt) { + Node node = (Node)evt.getTarget(); + BridgeUpdateHandler h = getBridgeUpdateHandler(node); + if (h != null) { + h.handleDOMAttrModifiedEvent((MutationEvent)evt); + } + } } - protected static class BridgeUpdateHandlerInfo { + /** + * The DOM EventListener invoked when a node is added. + */ + protected class DOMNodeInsertedEventListener implements EventListener { + + /** + * Handles 'DOMNodeInserted' event type. + */ + public void handleEvent(Event evt) { + MutationEvent me = (MutationEvent)evt; + BridgeUpdateHandler h = getBridgeUpdateHandler(me.getRelatedNode()); + if (h != null) { + h.handleDOMNodeInsertedEvent(me); + } + } + } - protected BridgeUpdateHandler handler; - protected int handlerKey; + /** + * The DOM EventListener invoked when a node is removed. + */ + protected class DOMNodeRemovedEventListener implements EventListener { - public BridgeUpdateHandlerInfo(BridgeUpdateHandler handler) { - this.handler = handler; + /** + * Handles 'DOMNodeRemoved' event type. + */ + public void handleEvent(Event evt) { + Node node = (Node)evt.getTarget(); + BridgeUpdateHandler h = getBridgeUpdateHandler(node); + if (h != null) { + h.handleDOMNodeRemovedEvent((MutationEvent)evt); + } + } + } + + /** + * The CSSEngineListener invoked when CSS properties are modified + * on a particular element. + */ + protected class CSSPropertiesChangedListener implements CSSEngineListener { + + /** + * Handles CSSEngineEvent that describes the CSS properties + * that have changed on a particular element. + */ + public void propertiesChanged(CSSEngineEvent evt) { + SVGContext ctx = getSVGContext(evt.getElement()); + if (ctx != null && (ctx instanceof BridgeUpdateHandler)) { + ((BridgeUpdateHandler)ctx).handleCSSEngineEvent(evt); + } } } - // CSS context ////////////////////////////////// + // CSS context //////////////////////////////////////////////////////////// /** * Returns the Value corresponding to the given system color. 1.3 +20 -11 xml-batik/sources/org/apache/batik/bridge/BridgeUpdateHandler.java Index: BridgeUpdateHandler.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeUpdateHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BridgeUpdateHandler.java 15 Feb 2002 14:58:44 -0000 1.2 +++ BridgeUpdateHandler.java 20 Mar 2002 16:34:43 -0000 1.3 @@ -8,27 +8,36 @@ package org.apache.batik.bridge; +import org.apache.batik.css.engine.CSSEngineEvent; +import org.w3c.dom.events.MutationEvent; + /** - * Interface for objects interested in being notified of updates - * by a <tt>Bridge</tt>. + * Interface for objects interested in being notified of updates. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: BridgeUpdateHandler.java,v 1.2 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: BridgeUpdateHandler.java,v 1.3 2002/03/20 16:34:43 tkormann Exp $ */ public interface BridgeUpdateHandler { /** - * Invoked when a bridge update starts. - * - * @param evt the evt that describes the incoming update + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. + */ + void handleDOMAttrModifiedEvent(MutationEvent evt); + + /** + * Invoked when an MutationEvent of type 'DOMNodeInserted' is fired. */ - void bridgeUpdateStarting(BridgeUpdateEvent evt); + void handleDOMNodeInsertedEvent(MutationEvent evt); /** - * Invoked when a bridge update ends. - * - * @param evt the evt that describes the update + * Invoked when an MutationEvent of type 'DOMNodeRemoved' is fired. */ - void bridgeUpdateCompleted(BridgeUpdateEvent evt); + void handleDOMNodeRemovedEvent(MutationEvent evt); + + /** + * Invoked when an CSSEngineEvent is fired. + */ + void handleCSSEngineEvent(CSSEngineEvent evt); + } 1.19 +4 -1 xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java Index: GVTBuilder.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/GVTBuilder.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- GVTBuilder.java 18 Mar 2002 10:28:19 -0000 1.18 +++ GVTBuilder.java 20 Mar 2002 16:34:43 -0000 1.19 @@ -30,7 +30,7 @@ * This class is responsible for creating a GVT tree using an SVG DOM tree. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: GVTBuilder.java,v 1.18 2002/03/18 10:28:19 hillion Exp $ + * @version $Id: GVTBuilder.java,v 1.19 2002/03/20 16:34:43 tkormann Exp $ */ public class GVTBuilder implements SVGConstants { @@ -86,7 +86,10 @@ // <!> FIXME: TO BE REMOVED if (ctx.isDynamic()) { + // register GVT listeners for AWT event support BridgeEventSupport.addGVTListener(ctx, svgElement); + // register DOM listeners for dynamic support + ctx.addDOMListeners(); } return rootNode; } 1.5 +1 -11 xml-batik/sources/org/apache/batik/bridge/PaintServer.java Index: PaintServer.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/PaintServer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- PaintServer.java 18 Mar 2002 10:28:19 -0000 1.4 +++ PaintServer.java 20 Mar 2002 16:34:43 -0000 1.5 @@ -52,15 +52,11 @@ * Paint using the ShapePainter interface. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: PaintServer.java,v 1.4 2002/03/18 10:28:19 hillion Exp $ + * @version $Id: PaintServer.java,v 1.5 2002/03/20 16:34:43 tkormann Exp $ */ public abstract class PaintServer implements SVGConstants, CSSConstants, ErrorConstants { - public static final int KEY_STROKE = 1; - - public static final int KEY_FILL = 2; - /** * No instance of this class is required. */ @@ -148,13 +144,7 @@ ShapeNode node, BridgeContext ctx) { - if (ctx.isDynamic()) { - ctx.setCurrentBridgeUpdateHandlerKey(KEY_FILL); - } Paint fillPaint = convertFillPaint(e, node, ctx); - if (ctx.isDynamic()) { - ctx.setCurrentBridgeUpdateHandlerKey(KEY_STROKE); - } Paint strokePaint = convertStrokePaint(e, node, ctx); Shape shape = node.getShape(); 1.8 +4 -9 xml-batik/sources/org/apache/batik/bridge/SVGCircleElementBridge.java Index: SVGCircleElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGCircleElementBridge.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SVGCircleElementBridge.java 15 Feb 2002 14:58:44 -0000 1.7 +++ SVGCircleElementBridge.java 20 Mar 2002 16:34:43 -0000 1.8 @@ -22,7 +22,7 @@ * Bridge class for the <circle> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGCircleElementBridge.java,v 1.7 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGCircleElementBridge.java,v 1.8 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGCircleElementBridge extends SVGShapeElementBridge { @@ -95,26 +95,21 @@ shapeNode.setShape(new Ellipse2D.Float(x, y, w, w)); } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_CX_ATTRIBUTE) || attrName.equals(SVG_CY_ATTRIBUTE) || attrName.equals(SVG_R_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.8 +4 -9 xml-batik/sources/org/apache/batik/bridge/SVGEllipseElementBridge.java Index: SVGEllipseElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGEllipseElementBridge.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SVGEllipseElementBridge.java 15 Feb 2002 14:58:44 -0000 1.7 +++ SVGEllipseElementBridge.java 20 Mar 2002 16:34:43 -0000 1.8 @@ -22,7 +22,7 @@ * Bridge class for the <ellipse> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGEllipseElementBridge.java,v 1.7 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGEllipseElementBridge.java,v 1.8 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGEllipseElementBridge extends SVGShapeElementBridge { @@ -108,27 +108,22 @@ shapeNode.setShape(new Ellipse2D.Float(cx-rx, cy-ry, rx*2, ry*2)); } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_CX_ATTRIBUTE) || attrName.equals(SVG_CY_ATTRIBUTE) || attrName.equals(SVG_RX_ATTRIBUTE) || attrName.equals(SVG_RY_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.18 +7 -104 xml-batik/sources/org/apache/batik/bridge/SVGGElementBridge.java Index: SVGGElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGGElementBridge.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- SVGGElementBridge.java 18 Mar 2002 10:28:19 -0000 1.17 +++ SVGGElementBridge.java 20 Mar 2002 16:34:43 -0000 1.18 @@ -26,7 +26,7 @@ * Bridge class for the <g> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGGElementBridge.java,v 1.17 2002/03/18 10:28:19 hillion Exp $ + * @version $Id: SVGGElementBridge.java,v 1.18 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGGElementBridge extends AbstractGraphicsNodeBridge { @@ -57,13 +57,11 @@ * @return a graphics node that represents the specified element */ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { - // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage' - if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) { - return null; - } - CompositeGraphicsNode gn = (CompositeGraphicsNode)super.createGraphicsNode(ctx, e); + if (gn == null) { + return null; + } // 'color-rendering' RenderingHints hints = CSSUtilities.convertColorRendering(e, null); @@ -93,31 +91,12 @@ return true; } - // dynamic support - - /** - * This method is invoked during the build phase if the document - * is dynamic. The responsability of this method is to ensure that - * any dynamic modifications of the element this bridge is - * dedicated to, happen on its associated GVT product. - */ - protected void initializeDynamicSupport() { - super.initializeDynamicSupport(); - ((EventTarget)e).addEventListener("DOMNodeInserted", - new DOMNodeInsertedEventListener(), - false); - ((EventTarget)e).addEventListener("DOMNodeRemoved", - new DOMNodeRemovedEventListener(), - false); - } + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMNodeInserted events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMNodeInserted' is fired. */ - protected void handleDOMNodeInserted(MutationEvent evt) { - //System.out.println("handleDOMNodeInserted "+e.getLocalName()); + public void handleDOMNodeInsertedEvent(MutationEvent evt) { Element childElt = (Element)evt.getTarget(); // build the graphics node GVTBuilder builder = ctx.getGVTBuilder(); @@ -147,82 +126,6 @@ } // insert at the index ((CompositeGraphicsNode)node).add(index, childNode); - } - } - - /** - * Handles DOMNodeRemoved events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMNodeRemoved(MutationEvent evt) { - //System.out.println("handleDOMNodeRemoved "+e.getLocalName()); - Element childElt = (Element)evt.getTarget(); - if (!ctx.hasGraphicsNodeBridge(childElt)) { - return; // the removed element is not a graphic element - } - Node n = e.getFirstChild(); - Node lastChild = e.getLastChild(); - if (n == childElt) { - // remove first - ((CompositeGraphicsNode)node).remove(0); - } else if (lastChild == childElt) { - // remove last - CompositeGraphicsNode cgn = (CompositeGraphicsNode)node; - cgn.remove(cgn.size()-1); - } else { - // find the index of the GraphicsNode to remove - int index = 0; - while (n != lastChild && n != childElt) { - if (n.getNodeType() == Node.ELEMENT_NODE) { - if (ctx.hasGraphicsNodeBridge((Element)n)) { - index++; - } - } - n = n.getNextSibling(); - } - // remove at the index - ((CompositeGraphicsNode)node).remove(index); - } - } - - /** - * The listener class for 'DOMNodeInserted' event. - */ - protected class DOMNodeInsertedEventListener implements EventListener { - - /** - * Handles 'DOMNodeInserted' events and deleguates to the - * 'handleDOMNodeInserted' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - if (((MutationEvent)evt).getRelatedNode() != e) { - return; - } - handleDOMNodeInserted((MutationEvent)evt); - } - } - - /** - * The listener class for 'DOMNodeRemoved' event. - */ - protected class DOMNodeRemovedEventListener implements EventListener { - - /** - * Handles 'DOMNodeRemoved' events and deleguates to the - * 'handleDOMNodeRemoved' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - if (((MutationEvent)evt).getRelatedNode() != e) { - return; - } - handleDOMNodeRemoved((MutationEvent)evt); } } } 1.42 +18 -65 xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java Index: SVGImageElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGImageElementBridge.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- SVGImageElementBridge.java 18 Mar 2002 10:28:19 -0000 1.41 +++ SVGImageElementBridge.java 20 Mar 2002 16:34:43 -0000 1.42 @@ -24,8 +24,9 @@ import org.apache.batik.css.engine.value.Value; import org.apache.batik.dom.svg.SVGOMDocument; -import org.apache.batik.dom.util.XLinkSupport; +import org.apache.batik.dom.svg.SVGOMElement; import org.apache.batik.dom.svg.XMLBaseSupport; +import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.ext.awt.color.ICCColorSpaceExt; import org.apache.batik.ext.awt.image.renderable.ClipRable8Bit; import org.apache.batik.ext.awt.image.renderable.Filter; @@ -56,7 +57,7 @@ * Bridge class for the <image> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGImageElementBridge.java,v 1.41 2002/03/18 10:28:19 hillion Exp $ + * @version $Id: SVGImageElementBridge.java,v 1.42 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGImageElementBridge extends AbstractGraphicsNodeBridge { @@ -88,13 +89,11 @@ * @return a graphics node that represents the specified element */ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { - // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage' - if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) { + ImageNode imageNode = (ImageNode)super.createGraphicsNode(ctx, e); + if (imageNode == null) { return null; } - ImageNode imageNode = (ImageNode)super.createGraphicsNode(ctx, e); - // 'xlink:href' attribute - required String uriStr = XLinkSupport.getXLinkHref(e); if (uriStr.length() == 0) { @@ -153,40 +152,6 @@ } /** - * Builds using the specified BridgeContext and element, the - * specified graphics node. - * - * @param ctx the bridge context to use - * @param e the element that describes the graphics node to build - * @param node the graphics node to build - */ - public void buildGraphicsNode(BridgeContext ctx, - Element e, - GraphicsNode node) { - // 'opacity' - node.setComposite(CSSUtilities.convertOpacity(e)); - // 'filter' - node.setFilter(CSSUtilities.convertFilter(e, node, ctx)); - // 'mask' - node.setMask(CSSUtilities.convertMask(e, node, ctx)); - // 'clip-path' - node.setClip(CSSUtilities.convertClipPath(e, node, ctx)); - // 'pointer-events' - node.setPointerEventType(CSSUtilities.convertPointerEvents(e)); - - // bind the specified element and its associated graphics node if needed - if (ctx.isDynamic()) { - this.e = e; - this.node = node; - this.ctx = ctx; - initializeDynamicSupport(); - } - - // Handle children elements such as <title> - SVGUtilities.bridgeChildren(ctx, e); - } - - /** * Creates an <tt>ImageNode</tt>. */ protected GraphicsNode instantiateGraphicsNode() { @@ -208,10 +173,12 @@ * any dynamic modifications of the element this bridge is * dedicated to, happen on its associated GVT product. */ - protected void initializeDynamicSupport() { - ((EventTarget)e).addEventListener("DOMAttrModified", - new DOMAttrModifiedEventListener(), - false); + protected void initializeDynamicSupport(BridgeContext ctx, + Element e, + GraphicsNode node) { + this.e = e; + this.node = node; + this.ctx = ctx; // HACK due to the way images are represented in GVT ImageNode imgNode = (ImageNode)node; if (imgNode.getImage() instanceof RasterImageNode) { @@ -220,33 +187,19 @@ } else { ctx.bind(e, node); } + ((SVGOMElement)e).setSVGContext(this); } + // BridgeUpdateHandler implementation ////////////////////////////////// + /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - if (attrName.equals(SVG_X_ATTRIBUTE) || - attrName.equals(SVG_Y_ATTRIBUTE) || - attrName.equals(SVG_WIDTH_ATTRIBUTE) || - attrName.equals(SVG_HEIGHT_ATTRIBUTE)) { - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); - - // <!> FIXME: Not yet implemented - System.err.println("Not yet implemented"); - - fireBridgeUpdateCompleted(be); - } else { - super.handleDOMAttrModifiedEvent(evt); - } + public void handleDOMAttrModifiedEvent(MutationEvent evt) { + super.handleDOMAttrModifiedEvent(evt); } - // convenient methods + // convenient methods ////////////////////////////////////////////////// /** * Returns a GraphicsNode that represents an raster image in JPEG or PNG 1.8 +4 -9 xml-batik/sources/org/apache/batik/bridge/SVGLineElementBridge.java Index: SVGLineElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGLineElementBridge.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SVGLineElementBridge.java 15 Feb 2002 14:58:44 -0000 1.7 +++ SVGLineElementBridge.java 20 Mar 2002 16:34:43 -0000 1.8 @@ -21,7 +21,7 @@ * Bridge class for the <line> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGLineElementBridge.java,v 1.7 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGLineElementBridge.java,v 1.8 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGLineElementBridge extends SVGDecoratedShapeElementBridge { @@ -93,27 +93,22 @@ shapeNode.setShape(new Line2D.Float(x1, y1, x2, y2)); } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_X1_ATTRIBUTE) || attrName.equals(SVG_Y1_ATTRIBUTE) || attrName.equals(SVG_X2_ATTRIBUTE) || attrName.equals(SVG_Y2_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.7 +1 -36 xml-batik/sources/org/apache/batik/bridge/SVGLinearGradientElementBridge.java Index: SVGLinearGradientElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGLinearGradientElementBridge.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- SVGLinearGradientElementBridge.java 15 Feb 2002 14:58:44 -0000 1.6 +++ SVGLinearGradientElementBridge.java 20 Mar 2002 16:34:43 -0000 1.7 @@ -25,7 +25,7 @@ * Bridge class for the <linearGradient> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGLinearGradientElementBridge.java,v 1.6 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGLinearGradientElementBridge.java,v 1.7 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGLinearGradientElementBridge extends AbstractSVGGradientElementBridge { @@ -43,13 +43,6 @@ } /** - * Returns a new instance of this bridge. - */ - public Bridge getInstance() { - return new SVGLinearGradientElementBridge(); - } - - /** * Builds a linear gradient according to the specified parameters. * * @param paintElement the element that defines a Paint @@ -146,33 +139,5 @@ colorSpace, transform); } - } - - // dynamic support - - /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - if (attrName.equals(SVG_X1_ATTRIBUTE) || - attrName.equals(SVG_Y1_ATTRIBUTE) || - attrName.equals(SVG_X2_ATTRIBUTE) || - attrName.equals(SVG_Y2_ATTRIBUTE) || - attrName.equals(SVG_GRADIENT_UNITS_ATTRIBUTE)) { - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - be.setOldValue(paint); - fireBridgeUpdateStarting(be); - // <!> FIXME: create a new paint each time - this.paint = createPaint - (ctx, paintElement, paintedElement, paintedNode, opacity); - be.setNewValue(paint); - fireBridgeUpdateCompleted(be); - } else { - super.handleDOMAttrModifiedEvent(evt); - } } } 1.11 +4 -9 xml-batik/sources/org/apache/batik/bridge/SVGPathElementBridge.java Index: SVGPathElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPathElementBridge.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SVGPathElementBridge.java 15 Feb 2002 14:58:44 -0000 1.10 +++ SVGPathElementBridge.java 20 Mar 2002 16:34:43 -0000 1.11 @@ -24,7 +24,7 @@ * Bridge class for the <path> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGPathElementBridge.java,v 1.10 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGPathElementBridge.java,v 1.11 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGPathElementBridge extends SVGDecoratedShapeElementBridge { @@ -82,24 +82,19 @@ } } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_D_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.12 +4 -10 xml-batik/sources/org/apache/batik/bridge/SVGPolygonElementBridge.java Index: SVGPolygonElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPolygonElementBridge.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- SVGPolygonElementBridge.java 15 Feb 2002 14:58:44 -0000 1.11 +++ SVGPolygonElementBridge.java 20 Mar 2002 16:34:43 -0000 1.12 @@ -24,7 +24,7 @@ * Bridge class for the <polygon> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGPolygonElementBridge.java,v 1.11 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGPolygonElementBridge.java,v 1.12 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGPolygonElementBridge extends SVGDecoratedShapeElementBridge { @@ -81,24 +81,18 @@ } } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_POINTS_ATTRIBUTE)) { - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.11 +4 -10 xml-batik/sources/org/apache/batik/bridge/SVGPolylineElementBridge.java Index: SVGPolylineElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGPolylineElementBridge.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SVGPolylineElementBridge.java 15 Feb 2002 14:58:44 -0000 1.10 +++ SVGPolylineElementBridge.java 20 Mar 2002 16:34:43 -0000 1.11 @@ -24,7 +24,7 @@ * Bridge class for the <polyline> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGPolylineElementBridge.java,v 1.10 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGPolylineElementBridge.java,v 1.11 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGPolylineElementBridge extends SVGDecoratedShapeElementBridge { @@ -81,24 +81,18 @@ } } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_POINTS_ATTRIBUTE)) { - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.8 +1 -39 xml-batik/sources/org/apache/batik/bridge/SVGRadialGradientElementBridge.java Index: SVGRadialGradientElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGRadialGradientElementBridge.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- SVGRadialGradientElementBridge.java 15 Feb 2002 14:58:44 -0000 1.7 +++ SVGRadialGradientElementBridge.java 20 Mar 2002 16:34:43 -0000 1.8 @@ -25,7 +25,7 @@ * Bridge class for the <radialGradient> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGRadialGradientElementBridge.java,v 1.7 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGRadialGradientElementBridge.java,v 1.8 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGRadialGradientElementBridge extends AbstractSVGGradientElementBridge { @@ -44,13 +44,6 @@ } /** - * Returns a new instance of this bridge. - */ - public Bridge getInstance() { - return new SVGRadialGradientElementBridge(); - } - - /** * Builds a radial gradient according to the specified parameters. * * @param paintElement the element that defines a Paint @@ -160,37 +153,6 @@ spreadMethod, RadialGradientPaint.SRGB, transform); - } - } - - // dynamic support - - /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - if (attrName.equals(SVG_CX_ATTRIBUTE) || - attrName.equals(SVG_CY_ATTRIBUTE) || - attrName.equals(SVG_R_ATTRIBUTE) || - attrName.equals(SVG_FX_ATTRIBUTE) || - attrName.equals(SVG_FY_ATTRIBUTE) || - attrName.equals(SVG_GRADIENT_UNITS_ATTRIBUTE)) { - //long t0 = System.currentTimeMillis(); - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - be.setOldValue(paint); - fireBridgeUpdateStarting(be); - // <!> FIXME: create a new paint each time - this.paint = createPaint - (ctx, paintElement, paintedElement, paintedNode, opacity); - be.setNewValue(paint); - fireBridgeUpdateCompleted(be); - //long t1 = System.currentTimeMillis(); - //System.out.println("new grad: "+(t1-t0)); - } else { - super.handleDOMAttrModifiedEvent(evt); } } } 1.10 +4 -9 xml-batik/sources/org/apache/batik/bridge/SVGRectElementBridge.java Index: SVGRectElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGRectElementBridge.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- SVGRectElementBridge.java 15 Feb 2002 14:58:44 -0000 1.9 +++ SVGRectElementBridge.java 20 Mar 2002 16:34:43 -0000 1.10 @@ -24,7 +24,7 @@ * Bridge class for the <rect> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGRectElementBridge.java,v 1.9 2002/02/15 14:58:44 tkormann Exp $ + * @version $Id: SVGRectElementBridge.java,v 1.10 2002/03/20 16:34:43 tkormann Exp $ */ public class SVGRectElementBridge extends SVGShapeElementBridge { @@ -152,14 +152,12 @@ shapeNode.setShape(shape); } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { + public void handleDOMAttrModifiedEvent(MutationEvent evt) { String attrName = evt.getAttrName(); if (attrName.equals(SVG_X_ATTRIBUTE) || attrName.equals(SVG_Y_ATTRIBUTE) || @@ -168,13 +166,10 @@ attrName.equals(SVG_RX_ATTRIBUTE) || attrName.equals(SVG_RY_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); buildShape(ctx, e, (ShapeNode)node); if (((ShapeNode)node).getShape() == null) { // <!> FIXME: disable the rendering } - fireBridgeUpdateCompleted(be); } else { super.handleDOMAttrModifiedEvent(evt); } 1.27 +13 -82 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.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- SVGSVGElementBridge.java 18 Mar 2002 10:28:20 -0000 1.26 +++ SVGSVGElementBridge.java 20 Mar 2002 16:34:43 -0000 1.27 @@ -33,25 +33,9 @@ * Bridge class for the <svg> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGSVGElementBridge.java,v 1.26 2002/03/18 10:28:20 hillion Exp $ + * @version $Id: SVGSVGElementBridge.java,v 1.27 2002/03/20 16:34:43 tkormann Exp $ */ -public class SVGSVGElementBridge extends AbstractSVGBridge - implements GraphicsNodeBridge, ErrorConstants { - - /** - * The element that has been handled by this bridge. - */ - protected Element e; - - /** - * The graphics node constructed by this bridge. - */ - protected GraphicsNode node; - - /** - * The bridge context to use for dynamic updates. - */ - protected BridgeContext ctx; +public class SVGSVGElementBridge extends SVGGElementBridge { /** * Constructs a new bridge for the <svg> element. @@ -204,79 +188,26 @@ public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) { - // <!> FIXME: no clip, filter, mask or opacity ??? - - // we have built all children, we can close the viewport - ctx.closeViewport(e); - if (ctx.isDynamic()) { - this.e = e; - this.node = node; - this.ctx = ctx; - initializeDynamicSupport(); + initializeDynamicSupport(ctx, e, node); } + // Handle children elements such as <title> + SVGUtilities.bridgeChildren(ctx, e); + //super.buildGraphicsNode(ctx, e, node); + ctx.closeViewport(e); } - /** - * Returns true as the <svg> element is a container. - */ - public boolean isComposite() { - return true; - } - - // dynamic support - - /** - * This method is invoked during the build phase if the document - * is dynamic. The responsability of this method is to ensure that - * any dynamic modifications of the element this bridge is - * dedicated to, happen on its associated GVT product. - */ - protected void initializeDynamicSupport() { - ((EventTarget)e).addEventListener("DOMAttrModified", - new DOMAttrModifiedEventListener(), - false); - ctx.bind(e, node); - } - - /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); - System.out.println("Unsupported attribute modification: "+attrName+ - " on "+e.getLocalName()); - fireBridgeUpdateCompleted(be); - } - + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * The listener class for 'DOMAttrModified' event. + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected class DOMAttrModifiedEventListener implements EventListener { - - /** - * Handles 'DOMAttrModfied' events and deleguates to the - * 'handleDOMAttrModifiedEvent' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - if (evt.getTarget() != e) { - return; - } - handleDOMAttrModifiedEvent((MutationEvent)evt); - } - } + public void handleDOMAttrModifiedEvent(MutationEvent evt) { + // Don't call 'super' because there is no 'transform' attribute on <svg> + } /** - * A viewport for a SVGSVGElement. + * A viewport defined an <svg> element. */ public static class SVGSVGElementViewport implements Viewport { 1.16 +50 -57 xml-batik/sources/org/apache/batik/bridge/SVGShapeElementBridge.java Index: SVGShapeElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGShapeElementBridge.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- SVGShapeElementBridge.java 18 Mar 2002 10:28:20 -0000 1.15 +++ SVGShapeElementBridge.java 20 Mar 2002 16:34:43 -0000 1.16 @@ -11,26 +11,26 @@ import java.awt.RenderingHints; import java.util.Map; +import org.apache.batik.css.engine.CSSEngineEvent; +import org.apache.batik.css.engine.SVGCSSEngine; + import org.apache.batik.gvt.GraphicsNode; import org.apache.batik.gvt.ShapeNode; import org.apache.batik.gvt.ShapePainter; import org.w3c.dom.Element; - import org.apache.batik.gvt.CompositeShapePainter; import org.apache.batik.gvt.FillShapePainter; import org.apache.batik.gvt.StrokeShapePainter; import java.awt.Paint; import java.awt.Shape; - - /** * The base bridge class for shapes. Subclasses bridge <tt>ShapeNode</tt>. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGShapeElementBridge.java,v 1.15 2002/03/18 10:28:20 hillion Exp $ + * @version $Id: SVGShapeElementBridge.java,v 1.16 2002/03/20 16:34:43 tkormann Exp $ */ public abstract class SVGShapeElementBridge extends AbstractGraphicsNodeBridge { @@ -85,19 +85,8 @@ public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) { - // push 'this' as the current BridgeUpdateHandler for subbridges - if (ctx.isDynamic()) { - ctx.pushBridgeUpdateHandler(this); - } - ShapeNode shapeNode = (ShapeNode)node; shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode)); - - // 'this' is no more the current BridgeUpdateHandler - if (ctx.isDynamic()) { - ctx.popBridgeUpdateHandler(); - } - super.buildGraphicsNode(ctx, e, node); } @@ -145,60 +134,64 @@ return false; } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * Invoked when a bridge update is starting. + * This flag bit indicates if a new shape painter has already been created. + * Avoid creating one ShapePainter per CSS property change + */ + private boolean hasNewShapePainter; + + /** + * Invoked when CSS properties have changed on an element. * - * @param evt the evt that describes the incoming update + * @param evt the CSSEngine event that describes the update */ - public void bridgeUpdateStarting(BridgeUpdateEvent evt) { - // System.out.println("("+e.getLocalName()+" "+node+") update started "+evt.getHandlerKey()); + public void handleCSSEngineEvent(CSSEngineEvent evt) { + hasNewShapePainter = false; + super.handleCSSEngineEvent(evt); } /** - * Invoked when a bridge update is completed. - * - * @param evt the evt that describes the update + * Invoked for each CSS property that has changed. */ - public void bridgeUpdateCompleted(BridgeUpdateEvent evt) { - // System.out.println(">>> ("+e.getLocalName()+" "+node+") update completed "+ evt.getHandlerKey()); - switch(evt.getHandlerKey()) { - case PaintServer.KEY_FILL: { - Paint paint = (Paint)evt.getNewValue(); - ShapeNode shapeNode = (ShapeNode)node; - Shape shape = shapeNode.getShape(); - ShapePainter painter = shapeNode.getShapePainter(); - if (painter instanceof FillShapePainter) { - FillShapePainter fp = (FillShapePainter)painter; - fp.setPaint(paint); - shapeNode.setShapePainter(fp); - } else if (painter instanceof CompositeShapePainter) { - CompositeShapePainter cp = (CompositeShapePainter)painter; - FillShapePainter fp = (FillShapePainter)cp.getShapePainter(0); - fp.setPaint(paint); - shapeNode.setShapePainter(cp); + protected void handleCSSPropertyChanged(int property) { + switch(property) { + case SVGCSSEngine.FILL_INDEX: + case SVGCSSEngine.FILL_OPACITY_INDEX: + case SVGCSSEngine.STROKE_INDEX: + case SVGCSSEngine.STROKE_OPACITY_INDEX: + case SVGCSSEngine.STROKE_WIDTH_INDEX: + case SVGCSSEngine.STROKE_LINECAP_INDEX: + case SVGCSSEngine.STROKE_LINEJOIN_INDEX: + case SVGCSSEngine.STROKE_MITERLIMIT_INDEX: + case SVGCSSEngine.STROKE_DASHARRAY_INDEX: + case SVGCSSEngine.STROKE_DASHOFFSET_INDEX: { + if (!hasNewShapePainter) { + hasNewShapePainter = true; + ShapeNode shapeNode = (ShapeNode)node; + ShapePainter painter = + PaintServer.convertFillAndStroke(e, shapeNode, ctx); + shapeNode.setShapePainter(createShapePainter(ctx, e, shapeNode)); } break; - } case PaintServer.KEY_STROKE: { - Paint paint = (Paint)evt.getNewValue(); - ShapeNode shapeNode = (ShapeNode)node; - Shape shape = shapeNode.getShape(); - ShapePainter painter = shapeNode.getShapePainter(); - if (painter instanceof StrokeShapePainter) { - StrokeShapePainter sp = (StrokeShapePainter)painter; - sp.setPaint(paint); - shapeNode.setShapePainter(sp); - } else if (painter instanceof CompositeShapePainter) { - CompositeShapePainter cp = (CompositeShapePainter)painter; - StrokeShapePainter sp = - (StrokeShapePainter)cp.getShapePainter(1); - sp.setPaint(paint); - shapeNode.setShapePainter(cp); + } case SVGCSSEngine.SHAPE_RENDERING_INDEX: { + RenderingHints hints = node.getRenderingHints(); + hints = CSSUtilities.convertShapeRendering(e, hints); + if (hints != null) { + node.setRenderingHints(hints); } break; - } + } case SVGCSSEngine.COLOR_RENDERING_INDEX: { + RenderingHints hints = node.getRenderingHints(); + hints = CSSUtilities.convertColorRendering(e, hints); + if (hints != null) { + node.setRenderingHints(hints); + } + break; + } default: { + super.handleCSSPropertyChanged(property); + } } - // System.out.println("<<< ("+e.getLocalName()+" "+node+") update completed "+ evt.getHandlerKey()); } } 1.54 +23 -139 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.53 retrieving revision 1.54 diff -u -r1.53 -r1.54 --- SVGTextElementBridge.java 19 Mar 2002 09:25:40 -0000 1.53 +++ SVGTextElementBridge.java 20 Mar 2002 16:34:43 -0000 1.54 @@ -34,6 +34,7 @@ import java.util.Vector; import java.util.StringTokenizer; +import org.apache.batik.css.engine.CSSEngineEvent; import org.apache.batik.css.engine.CSSStylableElement; import org.apache.batik.css.engine.StyleMap; import org.apache.batik.css.engine.SVGCSSEngine; @@ -41,7 +42,9 @@ import org.apache.batik.css.engine.value.ListValue; import org.apache.batik.css.engine.value.Value; +import org.apache.batik.dom.svg.SVGContext; import org.apache.batik.dom.svg.SVGOMDocument; +import org.apache.batik.dom.svg.SVGOMElement; import org.apache.batik.dom.util.XLinkSupport; import org.apache.batik.dom.util.XMLSupport; import org.apache.batik.gvt.GraphicsNode; @@ -66,29 +69,13 @@ * * @author <a href="[EMAIL PROTECTED]">Stephane Hillion</a> * @author <a href="[EMAIL PROTECTED]">Bill Haneman</a> - * @version $Id: SVGTextElementBridge.java,v 1.53 2002/03/19 09:25:40 hillion Exp $ + * @version $Id: SVGTextElementBridge.java,v 1.54 2002/03/20 16:34:43 tkormann Exp $ */ -public class SVGTextElementBridge extends AbstractSVGBridge - implements BridgeUpdateHandler, GraphicsNodeBridge, ErrorConstants { +public class SVGTextElementBridge extends AbstractGraphicsNodeBridge { protected final static Integer ZERO = new Integer(0); /** - * The element that has been handled by this bridge. - */ - protected Element e; - - /** - * The graphics node constructed by this bridge. - */ - protected GraphicsNode node; - - /** - * The bridge context to use for dynamic updates. - */ - protected BridgeContext ctx; - - /** * Constructs a new bridge for the <text> element. */ public SVGTextElementBridge() {} @@ -115,40 +102,34 @@ * @return a graphics node that represents the specified element */ public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e) { - // 'requiredFeatures', 'requiredExtensions' and 'systemLanguage' - if (!SVGUtilities.matchUserAgent(e, ctx.getUserAgent())) { + TextNode node = (TextNode)super.createGraphicsNode(ctx, e); + if (node == null) { return null; } - - TextNode node = new TextNode(); - // specify the text painter to use if one has been provided in the - // bridge context + // specify the text painter to use if (ctx.getTextPainter() != null) { node.setTextPainter(ctx.getTextPainter()); } - - // 'transform' - String s = e.getAttributeNS(null, SVG_TRANSFORM_ATTRIBUTE); - if (s.length() != 0) { - node.setTransform - (SVGUtilities.convertTransform(e, SVG_TRANSFORM_ATTRIBUTE, s)); - } - // 'visibility' - node.setVisible(CSSUtilities.convertVisibility(e)); - // 'text-rendering' and 'color-rendering' RenderingHints hints = CSSUtilities.convertTextRendering(e, null); hints = CSSUtilities.convertColorRendering(e, hints); if (hints != null) { node.setRenderingHints(hints); } - node.setLocation(getLocation(ctx, e)); return node; } /** + * Creates the GraphicsNode depending on the GraphicsNodeBridge + * implementation. + */ + protected GraphicsNode instantiateGraphicsNode() { + return new TextNode(); + } + + /** * Returns the text node location according to the 'x' and 'y' * attributes of the specified text element. * @@ -175,6 +156,7 @@ y = UnitProcessor.svgVerticalCoordinateToUserSpace (st.nextToken(), SVG_Y_ATTRIBUTE, uctx); } + return new Point2D.Float(x, y); } @@ -189,14 +171,8 @@ public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node) { - - - // push 'this' as the current BridgeUpdateHandler for subbridges - if (ctx.isDynamic()) { - ctx.pushBridgeUpdateHandler(this); - } - e.normalize(); + AttributedString as = buildAttributedString(ctx, e); addGlyphPositionAttributes(as, e, ctx); ((TextNode)node).setAttributedCharacterIterator(as.getIterator()); @@ -209,26 +185,7 @@ addPaintAttributes(as, e, (TextNode)node, textDecoration, ctx); ((TextNode)node).setAttributedCharacterIterator(as.getIterator()); - // 'filter' - node.setFilter(CSSUtilities.convertFilter(e, node, ctx)); - // 'mask' - node.setMask(CSSUtilities.convertMask(e, node, ctx)); - // 'clip-path' - node.setClip(CSSUtilities.convertClipPath(e, node, ctx)); - // 'pointer-events' - node.setPointerEventType(CSSUtilities.convertPointerEvents(e)); - - if (ctx.isDynamic()) { - this.e = e; - this.node = node; - this.ctx = ctx; - initializeDynamicSupport(); - // 'this' is no more the current BridgeUpdateHandler - ctx.popBridgeUpdateHandler(); - } - - // Handle children elements such as <title> - SVGUtilities.bridgeChildren(ctx, e); + super.buildGraphicsNode(ctx, e, node); } /** @@ -238,86 +195,13 @@ return false; } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * This method is invoked during the build phase if the document - * is dynamic. The responsability of this method is to ensure that - * any dynamic modifications of the element this bridge is - * dedicated to, happen on its associated GVT product. - */ - protected void initializeDynamicSupport() { - ((EventTarget)e).addEventListener("DOMAttrModified", - new DOMAttrModifiedEventListener(), - false); - ctx.bind(e, node); - } - - /** - * Invoked when a bridge update is starting. - * - * @param evt the evt that describes the incoming update + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - public void bridgeUpdateStarting(BridgeUpdateEvent evt) { - System.out.println("("+e.getLocalName()+" "+node+") update started "+ - evt.getHandlerKey()); - } - - /** - * Invoked when a bridge update is completed. - * - * @param evt the evt that describes the update - */ - public void bridgeUpdateCompleted(BridgeUpdateEvent evt) { - System.out.println("("+e.getLocalName()+" "+node+") update completed "+ - evt.getHandlerKey()); - } - - /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - if (attrName.equals(SVG_TRANSFORM_ATTRIBUTE)) { - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); - - String s = evt.getNewValue(); - AffineTransform at = GraphicsNode.IDENTITY; - if (s.length() != 0) { - at = SVGUtilities.convertTransform - (e, SVG_TRANSFORM_ATTRIBUTE, s); - } - node.setTransform(at); - - fireBridgeUpdateCompleted(be); - } else { - System.out.println("Unsupported attribute modification: "+attrName+ - " on "+e.getLocalName()); - } - } - - - /** - * The listener class for 'DOMAttrModified' event. - */ - protected class DOMAttrModifiedEventListener implements EventListener { - - /** - * Handles 'DOMAttrModfied' events and deleguates to the - * 'handleDOMAttrModifiedEvent' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - if (evt.getTarget() != e) { - return; - } - handleDOMAttrModifiedEvent((MutationEvent)evt); - } + public void handleDOMAttrModifiedEvent(MutationEvent evt) { + super.handleDOMAttrModifiedEvent(evt); } // ----------------------------------------------------------------------- 1.24 +10 -98 xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java Index: SVGUseElementBridge.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUseElementBridge.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- SVGUseElementBridge.java 18 Mar 2002 10:28:20 -0000 1.23 +++ SVGUseElementBridge.java 20 Mar 2002 16:34:43 -0000 1.24 @@ -28,36 +28,15 @@ import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.css.ViewCSS; -import org.w3c.dom.events.Event; -import org.w3c.dom.events.EventListener; -import org.w3c.dom.events.EventTarget; import org.w3c.dom.events.MutationEvent; -import org.w3c.dom.svg.SVGSVGElement; -import org.w3c.dom.svg.SVGSymbolElement; /** * Bridge class for the <use> element. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: SVGUseElementBridge.java,v 1.23 2002/03/18 10:28:20 hillion Exp $ + * @version $Id: SVGUseElementBridge.java,v 1.24 2002/03/20 16:34:43 tkormann Exp $ */ -public class SVGUseElementBridge extends AbstractSVGBridge - implements GraphicsNodeBridge, ErrorConstants { - - /** - * The element that has been handled by this bridge. - */ - protected Element e; - - /** - * The graphics node constructed by this bridge. - */ - protected GraphicsNode node; - - /** - * The bridge context to use for dynamic updates. - */ - protected BridgeContext ctx; +public class SVGUseElementBridge extends AbstractGraphicsNodeBridge { /** * Constructs a new bridge for the <use> element. @@ -216,36 +195,11 @@ } /** - * Builds using the specified BridgeContext and element, the - * specified graphics node. - * - * @param ctx the bridge context to use - * @param e the element that describes the graphics node to build - * @param node the graphics node to build + * Creates the GraphicsNode depending on the GraphicsNodeBridge + * implementation. */ - public void buildGraphicsNode(BridgeContext ctx, - Element e, - GraphicsNode node) { - - // 'opacity' - node.setComposite(CSSUtilities.convertOpacity(e)); - // 'filter' - node.setFilter(CSSUtilities.convertFilter(e, node, ctx)); - // 'mask' - node.setMask(CSSUtilities.convertMask(e, node, ctx)); - // 'clip-path' - node.setClip(CSSUtilities.convertClipPath(e, node, ctx)); - - // bind the specified element and its associated graphics node if needed - if (ctx.isDynamic()) { - this.e = e; - this.node = node; - this.ctx = ctx; - initializeDynamicSupport(); - } - - // Handle children elements such as <title> - SVGUtilities.bridgeChildren(ctx, e); + protected GraphicsNode instantiateGraphicsNode() { + return null; // nothing to do, createGraphicsNode is fully overriden } /** @@ -255,54 +209,12 @@ return false; } - // dynamic support + // BridgeUpdateHandler implementation ////////////////////////////////// /** - * This method is invoked during the build phase if the document - * is dynamic. The responsability of this method is to ensure that - * any dynamic modifications of the element this bridge is - * dedicated to, happen on its associated GVT product. + * Invoked when an MutationEvent of type 'DOMAttrModified' is fired. */ - protected void initializeDynamicSupport() { - ((EventTarget)e).addEventListener("DOMAttrModified", - new DOMAttrModifiedEventListener(), - false); - ctx.bind(e, node); - } - - /** - * Handles DOMAttrModified events. - * - * @param evt the DOM mutation event - */ - protected void handleDOMAttrModifiedEvent(MutationEvent evt) { - String attrName = evt.getAttrName(); - - BridgeUpdateEvent be = new BridgeUpdateEvent(this); - fireBridgeUpdateStarting(be); - System.out.println("Unsupported attribute modification: "+attrName+ - " on "+e.getLocalName()); - fireBridgeUpdateCompleted(be); - } - - - /** - * The listener class for 'DOMAttrModified' event. - */ - protected class DOMAttrModifiedEventListener implements EventListener { - - /** - * Handles 'DOMAttrModfied' events and deleguates to the - * 'handleDOMAttrModifiedEvent' method any changes to the - * GraphicsNode if any. - * - * @param evt the DOM event - */ - public void handleEvent(Event evt) { - if (evt.getTarget() != e) { - return; - } - handleDOMAttrModifiedEvent((MutationEvent)evt); - } + public void handleDOMAttrModifiedEvent(MutationEvent evt) { + super.handleDOMAttrModifiedEvent(evt); } } 1.3 +3 -3 xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java Index: CSSEngine.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/css/engine/CSSEngine.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- CSSEngine.java 20 Mar 2002 10:42:26 -0000 1.2 +++ CSSEngine.java 20 Mar 2002 16:34:44 -0000 1.3 @@ -58,7 +58,7 @@ * This is the base class for all the CSS engines. * * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a> - * @version $Id: CSSEngine.java,v 1.2 2002/03/20 10:42:26 hillion Exp $ + * @version $Id: CSSEngine.java,v 1.3 2002/03/20 16:34:44 tkormann Exp $ */ public abstract class CSSEngine { @@ -1315,8 +1315,8 @@ * Fires a CSSEngineEvent, given a list of modified properties. */ protected void firePropertiesChangedEvent(Element target, int[] props) { - System.out.println("EVT props.length: " + props.length); - System.out.println(" target : " + target); + //System.out.println("EVT props.length: " + props.length); + //System.out.println(" target : " + target); CSSEngineListener[] ll = (CSSEngineListener[])listeners.toArray(LISTENER_ARRAY); 1.39 +9 -1 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.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- AbstractGraphicsNode.java 7 Mar 2002 22:07:44 -0000 1.38 +++ AbstractGraphicsNode.java 20 Mar 2002 16:34:44 -0000 1.39 @@ -54,7 +54,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> * @author <a href="mailto:[EMAIL PROTECTED]">Emmanuel Tissandier</a> * @author <a href="mailto:[EMAIL PROTECTED]">Thomas DeWeese</a> - * @version $Id: AbstractGraphicsNode.java,v 1.38 2002/03/07 22:07:44 deweese Exp $ + * @version $Id: AbstractGraphicsNode.java,v 1.39 2002/03/20 16:34:44 tkormann Exp $ */ public abstract class AbstractGraphicsNode implements GraphicsNode { @@ -264,7 +264,9 @@ * @param isVisible If true this node is visible */ public void setVisible(boolean isVisible) { + fireGraphicsNodeChangeStarted(); this.isVisible = isVisible; + fireGraphicsNodeChangeCompleted(); } /** @@ -297,11 +299,13 @@ * hint category. */ public void setRenderingHint(RenderingHints.Key key, Object value) { + fireGraphicsNodeChangeStarted(); if (this.hints == null) { this.hints = new RenderingHints(key, value); } else { hints.put(key, value); } + fireGraphicsNodeChangeCompleted(); } /** @@ -311,11 +315,13 @@ * @param hints the rendering hints to be set */ public void setRenderingHints(Map hints) { + fireGraphicsNodeChangeStarted(); if (this.hints == null) { this.hints = new RenderingHints(hints); } else { this.hints.putAll(hints); } + fireGraphicsNodeChangeCompleted(); } /** @@ -324,7 +330,9 @@ * @param newHints the new rendering hints of this node */ public void setRenderingHints(RenderingHints newHints) { + fireGraphicsNodeChangeStarted(); this.hints = newHints; + fireGraphicsNodeChangeCompleted(); } /** 1.5 +74 -55 xml-batik/test-references/samples/tests/spec/text/smallFonts.png <<Binary file>> 1.4 +127 -118 xml-batik/test-references/samples/tests/spec/text/textFeatures.png <<Binary file>>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]