/[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.1 by mkoch, Mon Feb 17 08:05:50 2003 UTC revision 1.2 by graydon, Thu Nov 20 23:52:41 2003 UTC
# Line 43  import java.awt.Graphics2D; Line 43  import java.awt.Graphics2D;
43  import java.awt.Shape;  import java.awt.Shape;
44  import java.awt.geom.AffineTransform;  import java.awt.geom.AffineTransform;
45  import java.awt.geom.Rectangle2D;  import java.awt.geom.Rectangle2D;
46    import java.text.CharacterIterator;
47  import java.text.AttributedCharacterIterator;  import java.text.AttributedCharacterIterator;
48    import java.text.AttributedString;
49  import java.util.Map;  import java.util.Map;
50    import java.awt.font.TextAttribute;
51    
52    
53  /**  /**
54   * @author Michael Koch   * @author Michael Koch
# Line 67  public final class TextLayout implements Line 71  public final class TextLayout implements
71      }      }
72    }    }
73    
74      private AttributedString attributedString;
75    private FontRenderContext fontRenderContext;    private FontRenderContext fontRenderContext;
76        
77    public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)    public TextLayout (AttributedCharacterIterator text, FontRenderContext frc)
78    {    {    
79      // FIXME      attributedString = new AttributedString (text);
80      this.fontRenderContext = frc;      fontRenderContext = frc;
81    }    }
82    
83    public TextLayout (String string, Font font, FontRenderContext frc)    public TextLayout (String string, Font font, FontRenderContext frc)
84    {    {
85      // FIXME      attributedString = new AttributedString (string);
86      this.fontRenderContext = frc;      attributedString.addAttribute (TextAttribute.FONT, font);
87        fontRenderContext = frc;
88    }    }
89    
90    public TextLayout (String string, Map attributes, FontRenderContext frc)    public TextLayout (String string, Map attributes, FontRenderContext frc)
91    {    {
92      // FIXME      attributedString = new AttributedString (string, attributes);
93      this.fontRenderContext = frc;      fontRenderContext = frc;
94    }    }
95    
96    protected Object clone ()    protected Object clone ()
# Line 100  public final class TextLayout implements Line 106  public final class TextLayout implements
106        }        }
107    }    }
108    
109    
110      protected class CharacterIteratorProxy
111        implements CharacterIterator
112      {
113        public CharacterIterator target;
114        public int begin;
115        public int limit;
116        public int index;
117    
118        public CharacterIteratorProxy (CharacterIterator ci)
119        {
120          target = ci;
121        }
122    
123        public int getBeginIndex ()
124        {
125          return begin;
126        }
127    
128        public int getEndIndex ()
129        {
130          return limit;
131        }
132    
133        public int getIndex ()
134        {
135          return index;
136        }
137    
138        public char setIndex (int idx)
139          throws IllegalArgumentException
140        {
141          if (idx < begin || idx >= limit)
142            throw new IllegalArgumentException ();
143          char ch = target.setIndex (idx);
144          index = idx;
145          return ch;
146        }
147    
148        public char first ()
149        {
150          int save = target.getIndex ();
151          char ch = target.setIndex (begin);
152          target.setIndex (save);
153          return ch;
154        }
155    
156        public char last ()
157        {
158          if (begin == limit)
159            return this.first ();
160    
161          int save = target.getIndex ();
162          char ch = target.setIndex (limit - 1);
163          target.setIndex (save);
164          return ch;
165        }
166    
167        public char current ()
168        {
169          return target.current();
170        }
171    
172        public char next ()
173        {
174          if (index >= limit - 1)
175            return CharacterIterator.DONE;
176          else
177            {
178              index++;
179              return target.next();
180            }
181        }
182    
183        public char previous ()
184        {
185          if (index <= begin)
186            return CharacterIterator.DONE;
187          else
188            {
189              index--;
190              return target.previous ();
191            }
192        }
193    
194        public Object clone ()
195        {
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;
201        }
202        
203      }
204    
205    
206    public void draw (Graphics2D g2, float x, float y)    public void draw (Graphics2D g2, float x, float y)
207    {    {
208      throw new Error ("not implemented");      AttributedCharacterIterator ci = attributedString.getIterator ();
209        CharacterIteratorProxy proxy = new CharacterIteratorProxy (ci);
210        Font defFont = g2.getFont ();
211    
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.
218         */
219    
220        for (char c = ci.first ();
221             c != CharacterIterator.DONE;
222             c = ci.next ())
223          {                
224            proxy.begin = ci.getIndex ();
225            proxy.limit = ci.getRunLimit(TextAttribute.FONT);
226            if (proxy.limit <= proxy.begin)
227              continue;
228    
229            proxy.index = proxy.begin;
230    
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);
237    
238            g2.drawGlyphVector (gv, x, y);
239    
240            int n = gv.getNumGlyphs ();
241            for (int i = 0; i < n; ++i)
242              {
243                GlyphMetrics gm = gv.getGlyphMetrics (i);
244                if (gm.getAdvanceX() == gm.getAdvance ())
245                  x += gm.getAdvanceX ();
246                else
247                  y += gm.getAdvanceY ();
248              }
249          }
250    }    }
251    
252    public boolean equals (Object obj)    public boolean equals (Object obj)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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