[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] fenfire/org/fenfire/view TextNodeView.java
From: |
Asko Soukka |
Subject: |
[Gzz-commits] fenfire/org/fenfire/view TextNodeView.java |
Date: |
Wed, 13 Aug 2003 18:58:10 -0400 |
CVSROOT: /cvsroot/fenfire
Module name: fenfire
Branch:
Changes by: Asko Soukka <address@hidden> 03/08/13 18:58:10
Modified files:
org/fenfire/view: TextNodeView.java
Log message:
A couple of methods for querying the cursor positiong.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/view/TextNodeView.java.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
Patches:
Index: fenfire/org/fenfire/view/TextNodeView.java
diff -u fenfire/org/fenfire/view/TextNodeView.java:1.11
fenfire/org/fenfire/view/TextNodeView.java:1.12
--- fenfire/org/fenfire/view/TextNodeView.java:1.11 Wed Jul 30 11:04:21 2003
+++ fenfire/org/fenfire/view/TextNodeView.java Wed Aug 13 18:58:10 2003
@@ -39,7 +39,7 @@
*/
public class TextNodeView extends org.fenfire.view.lava.TextHandler
implements NodeFunction {
-public static final String rcsid = "$Id: TextNodeView.java,v 1.11 2003/07/30
15:04:21 mudyc Exp $";
+public static final String rcsid = "$Id: TextNodeView.java,v 1.12 2003/08/13
22:58:10 humppake Exp $";
public static boolean dbg = false;
private static void pa(String s) { System.out.println("TextNodeView::"+s);
}
@@ -64,6 +64,73 @@
public void setContext(org.fenfire.view.lava.TextHandler.Context context)
{ this.context = context; }
+ /** Get position of the first character placed
+ * after given coordinates.
+ */
+ public int getPos(ConstGraph g, Object node, float x, float y) {
+ Enfilade1D enf = (Enfilade1D)nodeContent.f(g, node);
+ final Object objNode = node;
+ String s = enf.makeString();
+ if (s.length() == 0) return 0;
+
+ HChain ch = getChain(s);
+ final HBroken br = breaker.breakLines(ch, width, scale);
+
+ int pos = 0;
+ int line = 0;
+ if (y < 0) return 0;
+ while (line < br.getLineCount()){
+ if (y >= br.getLineOffset(line)) line++;
+ else break;
+ }
+
+ float xoffs = 0;
+ for (int i=0; i<ch.length(); i++) {
+ int newLine = br.getLine(pos, null);
+ if (newLine < line) pos += ch.getBox(i).getLength();
+ else if (newLine == line) {
+ if (xoffs + ch.getBox(i).getWidth(scale) < x) {
+ pos += ch.getBox(i).getLength();
+ xoffs += ch.getBox(i).getWidth(scale);
+ } else {
+ for (int j=0; j<ch.getBox(i).getLength(); j++)
+ if (xoffs + ch.getBox(i).getX(j, scale) < x) pos++;
+ else break;
+ break;
+ }
+ } else break;
+ }
+ while (br.getLine(pos, null) > line) pos--;
+ return pos;
+ }
+
+ /** Get coordinates before the given character.
+ */
+ public void getXY(ConstGraph g, Object node, int pos, float[] xy) {
+ Enfilade1D enf = (Enfilade1D)nodeContent.f(g, node);
+ final Object objNode = node;
+ String s = enf.makeString();
+ if (s.length() == 0) {
+ if (xy != null && xy.length >= 2) {
+ xy[0] = 0;
+ xy[1] = style.getHeight(scale) + style.getAscent(scale);
+ }
+ return;
+ }
+
+ HChain ch = getChain(s);
+ final HBroken br = breaker.breakLines(ch, width, scale);
+
+ float xoffs[] = new float[1];
+ int line = br.getLine(pos, xoffs);
+
+ if (xy != null && xy.length >= 2) {
+ // XXX the x offs doesn't seem to be exact, when there is a lot of
spaces
+ xy[0] = xoffs[0];
+ xy[1] = br.getLineOffset(line);
+ }
+ }
+
public Object f(ConstGraph g, Object node) {
if (hasContext) {
if (context == null) throw new Error("No context set");
@@ -87,10 +154,13 @@
final float height = br.getHeight();
final float width;
- if(br.getLineCount() > 1)
- width = this.width;
- else
- width = br.getLineWidth(0);
+ if(br.getLineCount() > 1) { // Let's get the longest line
+ float maxWidth = br.getLineWidth(0);
+ for (int i=1; i<br.getLineCount(); i++)
+ if (br.getLineWidth(i) > maxWidth)
+ maxWidth = br.getLineWidth(i);
+ width = maxWidth;
+ } else width = br.getLineWidth(0);
//final TextVob vob = new TextVob(style, s, false);
//final float width = style.getWidth(s, scale);
@@ -111,7 +181,7 @@
}
- protected HChain getChain(String s) {
+ protected HChain getChain(String s) {
HChain ch = new LinebreakableChain();
int pos = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] fenfire/org/fenfire/view TextNodeView.java,
Asko Soukka <=