You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by tk...@apache.org on 2002/04/22 11:45:49 UTC
cvs commit: xml-batik/sources/org/apache/batik/bridge BridgeEventSupport.java
tkormann 02/04/22 02:45:49
Modified: sources/org/apache/batik/bridge BridgeEventSupport.java
Log:
mouse events now work on tspan.
if you click on a tspan, the target of the event is the tspan and the
mouse events are propagated in the DOM, from the tspan.
Revision Changes Path
1.29 +55 -1 xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java
Index: BridgeEventSupport.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/BridgeEventSupport.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- BridgeEventSupport.java 18 Mar 2002 10:28:19 -0000 1.28
+++ BridgeEventSupport.java 22 Apr 2002 09:45:49 -0000 1.29
@@ -9,24 +9,39 @@
package org.apache.batik.bridge;
import java.awt.Point;
+
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
+
import java.io.IOException;
import java.io.StringReader;
+
+import java.text.AttributedCharacterIterator;
+
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.HashMap;
import org.apache.batik.gvt.GraphicsNode;
+import org.apache.batik.gvt.TextNode;
+
import org.apache.batik.gvt.event.EventDispatcher;
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.renderer.StrokingTextPainter;
+
+import org.apache.batik.gvt.text.GVTAttributedCharacterIterator;
+import org.apache.batik.gvt.text.TextHit;
+import org.apache.batik.gvt.text.TextSpanLayout;
+
import org.apache.batik.script.Interpreter;
import org.apache.batik.script.InterpreterException;
import org.apache.batik.script.InterpreterPool;
+
import org.apache.batik.util.RunnableQueue;
import org.apache.batik.util.SVGConstants;
@@ -54,7 +69,7 @@
* on the GVT root to propagate GVT events to the DOM.
* @author <a href="mailto:cjolif@ilog.fr>Christophe Jolif</a>
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: BridgeEventSupport.java,v 1.28 2002/03/18 10:28:19 hillion Exp $
+ * @version $Id: BridgeEventSupport.java,v 1.29 2002/04/22 09:45:49 tkormann Exp $
*/
class BridgeEventSupport implements SVGConstants {
@@ -171,6 +186,8 @@
public void mouseMoved(GraphicsNodeMouseEvent evt) {
dispatchMouseEvent("mousemove", evt, false);
}
+
+
private void dispatchMouseEvent(String eventType,
GraphicsNodeMouseEvent evt,
boolean cancelok) {
@@ -186,6 +203,32 @@
Element elmt = context.getElement(node);
if (elmt == null) // should not appeared if binding on
return;
+
+ // see whether or not the GraphicsNode is a TextNode
+ if (node instanceof TextNode) {
+ // handle tspan or textPath if any
+ TextNode textNode = (TextNode)node;
+ List list = textNode.getTextRuns();
+ for (int i = 0 ; i < list.size(); i++) {
+ StrokingTextPainter.TextRun run =
+ (StrokingTextPainter.TextRun)list.get(i);
+ AttributedCharacterIterator aci = run.getACI();
+ //printACI(aci);
+ TextSpanLayout layout = run.getLayout();
+ float x = (float)pos.getX();
+ float y = (float)pos.getY();
+ TextHit textHit = layout.hitTestChar(x, y);
+ if (textHit != null && layout.getBounds().contains(x, y)) {
+ Object delimiter = aci.getAttribute
+ (GVTAttributedCharacterIterator.TextAttribute.TEXT_COMPOUND_DELIMITER);
+ if (delimiter instanceof Element) {
+ elmt = (Element)delimiter;
+ break;
+ }
+ }
+ }
+ }
+
EventTarget target = (EventTarget)elmt;
// <!> TODO dispatch it only if pointers-event property ask for
short button = 1;
@@ -218,4 +261,15 @@
}
}
}
+ /*
+ public static void printACI(AttributedCharacterIterator aci) {
+ AttributedCharacterIterator newAci = (AttributedCharacterIterator)aci.clone();
+ newAci.first();
+ while (newAci.current() != AttributedCharacterIterator.DONE &&
+ newAci.getIndex() < newAci.getEndIndex()) {
+ System.out.print(newAci.current());
+ newAci.next();
+ }
+ System.out.println("\n---------------------------------------");
+ }*/
}
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org