/[classpath]/classpath/java/awt/font/TextLayout.java
ViewVC logotype

Diff of /classpath/java/awt/font/TextLayout.java

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

revision 1.3 by mkoch, Mon Sep 27 15:11:46 2004 UTC revision 1.4 by mkoch, Fri Oct 8 21:41:41 2004 UTC
# Line 41  package java.awt.font; Line 41  package java.awt.font;
41  import java.awt.Font;  import java.awt.Font;
42  import java.awt.Graphics2D;  import java.awt.Graphics2D;
43  import java.awt.Shape;  import java.awt.Shape;
44    import java.awt.Toolkit;
45  import java.awt.geom.AffineTransform;  import java.awt.geom.AffineTransform;
46  import java.awt.geom.Rectangle2D;  import java.awt.geom.Rectangle2D;
47  import java.text.AttributedCharacterIterator;  import java.text.AttributedCharacterIterator;
48  import java.text.AttributedString;  import java.text.AttributedString;
49  import java.text.CharacterIterator;  import java.text.CharacterIterator;
50  import java.util.Map;  import java.util.Map;
51    import java.awt.font.TextAttribute;
52    
53    import gnu.java.awt.ClasspathToolkit;
54    import gnu.java.awt.peer.ClasspathTextLayoutPeer;
55    
56  /**  /**
57   * @author Michael Koch   * @author Michael Koch
# Line 54  import java.util.Map; Line 59  import java.util.Map;
59  public final class TextLayout implements Cloneable  public final class TextLayout implements Cloneable
60  {  {
61    public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy ();    public static final CaretPolicy DEFAULT_CARET_POLICY = new CaretPolicy ();
62      ClasspathTextLayoutPeer peer;
63    
64    public static class CaretPolicy    public static class CaretPolicy
65    {    {
# Line 65  public final class TextLayout implements Line 71  public final class TextLayout implements
71      public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2,      public TextHitInfo getStrongCaret (TextHitInfo hit1, TextHitInfo hit2,
72                                         TextLayout layout)                                         TextLayout layout)
73      {      {
74        throw new Error ("not implemented");        return layout.peer.getStrongCaret(hit1, hit2);
75      }      }
76    }    }
77    
   private AttributedString attributedString;  
   private FontRenderContext fontRenderContext;  
     
78    public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)    public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
79    {        {    
80      attributedString = new AttributedString (text);      AttributedString as = new AttributedString (text);
81      fontRenderContext = frc;      ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
82        peer = tk.getClasspathTextLayoutPeer(as, frc);
83    }    }
84    
85    public TextLayout (String string, Font font, FontRenderContext frc)    public TextLayout (String string, Font font, FontRenderContext frc)
86    {    {
87      attributedString = new AttributedString (string);      AttributedString as = new AttributedString (string);
88      attributedString.addAttribute (TextAttribute.FONT, font);      as.addAttribute (TextAttribute.FONT, font);
89      fontRenderContext = frc;      ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
90        peer = tk.getClasspathTextLayoutPeer(as, frc);
91    }    }
92    
93    public TextLayout (String string, Map attributes, FontRenderContext frc)    public TextLayout (String string, Map attributes, FontRenderContext frc)
94    {    {
95      attributedString = new AttributedString (string, attributes);      AttributedString as = new AttributedString (string, attributes);
96      fontRenderContext = frc;      ClasspathToolkit tk = (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
97        peer = tk.getClasspathTextLayoutPeer(as, frc);
98    }    }
99    
100    protected Object clone ()    protected Object clone ()
101    {    {
102      try      try
103        {        {
104          return super.clone ();          TextLayout tl = (TextLayout) super.clone ();
105            tl.peer = (ClasspathTextLayoutPeer) this.peer.clone();
106            return tl;
107        }        }
108      catch (CloneNotSupportedException e)      catch (CloneNotSupportedException e)
109        {        {
# Line 105  public final class TextLayout implements Line 113  public final class TextLayout implements
113    }    }
114    
115    
   protected class CharacterIteratorProxy  
     implements CharacterIterator  
   {  
     public CharacterIterator target;  
     public int begin;  
     public int limit;  
     public int index;  
   
     public CharacterIteratorProxy (CharacterIterator ci)  
     {  
       target = ci;  
     }  
   
     public int getBeginIndex ()  
     {  
       return begin;  
     }  
   
     public int getEndIndex ()  
     {  
       return limit;  
     }  
   
     public int getIndex ()  
     {  
       return index;  
     }  
   
     public char setIndex (int idx)  
       throws IllegalArgumentException  
     {  
       if (idx < begin || idx >= limit)  
         throw new IllegalArgumentException ();  
       char ch = target.setIndex (idx);  
       index = idx;  
       return ch;  
     }  
   
     public char first ()  
     {  
       int save = target.getIndex ();  
       char ch = target.setIndex (begin);  
       target.setIndex (save);  
       return ch;  
     }  
   
     public char last ()  
     {  
       if (begin == limit)  
         return this.first ();  
   
       int save = target.getIndex ();  
       char ch = target.setIndex (limit - 1);  
       target.setIndex (save);  
       return ch;  
     }  
   
     public char current ()  
     {  
       return target.current();  
     }  
   
     public char next ()  
     {  
       if (index >= limit - 1)  
         return CharacterIterator.DONE;  
       else  
         {  
           index++;  
           return target.next();  
         }  
     }  
   
     public char previous ()  
     {  
       if (index <= begin)  
         return CharacterIterator.DONE;  
       else  
         {  
           index--;  
           return target.previous ();  
         }  
     }  
   
     public Object clone ()  
     {  
       CharacterIteratorProxy cip = new CharacterIteratorProxy (this.target);  
       cip.begin = this.begin;  
       cip.limit = this.limit;  
       cip.index = this.index;  
       return cip;  
     }  
       
   }  
   
   
116    public void draw (Graphics2D g2, float x, float y)    public void draw (Graphics2D g2, float x, float y)
117    {    {
118      AttributedCharacterIterator ci = attributedString.getIterator ();      peer.draw(g2, x, y);
     CharacterIteratorProxy proxy = new CharacterIteratorProxy (ci);  
     Font defFont = g2.getFont ();  
   
     /* Note: this implementation currently only interprets FONT text  
      * attributes. There is a reasonable argument to be made for some  
      * attributes being interpreted out here, where we have control of the  
      * Graphics2D and can construct or derive new fonts, and some  
      * attributes being interpreted by the GlyphVector itself. So far, for  
      * all attributes except FONT we do neither.  
      */  
   
     for (char c = ci.first ();  
          c != CharacterIterator.DONE;  
          c = ci.next ())  
       {                  
         proxy.begin = ci.getIndex ();  
         proxy.limit = ci.getRunLimit(TextAttribute.FONT);  
         if (proxy.limit <= proxy.begin)  
           continue;  
   
         proxy.index = proxy.begin;  
   
         Object fnt = ci.getAttribute(TextAttribute.FONT);  
         GlyphVector gv;  
         if (fnt instanceof Font)  
           gv = ((Font)fnt).createGlyphVector (fontRenderContext, proxy);  
         else  
           gv = defFont.createGlyphVector (fontRenderContext, proxy);  
   
         g2.drawGlyphVector (gv, x, y);  
   
         int n = gv.getNumGlyphs ();  
         for (int i = 0; i < n; ++i)  
           {  
             GlyphMetrics gm = gv.getGlyphMetrics (i);  
             if (gm.getAdvanceX() == gm.getAdvance ())  
               x += gm.getAdvanceX ();  
             else  
               y += gm.getAdvanceY ();  
           }  
       }  
119    }    }
120    
121    public boolean equals (Object obj)    public boolean equals (Object obj)
# Line 257  public final class TextLayout implements Line 128  public final class TextLayout implements
128    
129    public boolean equals (TextLayout tl)    public boolean equals (TextLayout tl)
130    {    {
131      throw new Error ("not implemented");      return this.peer.equals(tl.peer);
132    }    }
133    
134    public float getAdvance ()    public float getAdvance ()
135    {    {
136      throw new Error ("not implemented");      return peer.getAdvance();
137    }    }
138    
139    public float getAscent ()    public float getAscent ()
140    {    {
141      throw new Error ("not implemented");      return peer.getAscent();
142    }    }
143    
144    public byte getBaseline ()    public byte getBaseline ()
145    {    {
146      throw new Error ("not implemented");      return peer.getBaseline();
147    }    }
148    
149    public float[] getBaselineOffsets ()    public float[] getBaselineOffsets ()
150    {    {
151      throw new Error ("not implemented");      return peer.getBaselineOffsets();
152    }    }
153    
154    public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)    public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
155    {    {
156      throw new Error ("not implemented");      return peer.getBlackBoxBounds(firstEndpoint, secondEndpoint);
157    }    }
158    
159    public Rectangle2D getBounds()    public Rectangle2D getBounds()
160    {    {
161      throw new Error ("not implemented");      return peer.getBounds();
162    }    }
163    
164    public float[] getCaretInfo (TextHitInfo hit)    public float[] getCaretInfo (TextHitInfo hit)
165    {    {
166      throw new Error ("not implemented");      return getCaretInfo(hit, getBounds());
167    }    }
168    
169    public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)    public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)
170    {    {
171      throw new Error ("not implemented");      return peer.getCaretInfo(hit, bounds);
172    }    }
173    
174    public Shape getCaretShape (TextHitInfo hit)    public Shape getCaretShape (TextHitInfo hit)
175    {    {
176      throw new Error ("not implemented");      return getCaretShape(hit, getBounds());
177    }    }
178    
179    public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)    public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)
180    {    {
181      throw new Error ("not implemented");      return peer.getCaretShape(hit, bounds);
182    }    }
183    
184    public Shape[] getCaretShapes (int offset)    public Shape[] getCaretShapes (int offset)
185    {    {
186      throw new Error ("not implemented");      return getCaretShapes(offset, getBounds());
187    }    }
188    
189    public Shape[] getCaretShapes (int offset, Rectangle2D bounds)    public Shape[] getCaretShapes (int offset, Rectangle2D bounds)
190    {    {
191      throw new Error ("not implemented");      return getCaretShapes(offset, getBounds(), DEFAULT_CARET_POLICY);
192    }    }
193    
194    public Shape[] getCaretShapes (int offset, Rectangle2D bounds,    public Shape[] getCaretShapes (int offset, Rectangle2D bounds,
195                                   TextLayout.CaretPolicy policy)                                   TextLayout.CaretPolicy policy)
196    {    {
197      throw new Error ("not implemented");      return peer.getCaretShapes(offset, bounds, policy);
198    }    }
199    
200    public int getCharacterCount ()    public int getCharacterCount ()
201    {    {
202      throw new Error ("not implemented");      return peer.getCharacterCount();
203    }    }
204    
205    public byte getCharacterLevel (int index)    public byte getCharacterLevel (int index)
206    {    {
207      throw new Error ("not implemented");      return peer.getCharacterLevel(index);
208    }    }
209    
210    public float getDescent ()    public float getDescent ()
211    {    {
212      throw new Error ("not implemented");      return peer.getDescent();
213    }    }
214    
215    public TextLayout getJustifiedLayout (float justificationWidth)    public TextLayout getJustifiedLayout (float justificationWidth)
216    {    {
217      throw new Error ("not implemented");      return peer.getJustifiedLayout(justificationWidth);
218    }    }
219    
220    public float getLeading ()    public float getLeading ()
221    {    {
222      throw new Error ("not implemented");      return peer.getLeading();
223    }    }
224    
225    public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint)    public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint)
226    {    {
227      throw new Error ("not implemented");      return getLogicalHighlightShape (firstEndpoint, secondEndpoint, getBounds());
228    }    }
229    
230    public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,    public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
231                                           Rectangle2D bounds)                                           Rectangle2D bounds)
232    {    {
233      throw new Error ("not implemented");      return peer.getLogicalHighlightShape(firstEndpoint, secondEndpoint, bounds);
234    }    }
235    
236    public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,    public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
237                                                     TextHitInfo secondEndpoint)                                                     TextHitInfo secondEndpoint)
238    {    {
239      throw new Error ("not implemented");      return peer.getLogicalRangesForVisualSelection(firstEndpoint, secondEndpoint);
240    }    }
241    
242    public TextHitInfo getNextLeftHit (int offset)    public TextHitInfo getNextLeftHit (int offset)
243    {    {
244      throw new Error ("not implemented");      return getNextLeftHit(offset, DEFAULT_CARET_POLICY);
245    }    }
246    
247    public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy)    public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy)
248    {    {
249      throw new Error ("not implemented");      return peer.getNextLeftHit(offset, policy);
250    }    }
251    
252    public TextHitInfo getNextLeftHit (TextHitInfo hit)    public TextHitInfo getNextLeftHit (TextHitInfo hit)
253    {    {
254      throw new Error ("not implemented");      return getNextLeftHit(hit.getCharIndex());
255    }    }
256    
257    public TextHitInfo getNextRightHit (int offset)    public TextHitInfo getNextRightHit (int offset)
258    {    {
259      throw new Error ("not implemented");      return getNextRightHit(offset, DEFAULT_CARET_POLICY);
260    }    }
261    
262    public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy)    public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy)
263    {    {
264      throw new Error ("not implemented");      return peer.getNextRightHit(offset, policy);
265    }    }
266    
267    public TextHitInfo getNextRightHit (TextHitInfo hit)    public TextHitInfo getNextRightHit (TextHitInfo hit)
268    {    {
269      throw new Error ("not implemented");      return getNextRightHit(hit.getCharIndex());
270    }    }
271    
272    public Shape getOutline (AffineTransform tx)    public Shape getOutline (AffineTransform tx)
273    {    {
274      throw new Error ("not implemented");      return peer.getOutline(tx);
275    }    }
276    
277    public float getVisibleAdvance ()    public float getVisibleAdvance ()
278    {    {
279      throw new Error ("not implemented");      return peer.getVisibleAdvance();
280    }    }
281    
282    public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,    public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
283                                          TextHitInfo secondEndpoint)                                          TextHitInfo secondEndpoint)
284    {    {
285      throw new Error ("not implemented");      return getVisualHighlightShape(firstEndpoint, secondEndpoint, getBounds());
286    }    }
287    
288    public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,    public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
289                                          TextHitInfo secondEndpoint,                                          TextHitInfo secondEndpoint,
290                                          Rectangle2D bounds)                                          Rectangle2D bounds)
291    {    {
292      throw new Error ("not implemented");      return peer.getVisualHighlightShape(firstEndpoint, secondEndpoint, bounds);
293    }    }
294    
295    public TextHitInfo getVisualOtherHit (TextHitInfo hit)    public TextHitInfo getVisualOtherHit (TextHitInfo hit)
296    {    {
297      throw new Error ("not implemented");      return peer.getVisualOtherHit(hit);
298    }    }
299    
300    protected void handleJustify (float justificationWidth)    protected void handleJustify (float justificationWidth)
301    {    {
302      throw new Error ("not implemented");      peer.handleJustify(justificationWidth);
303    }    }
304    
305    public int hashCode ()    public int hashCode ()
306    {    {
307      throw new Error ("not implemented");      return peer.hashCode();
308    }    }
309    
310    public TextHitInfo hitTestChar (float x, float y)    public TextHitInfo hitTestChar (float x, float y)
311    {    {
312      throw new Error ("not implemented");      return hitTestChar(x, y, getBounds());
313    }    }
314    
315    public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)    public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)
316    {    {
317      throw new Error ("not implemented");      return peer.hitTestChar(x, y, bounds);
318    }    }
319    
320    public boolean isLeftToRight ()    public boolean isLeftToRight ()
321    {    {
322      throw new Error ("not implemented");      return peer.isLeftToRight();
323    }    }
324    
325    public boolean isVertical ()    public boolean isVertical ()
326    {    {
327      throw new Error ("not implemented");      return peer.isVertical();
328    }    }
329    
330    public String toString ()    public String toString ()
331    {    {
332      throw new Error ("not implemented");      return peer.toString();
333    }    }
334  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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