2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / font / TextLayout.java
blobb58b5a583493a2fcf83a9a5f1e819ef17ac38a8f
1 /* TextLayout.java
2 Copyright (C) 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package java.awt.font;
41 import java.awt.Font;
42 import java.awt.Graphics2D;
43 import java.awt.Shape;
44 import java.awt.geom.AffineTransform;
45 import java.awt.geom.Rectangle2D;
46 import java.text.CharacterIterator;
47 import java.text.AttributedCharacterIterator;
48 import java.text.AttributedString;
49 import java.util.Map;
50 import java.awt.font.TextAttribute;
53 /**
54 * @author Michael Koch
56 public final class TextLayout implements Cloneable
58 public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy ();
60 public static class CaretPolicy
62 public CaretPolicy ()
64 // Do nothing here.
67 public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2,
68 TextLayout layout)
70 throw new Error ("not implemented");
74 private AttributedString attributedString;
75 private FontRenderContext fontRenderContext;
77 public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
79 attributedString = new AttributedString (text);
80 fontRenderContext = frc;
83 public TextLayout (String string, Font font, FontRenderContext frc)
85 attributedString = new AttributedString (string);
86 attributedString.addAttribute (TextAttribute.FONT, font);
87 fontRenderContext = frc;
90 public TextLayout (String string, Map attributes, FontRenderContext frc)
92 attributedString = new AttributedString (string, attributes);
93 fontRenderContext = frc;
96 protected Object clone ()
98 try
100 return super.clone ();
102 catch (CloneNotSupportedException e)
104 // This should never occur
105 throw new InternalError ();
110 protected class CharacterIteratorProxy
111 implements CharacterIterator
113 public CharacterIterator target;
114 public int begin;
115 public int limit;
116 public int index;
118 public CharacterIteratorProxy (CharacterIterator ci)
120 target = ci;
123 public int getBeginIndex ()
125 return begin;
128 public int getEndIndex ()
130 return limit;
133 public int getIndex ()
135 return index;
138 public char setIndex (int idx)
139 throws IllegalArgumentException
141 if (idx < begin || idx >= limit)
142 throw new IllegalArgumentException ();
143 char ch = target.setIndex (idx);
144 index = idx;
145 return ch;
148 public char first ()
150 int save = target.getIndex ();
151 char ch = target.setIndex (begin);
152 target.setIndex (save);
153 return ch;
156 public char last ()
158 if (begin == limit)
159 return this.first ();
161 int save = target.getIndex ();
162 char ch = target.setIndex (limit - 1);
163 target.setIndex (save);
164 return ch;
167 public char current ()
169 return target.current();
172 public char next ()
174 if (index >= limit - 1)
175 return CharacterIterator.DONE;
176 else
178 index++;
179 return target.next();
183 public char previous ()
185 if (index <= begin)
186 return CharacterIterator.DONE;
187 else
189 index--;
190 return target.previous ();
194 public Object clone ()
196 CharacterIteratorProxy cip = new CharacterIteratorProxy (this.target);
197 cip.begin = this.begin;
198 cip.limit = this.limit;
199 cip.index = this.index;
200 return cip;
206 public void draw (Graphics2D g2, float x, float y)
208 AttributedCharacterIterator ci = attributedString.getIterator ();
209 CharacterIteratorProxy proxy = new CharacterIteratorProxy (ci);
210 Font defFont = g2.getFont ();
212 /* Note: this implementation currently only interprets FONT text
213 * attributes. There is a reasonable argument to be made for some
214 * attributes being interpreted out here, where we have control of the
215 * Graphics2D and can construct or derive new fonts, and some
216 * attributes being interpreted by the GlyphVector itself. So far, for
217 * all attributes except FONT we do neither.
220 for (char c = ci.first ();
221 c != CharacterIterator.DONE;
222 c = ci.next ())
224 proxy.begin = ci.getIndex ();
225 proxy.limit = ci.getRunLimit(TextAttribute.FONT);
226 if (proxy.limit <= proxy.begin)
227 continue;
229 proxy.index = proxy.begin;
231 Object fnt = ci.getAttribute(TextAttribute.FONT);
232 GlyphVector gv;
233 if (fnt instanceof Font)
234 gv = ((Font)fnt).createGlyphVector (fontRenderContext, proxy);
235 else
236 gv = defFont.createGlyphVector (fontRenderContext, proxy);
238 g2.drawGlyphVector (gv, x, y);
240 int n = gv.getNumGlyphs ();
241 for (int i = 0; i < n; ++i)
243 GlyphMetrics gm = gv.getGlyphMetrics (i);
244 if (gm.getAdvanceX() == gm.getAdvance ())
245 x += gm.getAdvanceX ();
246 else
247 y += gm.getAdvanceY ();
252 public boolean equals (Object obj)
254 if (! (obj instanceof TextLayout))
255 return false;
257 return equals ((TextLayout) obj);
260 public boolean equals (TextLayout tl)
262 throw new Error ("not implemented");
265 public float getAdvance ()
267 throw new Error ("not implemented");
270 public float getAscent ()
272 throw new Error ("not implemented");
275 public byte getBaseline ()
277 throw new Error ("not implemented");
280 public float[] getBaselineOffsets ()
282 throw new Error ("not implemented");
285 public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
287 throw new Error ("not implemented");
290 public Rectangle2D getBounds()
292 throw new Error ("not implemented");
295 public float[] getCaretInfo (TextHitInfo hit)
297 throw new Error ("not implemented");
300 public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)
302 throw new Error ("not implemented");
305 public Shape getCaretShape (TextHitInfo hit)
307 throw new Error ("not implemented");
310 public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)
312 throw new Error ("not implemented");
315 public Shape[] getCaretShapes (int offset)
317 throw new Error ("not implemented");
320 public Shape[] getCaretShapes (int offset, Rectangle2D bounds)
322 throw new Error ("not implemented");
325 public Shape[] getCaretShapes (int offset, Rectangle2D bounds,
326 TextLayout.CaretPolicy policy)
328 throw new Error ("not implemented");
331 public int getCharacterCount ()
333 throw new Error ("not implemented");
336 public byte getCharacterLevel (int index)
338 throw new Error ("not implemented");
341 public float getDescent ()
343 throw new Error ("not implemented");
346 public TextLayout getJustifiedLayout (float justificationWidth)
348 throw new Error ("not implemented");
351 public float getLeading ()
353 throw new Error ("not implemented");
356 public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint)
358 throw new Error ("not implemented");
361 public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
362 Rectangle2D bounds)
364 throw new Error ("not implemented");
367 public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
368 TextHitInfo secondEndpoint)
370 throw new Error ("not implemented");
373 public TextHitInfo getNextLeftHit (int offset)
375 throw new Error ("not implemented");
378 public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy)
380 throw new Error ("not implemented");
383 public TextHitInfo getNextLeftHit (TextHitInfo hit)
385 throw new Error ("not implemented");
388 public TextHitInfo getNextRightHit (int offset)
390 throw new Error ("not implemented");
393 public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy)
395 throw new Error ("not implemented");
398 public TextHitInfo getNextRightHit (TextHitInfo hit)
400 throw new Error ("not implemented");
403 public Shape getOutline (AffineTransform tx)
405 throw new Error ("not implemented");
408 public float getVisibleAdvance ()
410 throw new Error ("not implemented");
413 public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
414 TextHitInfo secondEndpoint)
416 throw new Error ("not implemented");
419 public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
420 TextHitInfo secondEndpoint,
421 Rectangle2D bounds)
423 throw new Error ("not implemented");
426 public TextHitInfo getVisualOtherHit (TextHitInfo hit)
428 throw new Error ("not implemented");
431 protected void handleJustify (float justificationWidth)
433 throw new Error ("not implemented");
436 public int hashCode ()
438 throw new Error ("not implemented");
441 public TextHitInfo hitTestChar (float x, float y)
443 throw new Error ("not implemented");
446 public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)
448 throw new Error ("not implemented");
451 public boolean isLeftToRight ()
453 throw new Error ("not implemented");
456 public boolean isVertical ()
458 throw new Error ("not implemented");
461 public String toString ()
463 throw new Error ("not implemented");