deweese 01/09/27 14:19:44
Modified: sources/org/apache/batik/gvt TextNode.java
sources/org/apache/batik/gvt/renderer
StrokingTextPainter.java
sources/org/apache/batik/gvt/text ConcreteTextSelector.java
GlyphLayout.java TextLayoutAdapter.java
sources/org/apache/batik/swing/gvt TextSelectionManager.java
Log:
1) Fixed some bugs in the marker stuff for ligatures
2) Extended selection API into the swing package (TextSelectionManager).
Revision Changes Path
1.20 +6 -2 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.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- TextNode.java 2001/09/27 20:09:10 1.19
+++ TextNode.java 2001/09/27 21:19:44 1.20
@@ -35,7 +35,7 @@
* A graphics node that represents text.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Thierry Kormann</a>
- * @version $Id: TextNode.java,v 1.19 2001/09/27 20:09:10 deweese Exp $
+ * @version $Id: TextNode.java,v 1.20 2001/09/27 21:19:44 deweese Exp $
*/
public class TextNode extends AbstractGraphicsNode implements Selectable {
@@ -296,6 +296,10 @@
// Selection methods
//
public void setSelection(Mark begin, Mark end) {
+ if ((begin.getTextNode() != this) ||
+ (end.getTextNode() != this))
+ throw new Error("Markers not from this TextNode");
+
beginMark = begin;
endMark = end;
}
@@ -347,7 +351,7 @@
int[] ranges = textPainter.getSelected(beginMark, endMark);
Object o = null;
- // TODO: later we can return more complex things like
+ // TODO: later we can return more complex things like
// noncontiguous selections
if ((ranges != null) && (ranges.length > 1)) {
// make sure that they are in order
1.17 +4 -5
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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- StrokingTextPainter.java 2001/09/27 20:09:11 1.16
+++ StrokingTextPainter.java 2001/09/27 21:19:44 1.17
@@ -60,7 +60,7 @@
* @see org.apache.batik.gvt.text.GVTAttributedCharacterIterator
*
* @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
- * @version $Id: StrokingTextPainter.java,v 1.16 2001/09/27 20:09:11 deweese Exp $
+ * @version $Id: StrokingTextPainter.java,v 1.17 2001/09/27 21:19:44 deweese Exp $
*/
public class StrokingTextPainter extends BasicTextPainter {
@@ -1089,17 +1089,16 @@
aci.setIndex(index);
int charIndex = ((Integer)aci.getAttribute
(GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
-
+
// get the list of text runs
List textRuns = getTextRuns(node, aci);
- // for each text run, append any highlight it may contain for
- // the current selection
+ // for each text run, see if it contains the current char.
for (int i = 0; i < textRuns.size(); ++i) {
TextRun textRun = (TextRun)textRuns.get(i);
TextSpanLayout layout = textRun.getLayout();
- int idx = layout.getGlyphIndex(index);
+ int idx = layout.getGlyphIndex(charIndex);
if (idx != -1) {
TextHit textHit = new TextHit(charIndex, leadingEdge);
return new BasicTextPainter.BasicMark
1.7 +25 -24
xml-batik/sources/org/apache/batik/gvt/text/ConcreteTextSelector.java
Index: ConcreteTextSelector.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/gvt/text/ConcreteTextSelector.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ConcreteTextSelector.java 2001/09/17 16:28:28 1.6
+++ ConcreteTextSelector.java 2001/09/27 21:19:44 1.7
@@ -21,7 +21,11 @@
import java.util.ArrayList;
import java.util.Iterator;
-import org.apache.batik.gvt.*;
+import org.apache.batik.gvt.TextNode;
+import org.apache.batik.gvt.Selector;
+import org.apache.batik.gvt.Selectable;
+import org.apache.batik.gvt.GraphicsNode;
+import org.apache.batik.gvt.text.Mark;
import org.apache.batik.gvt.event.GraphicsNodeMouseEvent;
import org.apache.batik.gvt.event.GraphicsNodeInputEvent;
import org.apache.batik.gvt.event.GraphicsNodeEvent;
@@ -35,7 +39,7 @@
* A simple implementation of GraphicsNodeMouseListener for text selection.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Bill Haneman</a>
- * @version $Id: ConcreteTextSelector.java,v 1.6 2001/09/17 16:28:28 tkormann Exp $
+ * @version $Id: ConcreteTextSelector.java,v 1.7 2001/09/27 21:19:44 deweese Exp $
*/
public class ConcreteTextSelector implements Selector {
@@ -46,28 +50,9 @@
private int firstHit;
private int lastHit;
- // XXX: below is used by our current "direct" approach to selection
- // highlighting. It should probably be migrated to a
- // strategy that sends highlight requests directly to the Renderer.
- private Graphics2D g2d;
-
- private AffineTransform baseTransform = new AffineTransform();
-
public ConcreteTextSelector() {
}
- public void setGraphics2D(Graphics2D g2d) {
- this.g2d = g2d;
- }
-
- /**
- * Not used.
- * @deprecated.
- */
- public void setBaseTransform(AffineTransform t) {
- this.baseTransform = t;
- }
-
public void mouseClicked(GraphicsNodeMouseEvent evt) {
checkSelectGesture(evt);
}
@@ -111,6 +96,24 @@
report(evt, "keyTyped");
}
+ public void setSelection(Mark begin, Mark end) {
+ TextNode node = begin.getTextNode();
+ if (node != end.getTextNode())
+ throw new Error("Markers not from same TextNode");
+ node.setSelection(begin, end);
+ Object selection = getSelection();
+ Shape shape = node.getHighlightShape();
+ dispatchSelectionEvent(new SelectionEvent
+ (selection, SelectionEvent.SELECTION_DONE, shape));
+ copyToClipboard(selection);
+ }
+
+ public void clearSelection() {
+ dispatchSelectionEvent(new SelectionEvent
+ (null, SelectionEvent.SELECTION_CLEARED, null));
+ copyToClipboard(null);
+ }
+
/*
* Checks the event to see if it is a selection gesture and processes it
* accordingly.
@@ -192,9 +195,8 @@
}
} else if (isSelectAllGesture(evt)) {
-
selectionNode = source;
-
+
((Selectable) source).selectAll(p.getX(), p.getY());
Object oldSelection = getSelection();
Shape newShape =
@@ -204,7 +206,6 @@
SelectionEvent.SELECTION_DONE,
newShape));
copyToClipboard(oldSelection);
-
}
}
}
1.25 +10 -9 xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java
Index: GlyphLayout.java
===================================================================
RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/text/GlyphLayout.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- GlyphLayout.java 2001/09/25 12:37:47 1.24
+++ GlyphLayout.java 2001/09/27 21:19:44 1.25
@@ -40,7 +40,7 @@
* @see org.apache.batik.gvt.text.TextSpanLayout
*
* @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
- * @version $Id: GlyphLayout.java,v 1.24 2001/09/25 12:37:47 deweese Exp $
+ * @version $Id: GlyphLayout.java,v 1.25 2001/09/27 21:19:44 deweese Exp $
*/
public class GlyphLayout implements TextSpanLayout {
@@ -224,17 +224,18 @@
* or -1 if a matching glyph could not be found.
*/
public int getGlyphIndex(int charIndex) {
-
- int currentChar = aci.getBeginIndex();
int numGlyphs = getGlyphCount();
+ aci.first();
for (int i = 0; i < numGlyphs; i++) {
- aci.setIndex(currentChar);
- int glyphCharIndex = ((Integer)aci.getAttribute(
-
GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
- if (charIndex == glyphCharIndex) {
- return i;
+ int count = getCharacterCount(i, i);
+ for (int n=0; n<count; n++) {
+ int glyphCharIndex = ((Integer)aci.getAttribute
+
(GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
+ if (charIndex == glyphCharIndex)
+ return i;
+ if (aci.next() == AttributedCharacterIterator.DONE)
+ return -1;
}
- currentChar += getCharacterCount(i, i);
}
return -1;
}
1.11 +10 -8
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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TextLayoutAdapter.java 2001/09/18 21:19:01 1.10
+++ TextLayoutAdapter.java 2001/09/27 21:19:44 1.11
@@ -33,7 +33,7 @@
* @see org.apache.batik.gvt.TextPainter
*
* @author <a href="[EMAIL PROTECTED]>Bill Haneman</a>
- * @version $Id: TextLayoutAdapter.java,v 1.10 2001/09/18 21:19:01 deweese Exp $
+ * @version $Id: TextLayoutAdapter.java,v 1.11 2001/09/27 21:19:44 deweese Exp $
*/
public class TextLayoutAdapter implements TextSpanLayout {
@@ -168,16 +168,18 @@
* or -1 if a matching glyph could not be found.
*/
public int getGlyphIndex(int charIndex) {
- int currentChar = aci.getBeginIndex();
int numGlyphs = getGlyphCount();
+ aci.first();
for (int i = 0; i < numGlyphs; i++) {
- aci.setIndex(currentChar);
- int glyphCharIndex = ((Integer)aci.getAttribute(
-
GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
- if (charIndex == glyphCharIndex) {
- return i;
+ int count = getCharacterCount(i, i);
+ for (int n=0; n<count; n++) {
+ int glyphCharIndex = ((Integer)aci.getAttribute
+
(GVTAttributedCharacterIterator.TextAttribute.CHAR_INDEX)).intValue();
+ if (charIndex == glyphCharIndex)
+ return i;
+ if (aci.next() == AttributedCharacterIterator.DONE)
+ return -1;
}
- currentChar += getCharacterCount(i, i);
}
return -1;
}
1.9 +9 -1
xml-batik/sources/org/apache/batik/swing/gvt/TextSelectionManager.java
Index: TextSelectionManager.java
===================================================================
RCS file:
/home/cvs/xml-batik/sources/org/apache/batik/swing/gvt/TextSelectionManager.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TextSelectionManager.java 2001/09/25 12:37:47 1.8
+++ TextSelectionManager.java 2001/09/27 21:19:44 1.9
@@ -30,12 +30,13 @@
import org.apache.batik.gvt.event.SelectionListener;
import org.apache.batik.gvt.text.ConcreteTextSelector;
+import org.apache.batik.gvt.text.Mark;
/**
* This class represents an object which manage GVT text nodes selection.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephane Hillion</a>
- * @version $Id: TextSelectionManager.java,v 1.8 2001/09/25 12:37:47 deweese Exp $
+ * @version $Id: TextSelectionManager.java,v 1.9 2001/09/27 21:19:44 deweese Exp $
*/
public class TextSelectionManager {
@@ -105,6 +106,13 @@
*/
public Overlay getSelectionOverlay() {
return selectionOverlay;
+ }
+
+ /**
+ * Sets the selected text
+ */
+ public void setSelection(Mark start, Mark end) {
+ textSelector.setSelection(start, end);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]