tkormann 02/04/29 06:20:20 Modified: sources/org/apache/batik/bridge BridgeEventSupport.java SVGTextElementBridge.java sources/org/apache/batik/gvt ShapeNode.java TextNode.java sources/org/apache/batik/gvt/renderer StrokingTextPainter.java test-resources/org/apache/batik/test samplesRendering.xml Added: samples/tests/spec/linking anchorInsideText.svg Log: - fix a bug in containment test of TextNode - fix a bug in event propagation on tspan - add a new test for linking with tpsan and textPath BTW: 1. There is a bug in the SVG1.0 DTD, the test does not validate 2. there is a bug in the TextElementBridge (there is a missing work in my example) - CDATA section following textPath element Revision Changes Path 1.1 xml-batik/samples/tests/spec/linking/anchorInsideText.svg Index: anchorInsideText.svg =================================================================== <?xml version="1.0" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <!-- ====================================================================== --> <!-- Copyright (C) The Apache Software Foundation. All rights reserved. --> <!-- --> <!-- This software is published under the terms of the Apache Software --> <!-- License version 1.1, a copy of which has been included with this --> <!-- distribution in the LICENSE file. --> <!-- ====================================================================== --> <!-- ====================================================================== --> <!-- test anchor inside text --> <!-- --> <!-- @author [EMAIL PROTECTED] --> <!-- @version $Id: anchorInsideText.svg,v 1.1 2002/04/29 13:20:18 tkormann Exp $ --> <!-- ====================================================================== --> <?xml-stylesheet type="text/css" href="../../resources/style/test.css" ?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="body" width="450" height="500" viewBox="0 0 450 500"> <text class="title" x="50%" y="40">test anchor inside text <desc>Click in any of the links in the table. You should see a smilley.</desc></text> <g> <defs> <g id="smilley"> <g transform="scale(.8, .8) translate(-15,-15)"> <circle cx="15" cy="15" r="10"/> <circle cx="12" cy="12" r="1.5" fill="black"/> <circle cx="17" cy="12" r="1.5" fill="black"/> <path d="M 10 19 A 8 8 0 0 0 20 19" stroke="black" stroke-width="1"/> </g> </g> <g id="successBlack" fill="#aaa"> <use xlink:href="#smilley" /> </g> <g id="successCrimson" fill="crimson"> <use xlink:href="#smilley" /> </g> <g id="successOrange" fill="orange"> <use xlink:href="#smilley" /> </g> <g id="successBlue" fill="blue"> <use xlink:href="#smilley" /> </g> <path id="Path1" style="fill:none; stroke:blue;" d="M140 300 C140 150 280 150 280 300"/> </defs> <g transform="translate(5, 5) scale(.2)"> <use xlink:href="#successBlack"/> <a xlink:href="#svgView(viewBox(0,0,450,500))"> <text y="-11" font-size="2" fill="blue" text-decoration="underline" text-anchor="middle">Return to test</text> </a> </g> <g transform="translate(15, 5) scale(.2)"> <use xlink:href="#successCrimson"/> <a xlink:href="#svgView(viewBox(0,0,450,500))"> <text y="-11" font-size="2" fill="blue" text-decoration="underline" text-anchor="middle">Return to test</text> </a> </g> <g transform="translate(25, 5) scale(.2)"> <use xlink:href="#successOrange"/> <a xlink:href="#svgView(viewBox(0,0,450,500))"> <text y="-11" font-size="2" fill="blue" text-decoration="underline" text-anchor="middle">Return to test</text> </a> </g> <g transform="translate(35, 5) scale(.2)"> <use xlink:href="#successBlue"/> <a xlink:href="#svgView(viewBox(0,0,450,500))"> <text y="-11" font-size="2" fill="blue" text-decoration="underline" text-anchor="middle">Return to test</text> </a> </g> <view id="black" viewBox="3,2.5,4,4" /> <view id="crimson" viewBox="13,2.5,4,4" /> <view id="orange" viewBox="23,2.5,4,4" /> <view id="blue" viewBox="33,2.5,4,4" /> <!-- ################################################## --> <a xlink:href="#black"> <text x="50" y="100">This is simple text under the text element <a xlink:href="#crimson"><tspan fill="crimson">and here is a simple tspan </tspan></a> and <tspan x="50" dy="1.1em" fill="orange"><a xlink:href="#orange">some more with nested <a xlink:href="#blue"><tspan fill="blue"> tspan </tspan></a>and more...</a></tspan> </text> </a> <!-- ################################################## --> <g transform="translate(0 300)" > <a xlink:href="#black"> <text x="50" y="100">This is text with transform <a xlink:href="#crimson"><tspan fill="crimson">and here is a simple tspan </tspan></a> and <tspan x="50" dy="1.1em" fill="orange"><a xlink:href="#orange">some more with nested <a xlink:href="#blue"><tspan fill="blue"> tspan </tspan></a> and more...</a></tspan> </text> </a> </g> <!-- ################################################## --> <use xlink:href="#Path1" /> <a xlink:href="#black"> <text x="50" y="300" fill="black">This is simple <textPath fill="crimson" xlink:href="#Path1" startOffset="0%"><a xlink:href="#crimson">text on a path <a xlink:href="#orange"><tspan fill="orange" dy="-10">with nested tspan</tspan></a> <tspan dy="10"> and dy attributes </tspan></a></textPath> <tspan fill="blue" dx="10"><a xlink:href="#blue">all with</a></tspan> different links. </text> </a> </g> </svg> 1.34 +9 -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.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- BridgeEventSupport.java 23 Apr 2002 07:18:31 -0000 1.33 +++ BridgeEventSupport.java 29 Apr 2002 13:20:18 -0000 1.34 @@ -11,7 +11,9 @@ import java.awt.Point; import java.awt.geom.AffineTransform; +import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; import java.text.AttributedCharacterIterator; @@ -48,7 +50,7 @@ * fowarding them to the DOM as regular DOM MouseEvent. * * @author <a href="mailto:[EMAIL PROTECTED]>Thierry Kormann</a> - * @version $Id: BridgeEventSupport.java,v 1.33 2002/04/23 07:18:31 tkormann Exp $ + * @version $Id: BridgeEventSupport.java,v 1.34 2002/04/29 13:20:18 tkormann Exp $ */ public class BridgeEventSupport implements SVGConstants { @@ -314,9 +316,15 @@ Element target = context.getElement(node); // Lookup inside the text element children to see if the target // is a tspan or textPath + if (target != null && node instanceof TextNode) { TextNode textNode = (TextNode)node; List list = textNode.getTextRuns(); + // place coords in text node coordinate system + try { + node.getGlobalTransform().createInverse().transform(coords, coords); + } catch (NoninvertibleTransformException ex) { + } for (int i = 0 ; i < list.size(); i++) { StrokingTextPainter.TextRun run = (StrokingTextPainter.TextRun)list.get(i); 1.65 +4 -4 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.64 retrieving revision 1.65 diff -u -r1.64 -r1.65 --- SVGTextElementBridge.java 27 Apr 2002 22:41:57 -0000 1.64 +++ SVGTextElementBridge.java 29 Apr 2002 13:20:18 -0000 1.65 @@ -68,7 +68,7 @@ * * @author <a href="[EMAIL PROTECTED]">Stephane Hillion</a> * @author <a href="[EMAIL PROTECTED]">Bill Haneman</a> - * @version $Id: SVGTextElementBridge.java,v 1.64 2002/04/27 22:41:57 deweese Exp $ + * @version $Id: SVGTextElementBridge.java,v 1.65 2002/04/29 13:20:18 tkormann Exp $ */ public class SVGTextElementBridge extends AbstractGraphicsNodeBridge { @@ -613,11 +613,11 @@ n = n.getNextSibling()) { last = n.getNextSibling() == null; - + int lastChar = asb.getLastChar(); stripFirst = !preserve && first && (top || lastChar == ' ' || lastChar == -1); - + switch (n.getNodeType()) { case Node.ELEMENT_NODE: if (n.getNamespaceURI() != SVG_NAMESPACE_URI) { @@ -626,7 +626,7 @@ nodeElement = (Element)n; String ln = n.getLocalName(); - + if (ln.equals(SVG_TSPAN_TAG) || ln.equals(SVG_ALT_GLYPH_TAG)) { fillAttributedStringBuffer(ctx, 1.16 +3 -1 xml-batik/sources/org/apache/batik/gvt/ShapeNode.java Index: ShapeNode.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/ShapeNode.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- ShapeNode.java 6 Feb 2002 17:52:37 -0000 1.15 +++ ShapeNode.java 29 Apr 2002 13:20:19 -0000 1.16 @@ -20,7 +20,7 @@ * A graphics node that represents a shape. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: ShapeNode.java,v 1.15 2002/02/06 17:52:37 deweese Exp $ + * @version $Id: ShapeNode.java,v 1.16 2002/04/29 13:20:19 tkormann Exp $ */ public class ShapeNode extends AbstractGraphicsNode { @@ -160,6 +160,8 @@ * @param p the specified Point2D in the user space */ public boolean contains(Point2D p) { + // <!> FIXME: should put this code in TextPaint somewhere, + // as pointer-events support Rectangle2D b = getBounds(); if (b == null || !b.contains(p)) { return false; 1.24 +59 -1 xml-batik/sources/org/apache/batik/gvt/TextNode.java Index: TextNode.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/TextNode.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- TextNode.java 23 Jan 2002 14:14:08 -0000 1.23 +++ TextNode.java 29 Apr 2002 13:20:19 -0000 1.24 @@ -30,12 +30,14 @@ import org.apache.batik.gvt.text.AttributedCharacterSpanIterator; import org.apache.batik.gvt.text.GVTAttributedCharacterIterator; import org.apache.batik.gvt.text.Mark; +import org.apache.batik.gvt.text.TextHit; +import org.apache.batik.gvt.text.TextSpanLayout; /** * A graphics node that represents text. * * @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a> - * @version $Id: TextNode.java,v 1.23 2002/01/23 14:14:08 deweese Exp $ + * @version $Id: TextNode.java,v 1.24 2002/04/29 13:20:19 tkormann Exp $ */ public class TextNode extends AbstractGraphicsNode implements Selectable { @@ -378,6 +380,62 @@ } // Paint the text textPainter.paint(this, g2d); + } + + // + // Geometric methods + // + + /** + * Returns true if the specified Point2D is inside the boundary of this + * node, false otherwise. + * + * @param p the specified Point2D in the user space + */ + public boolean contains(Point2D p) { + // <!> FIXME: should put this code in TextPaint somewhere, + // as pointer-events support - same problem with pointer-events + // and ShapeNode + if (!super.contains(p)) { + return false; + } + List list = getTextRuns(); + // place coords in text node coordinate system + for (int i = 0 ; i < list.size(); i++) { + StrokingTextPainter.TextRun run = + (StrokingTextPainter.TextRun)list.get(i); + AttributedCharacterIterator aci = run.getACI(); + TextSpanLayout layout = run.getLayout(); + float x = (float)p.getX(); + float y = (float)p.getY(); + TextHit textHit = layout.hitTestChar(x, y); + if (textHit != null && contains(p, layout.getBounds())) { + return true; + } + } + return false; + } + + protected boolean contains(Point2D p, Rectangle2D b) { + if (b == null || !b.contains(p)) { + return false; + } + switch(pointerEventType) { + case VISIBLE_PAINTED: + case VISIBLE_FILL: + case VISIBLE_STROKE: + case VISIBLE: + return isVisible; + case PAINTED: + case FILL: + case STROKE: + case ALL: + return true; + case NONE: + return false; + default: + return false; + } } /** 1.33 +1 -2 xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java Index: StrokingTextPainter.java =================================================================== RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/renderer/StrokingTextPainter.java,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- StrokingTextPainter.java 12 Apr 2002 14:36:48 -0000 1.32 +++ StrokingTextPainter.java 29 Apr 2002 13:20:19 -0000 1.33 @@ -61,7 +61,7 @@ * @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator * * @author <a href="[EMAIL PROTECTED]>Bill Haneman</a> - * @version $Id: StrokingTextPainter.java,v 1.32 2002/04/12 14:36:48 deweese Exp $ + * @version $Id: StrokingTextPainter.java,v 1.33 2002/04/29 13:20:19 tkormann Exp $ */ public class StrokingTextPainter extends BasicTextPainter { @@ -1535,7 +1535,6 @@ } return highlightedShape; } - // inner classes 1.66 +2 -1 xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml Index: samplesRendering.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/samplesRendering.xml,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- samplesRendering.xml 26 Apr 2002 08:48:53 -0000 1.65 +++ samplesRendering.xml 29 Apr 2002 13:20:20 -0000 1.66 @@ -8,7 +8,7 @@ <!-- ========================================================================= --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: samplesRendering.xml,v 1.65 2002/04/26 08:48:53 vhardy Exp $ --> +<!-- @version $Id: samplesRendering.xml,v 1.66 2002/04/29 13:20:20 tkormann Exp $ --> <!-- ========================================================================= --> <testSuite id="samplesRendering" name="samples and samples/test Rendering" class="org.apache.batik.test.svg.SamplesRenderingTest"> @@ -108,6 +108,7 @@ </testGroup> <testGroup id="tests.spec.linking"> + <test id="samples/tests/spec/linking/anchorInsideText.svg" /> <test id="samples/tests/spec/linking/anchor.svg" /> <test id="samples/tests/spec/linking/linkingTransform.svg" /> <test id="samples/tests/spec/linking/linkingViewBox.svg" />
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]