/[fenfire]/fenfire/org/fenfire/view/TextNodeView.java
ViewVC logotype

Diff of /fenfire/org/fenfire/view/TextNodeView.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by mudyc, Wed Jul 30 15:04:21 2003 UTC revision 1.12 by humppake, Wed Aug 13 22:58:10 2003 UTC
# Line 64  public static final String rcsid = "$Id$ Line 64  public static final String rcsid = "$Id$
64      public void setContext(org.fenfire.view.lava.TextHandler.Context context)      public void setContext(org.fenfire.view.lava.TextHandler.Context context)
65      { this.context = context; }      { this.context = context; }
66    
67        /** Get position of the first character placed
68         * after given coordinates.
69         */
70        public int getPos(ConstGraph g, Object node, float x, float y) {
71            Enfilade1D enf = (Enfilade1D)nodeContent.f(g, node);
72            final Object objNode = node;
73            String s = enf.makeString();
74            if (s.length() == 0) return 0;
75    
76            HChain ch = getChain(s);
77            final HBroken br = breaker.breakLines(ch, width, scale);
78    
79            int pos = 0;
80            int line = 0;
81            if (y < 0) return 0;
82            while (line < br.getLineCount()){
83                if (y >= br.getLineOffset(line)) line++;
84                else break;
85            }
86    
87            float xoffs = 0;
88            for (int i=0; i<ch.length(); i++) {
89                int newLine = br.getLine(pos, null);
90                if (newLine < line) pos += ch.getBox(i).getLength();
91                else if (newLine == line) {
92                    if (xoffs + ch.getBox(i).getWidth(scale) < x) {
93                        pos += ch.getBox(i).getLength();
94                        xoffs += ch.getBox(i).getWidth(scale);
95                    } else {
96                        for (int j=0; j<ch.getBox(i).getLength(); j++)
97                            if (xoffs + ch.getBox(i).getX(j, scale) < x) pos++;
98                            else break;
99                        break;
100                    }
101                } else break;
102            }
103            while (br.getLine(pos, null) > line) pos--;
104            return pos;
105        }
106    
107        /** Get coordinates before the given character.
108         */
109        public void getXY(ConstGraph g, Object node, int pos, float[] xy) {
110            Enfilade1D enf = (Enfilade1D)nodeContent.f(g, node);
111            final Object objNode = node;
112            String s = enf.makeString();
113            if (s.length() == 0) {
114                if (xy != null && xy.length >= 2) {
115                    xy[0] = 0;
116                    xy[1] = style.getHeight(scale) + style.getAscent(scale);
117                }
118                return;
119            }
120    
121            HChain ch = getChain(s);
122            final HBroken br = breaker.breakLines(ch, width, scale);
123    
124            float xoffs[] = new float[1];
125            int line = br.getLine(pos, xoffs);
126            
127            if (xy != null && xy.length >= 2) {
128                // XXX the x offs doesn't seem to be exact, when there is a lot of spaces
129                xy[0] = xoffs[0];
130                xy[1] = br.getLineOffset(line);
131            }
132        }
133    
134      public Object f(ConstGraph g, Object node) {      public Object f(ConstGraph g, Object node) {
135          if (hasContext) {          if (hasContext) {
136              if (context == null) throw new Error("No context set");              if (context == null) throw new Error("No context set");
# Line 87  public static final String rcsid = "$Id$ Line 154  public static final String rcsid = "$Id$
154          final float height = br.getHeight();          final float height = br.getHeight();
155    
156          final float width;          final float width;
157          if(br.getLineCount() > 1)          if(br.getLineCount() > 1) { // Let's get the longest line
158              width = this.width;              float maxWidth = br.getLineWidth(0);
159          else              for (int i=1; i<br.getLineCount(); i++)
160              width = br.getLineWidth(0);                  if (br.getLineWidth(i) > maxWidth)
161                        maxWidth = br.getLineWidth(i);
162                width = maxWidth;
163            } else width = br.getLineWidth(0);
164    
165          //final TextVob vob = new TextVob(style, s, false);          //final TextVob vob = new TextVob(style, s, false);
166          //final float width = style.getWidth(s, scale);          //final float width = style.getWidth(s, scale);
# Line 111  public static final String rcsid = "$Id$ Line 181  public static final String rcsid = "$Id$
181      }      }
182    
183    
184      protected HChain getChain(String s) {      protected  HChain getChain(String s) {
185          HChain ch = new LinebreakableChain();          HChain ch = new LinebreakableChain();
186    
187          int pos = 0;          int pos = 0;

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26