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 bi...@apache.org on 2001/02/02 15:13:17 UTC
cvs commit: xml-batik/sources/org/apache/batik/gvt/text TextLayoutAdapter.java
billh 01/02/02 06:13:17
Modified: sources/org/apache/batik/bridge SVGTextElementBridge.java
sources/org/apache/batik/gvt CompositeGraphicsNode.java
TextNode.java TextPainter.java
sources/org/apache/batik/gvt/renderer BasicTextPainter.java
sources/org/apache/batik/gvt/text TextLayoutAdapter.java
Log:
Fix for tref text selection.
Also a small change to CompositeGraphicsNode so that it exits
its child-painting loop when interrupted.
Revision Changes Path
1.8 +4 -2 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.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SVGTextElementBridge.java 2001/02/01 19:22:55 1.7
+++ SVGTextElementBridge.java 2001/02/02 14:13:13 1.8
@@ -66,7 +66,7 @@
* A factory for the <text> SVG element.
*
* @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
- * @version $Id: SVGTextElementBridge.java,v 1.7 2001/02/01 19:22:55 billh Exp $
+ * @version $Id: SVGTextElementBridge.java,v 1.8 2001/02/02 14:13:13 billh Exp $
*/
public class SVGTextElementBridge implements GraphicsNodeBridge, SVGConstants {
protected final static Map fonts = new HashMap(11);
@@ -333,6 +333,9 @@
as = createAttributedString(s, map, indexMap, preserve,
stripFirst, last && top);
if (as != null) {
+ // NOTE: we get position attributes from the
+ // surrounding text or tspan node, not the tref
+ // link target
addGlyphPositionAttributes(
as, true, indexMap, ctx, nodeElement);
stripLast = !preserve &&
@@ -513,7 +516,6 @@
// glyph and sub-element positions
String s = element.getAttributeNS(null, SVG_X_ATTRIBUTE);
- //System.out.println("X: "+s);
if (s.length() != 0) {
float x[] = SVGUtilities.svgToUserSpaceArray(element,
SVG_X_ATTRIBUTE, s,
1.7 +4 -2 xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java
Index: CompositeGraphicsNode.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/CompositeGraphicsNode.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CompositeGraphicsNode.java 2001/02/01 16:41:56 1.6
+++ CompositeGraphicsNode.java 2001/02/02 14:13:14 1.7
@@ -32,7 +32,7 @@
* A CompositeGraphicsNode is a graphics node that can contain graphics nodes.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: CompositeGraphicsNode.java,v 1.6 2001/02/01 16:41:56 vhardy Exp $
+ * @version $Id: CompositeGraphicsNode.java,v 1.7 2001/02/02 14:13:14 billh Exp $
*/
public class CompositeGraphicsNode extends AbstractGraphicsNode
implements List {
@@ -124,7 +124,9 @@
}
try {
node.paint(g2d, rc);
- } catch (InterruptedException ie) { }
+ } catch (InterruptedException ie) {
+ break;
+ }
}
}
1.4 +5 -4 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TextNode.java 2001/01/24 16:03:32 1.3
+++ TextNode.java 2001/02/02 14:13:15 1.4
@@ -25,7 +25,7 @@
* A graphics node that represents text.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: TextNode.java,v 1.3 2001/01/24 16:03:32 tkormann Exp $
+ * @version $Id: TextNode.java,v 1.4 2001/02/02 14:13:15 billh Exp $
*/
public class TextNode extends AbstractGraphicsNode implements Selectable {
@@ -117,6 +117,7 @@
rc.getFontRenderContext());
} else {
// Don't cache if ACI is null
+ System.out.println("ACI is null for "+this);
return new Rectangle2D.Float(0, 0, 0, 0);
}
}
@@ -174,7 +175,7 @@
* @param the anchor of this node
*/
public boolean selectAt(double x, double y, GraphicsNodeRenderContext rc) {
- beginMark = rc.getTextPainter().selectAt(x, y, aci, rc);
+ beginMark = rc.getTextPainter().selectAt(x, y, aci, this, rc);
return true; // assume this always changes selection, for now.
}
@@ -183,7 +184,7 @@
* @param the anchor of this node
*/
public boolean selectTo(double x, double y, GraphicsNodeRenderContext rc) {
- Mark tmpMark = rc.getTextPainter().selectTo(x, y, beginMark, aci, rc);
+ Mark tmpMark = rc.getTextPainter().selectTo(x, y, beginMark, aci, this, rc);
boolean result = false;
if (tmpMark != endMark) {
@@ -199,7 +200,7 @@
* @param the anchor of this node
*/
public boolean selectAll(double x, double y, GraphicsNodeRenderContext rc) {
- endMark = rc.getTextPainter().selectAll(x, y, aci, rc);
+ endMark = rc.getTextPainter().selectAll(x, y, aci, this, rc);
beginMark = endMark;
return true;
}
1.9 +4 -4 xml-batik/sources/org/apache/batik/gvt/TextPainter.java
Index: TextPainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/TextPainter.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TextPainter.java 2001/01/22 16:37:37 1.8
+++ TextPainter.java 2001/02/02 14:13:15 1.9
@@ -21,7 +21,7 @@
* Renders the attributed character iterator of a <tt>TextNode</tt>.
*
* @author <a href="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
- * @version $Id: TextPainter.java,v 1.8 2001/01/22 16:37:37 billh Exp $
+ * @version $Id: TextPainter.java,v 1.9 2001/02/02 14:13:15 billh Exp $
*/
public interface TextPainter {
@@ -49,7 +49,7 @@
* implement hit testing and text selection.
*/
public Mark selectAt(double x, double y, AttributedCharacterIterator aci,
- GraphicsNodeRenderContext context);
+ TextNode node, GraphicsNodeRenderContext context);
/**
* Continues a text selection on a particular AttributedCharacterIterator,
@@ -65,7 +65,7 @@
*/
public Mark selectTo(double x, double y, Mark beginMark,
AttributedCharacterIterator aci,
- GraphicsNodeRenderContext context);
+ TextNode node, GraphicsNodeRenderContext context);
/**
* Select all of the text represented by an AttributedCharacterIterator,
@@ -81,7 +81,7 @@
*/
public Mark selectAll(double x, double y,
AttributedCharacterIterator aci,
- GraphicsNodeRenderContext context);
+ TextNode node, GraphicsNodeRenderContext context);
/*
* Get an array of index pairs corresponding to the indices within an
1.2 +26 -15 xml-batik/sources/org/apache/batik/gvt/renderer/BasicTextPainter.java
Index: BasicTextPainter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/renderer/BasicTextPainter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BasicTextPainter.java 2001/01/23 17:08:00 1.1
+++ BasicTextPainter.java 2001/02/02 14:13:16 1.2
@@ -39,7 +39,7 @@
*
* @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
* @author <a href="vincent.hardy@sun.com>Vincent Hardy</a>
- * @version $Id: BasicTextPainter.java,v 1.1 2001/01/23 17:08:00 tkormann Exp $
+ * @version $Id: BasicTextPainter.java,v 1.2 2001/02/02 14:13:16 billh Exp $
*/
public class BasicTextPainter implements TextPainter {
@@ -60,7 +60,8 @@
* works for J2SE base implementation of AttributeCharacterIterator
*/
- TextSpanLayout layout = getOffsetAdjustedTextLayout(aci, frc);
+ TextSpanLayout layout =
+ getOffsetAdjustedTextLayout(aci, node.getLocation(), frc);
layout.draw(g2d);
}
@@ -81,10 +82,11 @@
*/
public org.apache.batik.gvt.text.Mark selectAt(double x, double y,
AttributedCharacterIterator aci,
+ TextNode node,
GraphicsNodeRenderContext context) {
org.apache.batik.gvt.text.Mark
- newMark = hitTest(x, y, aci, context);
+ newMark = hitTest(x, y, aci, node, context);
cachedHit = null;
return newMark;
}
@@ -99,9 +101,10 @@
public org.apache.batik.gvt.text.Mark selectTo(double x, double y,
org.apache.batik.gvt.text.Mark beginMark,
AttributedCharacterIterator aci,
+ TextNode node,
GraphicsNodeRenderContext context) {
org.apache.batik.gvt.text.Mark newMark =
- hitTest(x, y, aci, context);
+ hitTest(x, y, aci, node, context);
return newMark;
}
@@ -113,9 +116,10 @@
*/
public org.apache.batik.gvt.text.Mark selectAll(double x, double y,
AttributedCharacterIterator aci,
+ TextNode node,
GraphicsNodeRenderContext context) {
org.apache.batik.gvt.text.Mark newMark =
- hitTest(x, y, aci, context);
+ hitTest(x, y, aci, node, context);
return newMark;
}
@@ -263,7 +267,8 @@
*/
public Rectangle2D getPaintedBounds(TextNode node,
FontRenderContext frc) {
- return getBounds(node, frc, true, true);
+ Rectangle2D r = getBounds(node, frc, true, true);
+ return r;
}
/*
@@ -282,8 +287,10 @@
boolean includeDecoration,
boolean includeStrokeWidth) {
- AttributedCharacterIterator aci = node.getAttributedCharacterIterator();
- TextSpanLayout layout = getOffsetAdjustedTextLayout(aci, context);
+ AttributedCharacterIterator aci =
+ node.getAttributedCharacterIterator();
+ TextSpanLayout layout =
+ getOffsetAdjustedTextLayout(aci, node.getLocation(), context);
Rectangle2D bounds;
@@ -301,7 +308,6 @@
bounds = layout.getBounds();
}
}
-
return bounds;
}
@@ -317,7 +323,8 @@
boolean includeDecoration) {
Shape outline;
AttributedCharacterIterator aci = node.getAttributedCharacterIterator();
- TextSpanLayout layout = getOffsetAdjustedTextLayout(aci, frc);
+ TextSpanLayout layout =
+ getOffsetAdjustedTextLayout(aci, node.getLocation(), frc);
outline = layout.getOutline();
@@ -392,7 +399,7 @@
return outline;
}
- /*
+ /*
* Note: this method only works if the layout is constructed
* from the entire "text chunk"! If there are multiple
* text chunks in this node, this code will fail.
@@ -400,15 +407,17 @@
*/
private TextSpanLayout getOffsetAdjustedTextLayout(
- AttributedCharacterIterator aci, FontRenderContext frc) {
+ AttributedCharacterIterator aci,
+ Point2D location,
+ FontRenderContext frc) {
TextSpanLayout layout = getTextLayoutFactory().createTextLayout(aci,
- new Point2D.Float(0f, 0f),
+ location,
new java.awt.font.FontRenderContext(
new AffineTransform(),
true,
true));
-
+
TextNode.Anchor anchor = (TextNode.Anchor) aci.getAttribute(
GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);
int anchorType = TextNode.Anchor.ANCHOR_START;
@@ -451,11 +460,13 @@
private org.apache.batik.gvt.text.Mark hitTest(
double x, double y, AttributedCharacterIterator aci,
+ TextNode node,
GraphicsNodeRenderContext context) {
FontRenderContext frc = context.getFontRenderContext();
- TextSpanLayout layout = getOffsetAdjustedTextLayout(aci, frc);
+ TextSpanLayout layout =
+ getOffsetAdjustedTextLayout(aci, node.getLocation(), frc);
TextHit textHit =
layout.hitTestChar((float) x, (float) y);
1.2 +32 -19 xml-batik/sources/org/apache/batik/gvt/text/TextLayoutAdapter.java
Index: TextLayoutAdapter.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/TextLayoutAdapter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TextLayoutAdapter.java 2001/01/23 17:08:10 1.1
+++ TextLayoutAdapter.java 2001/02/02 14:13:17 1.2
@@ -32,18 +32,20 @@
* @see org.apache.batik.gvt.TextPainter.
*
* @author <a href="bill.haneman@ireland.sun.com>Bill Haneman</a>
- * @version $Id: TextLayoutAdapter.java,v 1.1 2001/01/23 17:08:10 tkormann Exp $
+ * @version $Id: TextLayoutAdapter.java,v 1.2 2001/02/02 14:13:17 billh Exp $
*/
public class TextLayoutAdapter implements TextSpanLayout {
private TextLayout layout;
private AttributedCharacterIterator aci;
private Point2D offset;
+ private AffineTransform transform;
public TextLayoutAdapter(TextLayout layout, Point2D offset, AttributedCharacterIterator aci) {
this.layout = layout;
this.aci = aci;
this.offset = adjustOffset(offset);
+ this.transform = computeTransform();
}
/**
@@ -52,7 +54,15 @@
* @param g2d the Graphics2D to use
*/
public void draw(Graphics2D g2d) {
- layout.draw(g2d, (float) offset.getX(), (float) offset.getY());
+ AffineTransform t;
+ if (transform != null) {
+ t = g2d.getTransform();
+ g2d.transform(transform);
+ layout.draw(g2d, 0f, 0f);
+ g2d.setTransform(t);
+ } else {
+ layout.draw(g2d, 0f, 0f);
+ }
}
/**
@@ -72,6 +82,7 @@
*/
public void setOffset(Point2D offset) {
this.offset = offset;
+ this.transform = computeTransform();
}
/**
@@ -79,9 +90,7 @@
* by an AffineTransform.
*/
public Shape getOutline() {
- AffineTransform nt = AffineTransform.getTranslateInstance(
- offset.getX(), offset.getY());
- return layout.getOutline(nt);
+ return layout.getOutline(transform);
}
/**
@@ -103,20 +112,15 @@
if ((decorationType & DECORATION_OVERLINE) != 0) {
g.append(getOverlineShape(aci, layout), false);
}
- AffineTransform nt = AffineTransform.getTranslateInstance(
- offset.getX(), offset.getY());
- return nt.createTransformedShape(g);
+ return transform.createTransformedShape(g);
}
/**
* Returns the rectangular bounds of the completed glyph layout.
*/
public Rectangle2D getBounds() {
- Rectangle2D bounds = layout.getBounds();
- return new Rectangle2D.Double(bounds.getX()+offset.getX(),
- bounds.getY()+offset.getY(),
- bounds.getWidth(),
- bounds.getHeight());
+ Shape bounds = layout.getBounds();
+ return transform.createTransformedShape(bounds).getBounds2D();
}
/**
@@ -156,9 +160,7 @@
* @param end the index of the last glyph in the contiguous selection.
*/
public Shape getLogicalHighlightShape(int begin, int end) {
- AffineTransform nt = AffineTransform.getTranslateInstance(
- offset.getX(), offset.getY());
- return nt.createTransformedShape(
+ return transform.createTransformedShape(
layout.getLogicalHighlightShape(begin, end));
}
@@ -171,8 +173,13 @@
* @param y the y coordinate of the point to be tested.
*/
public TextHit hitTestChar(float x, float y) {
- TextHitInfo hit = layout.hitTestChar(x-(float) offset.getX(),
- y-(float) offset.getY());
+
+ Point2D p = new Point2D.Float(x, y);
+ try {
+ transform.inverseTransform(p, p);
+ } catch (java.awt.geom.NoninvertibleTransformException nite) {;}
+ TextHitInfo hit = layout.hitTestChar((float) p.getX(),
+ (float) p.getY());
return new TextHit(hit.getCharIndex(), hit.isLeadingEdge());
}
@@ -197,7 +204,7 @@
layout.getAscent();
Stroke overlineStroke =
new BasicStroke(getDecorationThickness(runaci, layout));
- return overlineStroke.createStrokedShape(
+ return overlineStroke.createStrokedShape(
new java.awt.geom.Line2D.Double(
0f, y,
layout.getAdvance(), y));
@@ -273,6 +280,12 @@
}
// private
+
+ private AffineTransform computeTransform() {
+ AffineTransform nt = AffineTransform.getTranslateInstance(
+ offset.getX(), offset.getY());
+ return nt;
+ }
private Point2D adjustOffset(Point2D p) {