/[classpath]/classpath/java/awt/Font.java
ViewVC logotype

Diff of /classpath/java/awt/Font.java

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

revision 1.18.2.7 by gnu_andrew, Wed Sep 28 17:50:19 2005 UTC revision 1.18.2.8 by gnu_andrew, Wed Nov 2 00:43:30 2005 UTC
# Line 44  import gnu.java.awt.peer.ClasspathFontPe Line 44  import gnu.java.awt.peer.ClasspathFontPe
44  import java.awt.font.FontRenderContext;  import java.awt.font.FontRenderContext;
45  import java.awt.font.GlyphVector;  import java.awt.font.GlyphVector;
46  import java.awt.font.LineMetrics;  import java.awt.font.LineMetrics;
 import java.awt.font.TextAttribute;  
47  import java.awt.font.TextLayout;  import java.awt.font.TextLayout;
48  import java.awt.geom.AffineTransform;  import java.awt.geom.AffineTransform;
49  import java.awt.geom.Rectangle2D;  import java.awt.geom.Rectangle2D;
50  import java.awt.peer.FontPeer;  import java.awt.peer.FontPeer;
51  import java.io.IOException;  import java.io.IOException;
52  import java.io.InputStream;  import java.io.InputStream;
53    import java.io.ObjectInputStream;
54  import java.io.Serializable;  import java.io.Serializable;
55  import static java.text.AttributedCharacterIterator.Attribute;  import java.text.AttributedCharacterIterator;
56  import java.text.CharacterIterator;  import java.text.CharacterIterator;
57  import java.text.StringCharacterIterator;  import java.text.StringCharacterIterator;
58  import java.util.HashMap;  import java.util.HashMap;
# Line 70  import java.util.StringTokenizer; Line 70  import java.util.StringTokenizer;
70  public class Font implements Serializable  public class Font implements Serializable
71  {  {
72    
73  /*    /**
74   * Static Variables     * Constant indicating a "plain" font.
75   */     */
76      public static final int PLAIN = 0;
 /**  
   * Constant indicating a "plain" font.  
   */  
 public static final int PLAIN = 0;  
77    
78  /**    /**
79    * Constant indicating a "bold" font.     * Constant indicating a "bold" font.
80    */     */
81  public static final int BOLD = 1;    public static final int BOLD = 1;
82    
83  /**    /**
84    * Constant indicating an "italic" font.     * Constant indicating an "italic" font.
85    */     */
86  public static final int ITALIC = 2;    public static final int ITALIC = 2;
87    
88  /**    /**
89   * Constant indicating the baseline mode characteristic of Roman.     * Constant indicating the baseline mode characteristic of Roman.
90   */     */
91  public static final int ROMAN_BASELINE = 0;    public static final int ROMAN_BASELINE = 0;
92    
93  /**    /**
94   * Constant indicating the baseline mode characteristic of Chinese.     * Constant indicating the baseline mode characteristic of Chinese.
95   */     */
96  public static final int CENTER_BASELINE = 1;    public static final int CENTER_BASELINE = 1;
97    
98  /**    /**
99   * Constant indicating the baseline mode characteristic of Devanigri.     * Constant indicating the baseline mode characteristic of Devanigri.
100   */     */
101  public static final int HANGING_BASELINE = 2;      public static final int HANGING_BASELINE = 2;  
102    
103    
104    /**    /**
# Line 171  public static final int HANGING_BASELINE Line 167  public static final int HANGING_BASELINE
167    protected String name;    protected String name;
168    
169    /**    /**
170     * The size of this font in pixels.     * The size of this font in points, rounded.
171     *     *
172     * @since 1.0     * @since 1.0
173     */     */
174    protected int size;    protected int size;
175    
176    /**    /**
177       * The size of this font in points.
178       *
179       * @since 1.0
180       */
181      protected float pointSize;
182    
183      /**
184     * The style of this font -- PLAIN, BOLD, ITALIC or BOLD+ITALIC.     * The style of this font -- PLAIN, BOLD, ITALIC or BOLD+ITALIC.
185     *     *
186     * @since 1.0     * @since 1.0
187     */     */
188    protected int style;    protected int style;
189    
190  // Serialization constant  //Serialization constant
191  private static final long serialVersionUID = -4206021311591459213L;    private static final long serialVersionUID = -4206021311591459213L;
192    
193    
194    // The ClasspathToolkit-provided peer which implements this font    // The ClasspathToolkit-provided peer which implements this font
195    private ClasspathFontPeer peer;    private transient ClasspathFontPeer peer;
   
 /*************************************************************************/  
196    
 /*  
  * Static Methods  
  */  
197    
198  /**    /**
199    * Creates a <code>Font</code> object from the specified string, which     * Creates a <code>Font</code> object from the specified string, which
200    * is in one of the following formats:     * is in one of the following formats:
201    * <p>     * <p>
202    * <ul>     * <ul>
203    * <li>fontname-style-pointsize     * <li>fontname-style-pointsize
204    * <li>fontname-style     * <li>fontname-style
205    * <li>fontname-pointsize     * <li>fontname-pointsize
206    * <li>fontname     * <li>fontname
207    * </ul>     * </ul>
208    * <p>     * <p>
209    * The style should be one of BOLD, ITALIC, or BOLDITALIC.  The default     * The style should be one of BOLD, ITALIC, or BOLDITALIC.  The default
210    * style if none is specified is PLAIN.  The default size if none     * style if none is specified is PLAIN.  The default size if none
211    * is specified is 12.     * is specified is 12.
212    *     *
213    * @param fontspec  a string specifying the required font (<code>null</code>     * @param fontspec  a string specifying the required font (<code>null</code>
214    *                  permitted, interpreted as 'Dialog-PLAIN-12').     *                  permitted, interpreted as 'Dialog-PLAIN-12').
215    *     *
216    * @return A font.     * @return A font.
217    */     */
218    public static Font decode (String fontspec)    public static Font decode(String fontspec)
219  {    {
220    if (fontspec == null)      if (fontspec == null)
221      fontspec = "Dialog-PLAIN-12";        fontspec = "Dialog-PLAIN-12";
222    String name = null;      String name = null;
223    int style = PLAIN;      int style = PLAIN;
224    int size = 12;      int size = 12;
225    
226    StringTokenizer st = new StringTokenizer(fontspec, "- ");      StringTokenizer st = new StringTokenizer(fontspec, "- ");
227    while (st.hasMoreTokens())      while (st.hasMoreTokens())
228      {        {
229        String token = st.nextToken();          String token = st.nextToken();
230        if (name == null)          if (name == null)
231          {            {
232            name = token;              name = token;
233            continue;              continue;
234          }            }
235    
236        if (token.toUpperCase().equals("BOLD"))          if (token.toUpperCase().equals("BOLD"))
237          {            {
238            style = BOLD;              style = BOLD;
239            continue;              continue;
240          }            }
241        if (token.toUpperCase().equals("ITALIC"))          if (token.toUpperCase().equals("ITALIC"))
242          {            {
243            style = ITALIC;              style = ITALIC;
244            continue;              continue;
245          }            }
246        if (token.toUpperCase().equals("BOLDITALIC"))          if (token.toUpperCase().equals("BOLDITALIC"))
247          {            {
248              style = BOLD | ITALIC;              style = BOLD | ITALIC;
249            continue;              continue;
250          }            }
251    
252        int tokenval = 0;          int tokenval = 0;
253        try          try
254          {            {
255            tokenval = Integer.parseInt(token);              tokenval = Integer.parseInt(token);
256          }            }
257        catch(NumberFormatException e)          catch (NumberFormatException e)
258          {            {
259            // Ignored.              // Ignored.
260          }            }
261    
262        if (tokenval != 0)        if (tokenval != 0)
263          size = tokenval;          size = tokenval;
264      }      }
265    
266      HashMap attrs = new HashMap();      HashMap attrs = new HashMap();
267      ClasspathFontPeer.copyStyleToAttrs (style, attrs);      ClasspathFontPeer.copyStyleToAttrs(style, attrs);
268      ClasspathFontPeer.copySizeToAttrs (size, attrs);      ClasspathFontPeer.copySizeToAttrs(size, attrs);
269    
270      return getFontFromToolkit (name, attrs);      return getFontFromToolkit(name, attrs);
271  }    }
272    
273    /* These methods delegate to the toolkit. */    /* These methods delegate to the toolkit. */
274    
275    protected static ClasspathToolkit tk ()    static ClasspathToolkit tk()
276    {    {
277      return (ClasspathToolkit)(Toolkit.getDefaultToolkit ());      return (ClasspathToolkit) Toolkit.getDefaultToolkit();
278    }    }
279    
280    /* Every factory method in Font should eventually call this. */    /* Every factory method in Font should eventually call this. */
281    protected static Font getFontFromToolkit (String name, Map attribs)    static Font getFontFromToolkit(String name, Map attribs)
282    {    {
283      return tk ().getFont (name, attribs);      return tk().getFont(name, attribs);
284    }    }
285    
286    /* Every Font constructor should eventually call this. */    /* Every Font constructor should eventually call this. */
287    protected static ClasspathFontPeer getPeerFromToolkit (String name, Map attrs)    static ClasspathFontPeer getPeerFromToolkit(String name, Map attrs)
288    {    {
289      return tk ().getClasspathFontPeer (name, attrs);      return tk().getClasspathFontPeer(name, attrs);
290    }    }
291    
292    
293  /*************************************************************************/    /**
294       * Returns a <code>Font</code> object from the passed property name.
295  /**     *
296    * Returns a <code>Font</code> object from the passed property name.     * @param propname The name of the system property.
297    *     * @param defval Value to use if the property is not found.
298    * @param propname The name of the system property.     *
299    * @param defval Value to use if the property is not found.     * @return The requested font, or <code>default</code> if the property
300    *     * not exist or is malformed.
301    * @return The requested font, or <code>default</code> if the property     */
302    * not exist or is malformed.    public static Font getFont(String propname, Font defval)
303    */    {
304    public static Font getFont (String propname, Font defval)      String propval = System.getProperty(propname);
305  {      if (propval != null)
306    String propval = System.getProperty(propname);        return decode(propval);
   if (propval != null)  
       return decode (propval);  
307      return defval;      return defval;
308  }    }
   
 /*************************************************************************/  
   
 /**  
   * Returns a <code>Font</code> object from the passed property name.  
   *  
   * @param propname The name of the system property.  
   *  
   * @return The requested font, or <code>null</code> if the property  
   * not exist or is malformed.  
   */  
   public static Font getFont (String propname)  
 {  
     return getFont (propname, (Font)null);  
 }  
   
 /*************************************************************************/  
   
 /*  
  * Constructors  
  */  
309    
310  /**    /**
311    * Initializes a new instance of <code>Font</code> with the specified     * Returns a <code>Font</code> object from the passed property name.
312    * attributes.     *
313    *     * @param propname The name of the system property.
314    * @param name The name of the font.     *
315    * @param style The font style.     * @return The requested font, or <code>null</code> if the property
316    * @param size The font point size.     * not exist or is malformed.
317    */     */
318      public static Font getFont(String propname)
319      {
320        return getFont(propname, (Font) null);
321      }
322    
323    public Font (String name, int style, int size)    /**
324       * Initializes a new instance of <code>Font</code> with the specified
325       * attributes.
326       *
327       * @param name The name of the font.
328       * @param style The font style.
329       * @param size The font point size.
330       */
331      public Font(String name, int style, int size)
332    {    {
333      HashMap attrs = new HashMap();      HashMap attrs = new HashMap();
334      ClasspathFontPeer.copyStyleToAttrs (style, attrs);      ClasspathFontPeer.copyStyleToAttrs(style, attrs);
335      ClasspathFontPeer.copySizeToAttrs (size, attrs);      ClasspathFontPeer.copySizeToAttrs(size, attrs);
336      this.peer = getPeerFromToolkit (name, attrs);      this.peer = getPeerFromToolkit(name, attrs);
337        this.size = size;
338        this.pointSize = (float) size;
339        if (name != null)
340          this.name = name;
341        else
342          this.name = peer.getName(this);
343    }    }
344    
345    public Font (Map<? extends Attribute, ?> attrs)    public Font(Map attrs)
346    {    {
347      this(null, attrs);      this(null, attrs);
348    }    }
349    
350    /* This extra constructor is here to permit ClasspathToolkit and to    /* This extra constructor is here to permit ClasspathToolkit and to
351       build a font with a "logical name" as well as attrs.     build a font with a "logical name" as well as attrs.
352       ClasspathToolkit.getFont(String,Map) uses reflection to call this     ClasspathToolkit.getFont(String,Map) uses reflection to call this
353       package-private constructor. */     package-private constructor. */
354    Font (String name, Map attrs)    Font(String name, Map attrs)
355    {    {
356      // If attrs is null, setting it to an empty HashMap will give this      // If attrs is null, setting it to an empty HashMap will give this
357      // Font default attributes.      // Font default attributes.
358      if (attrs == null)      if (attrs == null)
359        attrs = new HashMap();        attrs = new HashMap();
360      this.peer = getPeerFromToolkit (name, attrs);      peer = getPeerFromToolkit(name, attrs);
361        size = (int) peer.getSize(this);
362        pointSize = peer.getSize(this);
363        if (name != null)
364          this.name = name;
365        else
366          this.name = peer.getName(this);
367    }    }
368    
369  /*************************************************************************/    /**
   
 /*  
  * Instance Methods  
  */  
   
 /**  
370     * Returns the logical name of the font.  A logical name is the name the     * Returns the logical name of the font.  A logical name is the name the
371     * font was constructed with. It may be the name of a logical font (one     * font was constructed with. It may be the name of a logical font (one
372     * of 6 required names in all java environments) or it may be a face     * of 6 required names in all java environments) or it may be a face
373     * name.     * name.
374    *     *
375    * @return The logical name of the font.     * @return The logical name of the font.
376    *     *
377    * @see #getFamily()     * @see #getFamily()
378    * @see #getFontName()     * @see #getFontName()
379    */     */
380    public String getName ()    public String getName ()
381  {    {
382      return peer.getName (this);      return peer.getName(this);
383  }    }
   
 /*************************************************************************/  
   
 /**  
   * Returns the style of the font.  
   *  
   * @return The font style.  
   */  
   public int getSize ()  
 {  
     return (int) peer.getSize (this);  
 }  
   
   public float getSize2D ()  
 {  
     return peer.getSize (this);  
 }  
   
 /*************************************************************************/  
   
 /**  
   * Tests whether or not this is a plain font.  This will be true if  
   * and only if neither the bold nor the italics style is set.  
   *  
   * @return <code>true</code> if this is a plain font, <code>false</code>  
   * otherwise.  
   */  
   public boolean isPlain ()  
 {  
     return peer.isPlain (this);  
 }  
384    
385  /*************************************************************************/    /**
386       * Returns the size of the font, in typographics points (1/72 of an inch),
387       * rounded to an integer.
388       *
389       * @return The font size
390       */
391      public int getSize()
392      {
393        return size;
394      }
395    
396  /**    /**
397    * Tests whether or not this font is bold.     * Returns the size of the font, in typographics points (1/72 of an inch).
398    *     *
399    * @return <code>true</code> if this font is bold, <code>false</code>     * @return The font size
400    * otherwise.     */
401    */    public float getSize2D()
402    public boolean isBold ()    {
403  {      return pointSize;
404      return peer.isBold (this);    }
 }  
405    
406  /*************************************************************************/    /**
407       * Tests whether or not this is a plain font.  This will be true if
408       * and only if neither the bold nor the italics style is set.
409       *
410       * @return <code>true</code> if this is a plain font, <code>false</code>
411       * otherwise.
412       */
413      public boolean isPlain()
414      {
415        return peer.isPlain(this);
416      }
417    
418  /**    /**
419    * Tests whether or not this font is italic.     * Tests whether or not this font is bold.
420    *     *
421    * @return <code>true</code> if this font is italic, <code>false</code>     * @return <code>true</code> if this font is bold, <code>false</code>
422    * otherwise.     * otherwise.
423    */     */
424    public boolean isItalic ()    public boolean isBold()
425  {    {
426      return peer.isItalic (this);      return peer.isBold(this);
427  }    }
428    
429  /*************************************************************************/    /**
430       * Tests whether or not this font is italic.
431       *
432       * @return <code>true</code> if this font is italic, <code>false</code>
433       * otherwise.
434       */
435      public boolean isItalic()
436      {
437        return peer.isItalic(this);
438      }
439    
440  /**    /**
441     * Returns the family name of this font. A family name describes a design     * Returns the family name of this font. A family name describes a design
442     * or "brand name" (such as Helvetica or Palatino). It is less specific     * or "brand name" (such as Helvetica or Palatino). It is less specific
443     * than a font face name (such as Helvetica Bold).     * than a font face name (such as Helvetica Bold).
444    *     *
445    * @return A string containing the font family name.     * @return A string containing the font family name.
446    *     *
447    * @since 1.2     * @since 1.2
448    *     *
449    * @see #getName()     * @see #getName()
450    * @see #getFontName()     * @see #getFontName()
451    * @see GraphicsEnvironment#getAvailableFontFamilyNames()     * @see GraphicsEnvironment#getAvailableFontFamilyNames()
452    */     */
453    public String getFamily ()    public String getFamily()
454  {    {
455      return peer.getFamily (this);      return peer.getFamily(this);
456  }    }
457    
458  /**    /**
459    * Returns integer code representing the sum of style flags of this font, a     * Returns integer code representing the sum of style flags of this font, a
460    * combination of either {@link #PLAIN}, {@link #BOLD}, or {@link #ITALIC}.     * combination of either {@link #PLAIN}, {@link #BOLD}, or {@link #ITALIC}.
461    *     *
462    * @return code representing the style of this font.     * @return code representing the style of this font.
463    *     *
464    * @see #isPlain()     * @see #isPlain()
465    * @see #isBold()     * @see #isBold()
466    * @see #isItalic()     * @see #isItalic()
467    */     */
468    public int getStyle ()    public int getStyle()
469  {    {
470      return peer.getStyle (this);      return peer.getStyle(this);
471  }    }
472    
473  /**    /**
474    * Checks if specified character maps to a glyph in this font.     * Checks if specified character maps to a glyph in this font.
475    *     *
476    * @param c The character to check.     * @param c The character to check.
477    *     *
478    * @return Whether the character has a corresponding glyph in this font.     * @return Whether the character has a corresponding glyph in this font.
479    *     *
480    * @since 1.2     * @since 1.2
481    */     */
482    public boolean canDisplay (char c)    public boolean canDisplay(char c)
483  {    {
484      return peer.canDisplay (this, c);          return peer.canDisplay(this, c);    
485  }    }
486    
487  /**    /**
488    * Checks how much of a given string can be mapped to glyphs in     * Checks how much of a given string can be mapped to glyphs in
489    * this font.     * this font.
490    *     *
491    * @param s The string to check.     * @param s The string to check.
492    *     *
493    * @return The index of the first character in <code>s</code> which cannot     * @return The index of the first character in <code>s</code> which cannot
494    * be converted to a glyph by this font, or <code>-1</code> if all     * be converted to a glyph by this font, or <code>-1</code> if all
495    * characters can be mapped to glyphs.     * characters can be mapped to glyphs.
496    *     *
497    * @since 1.2     * @since 1.2
498    */     */
499    public int canDisplayUpTo (String s)    public int canDisplayUpTo(String s)
500  {    {
501      return peer.canDisplayUpTo (this, new StringCharacterIterator (s),      return peer.canDisplayUpTo(this, new StringCharacterIterator(s),
502                                  0, s.length () - 1);                                 0, s.length() - 1);
503  }    }
504    
505  /**    /**
506    * Checks how much of a given sequence of text can be mapped to glyphs in     * Checks how much of a given sequence of text can be mapped to glyphs in
507    * this font.     * this font.
508    *     *
509    * @param text Array containing the text to check.     * @param text Array containing the text to check.
510    * @param start Position of first character to check in <code>text</code>.     * @param start Position of first character to check in <code>text</code>.
511    * @param limit Position of last character to check in <code>text</code>.     * @param limit Position of last character to check in <code>text</code>.
512    *     *
513    * @return The index of the first character in the indicated range which     * @return The index of the first character in the indicated range which
514    * cannot be converted to a glyph by this font, or <code>-1</code> if all     * cannot be converted to a glyph by this font, or <code>-1</code> if all
515    * characters can be mapped to glyphs.     * characters can be mapped to glyphs.
516    *     *
517    * @since 1.2     * @since 1.2
518    *     *
519    * @throws IndexOutOfBoundsException if the range [start, limit] is     * @throws IndexOutOfBoundsException if the range [start, limit] is
520    * invalid in <code>text</code>.     * invalid in <code>text</code>.
521    */     */
522    public int canDisplayUpTo (char[] text, int start, int limit)    public int canDisplayUpTo (char[] text, int start, int limit)
523  {    {
524      return peer.canDisplayUpTo      return peer.canDisplayUpTo(this,
525        (this, new StringCharacterIterator (new String (text)), start, limit);                                 new StringCharacterIterator(new String (text)),
526  }                                 start, limit);
527      }
 /**  
   * Checks how much of a given sequence of text can be mapped to glyphs in  
   * this font.  
   *  
   * @param i Iterator over the text to check.  
   * @param start Position of first character to check in <code>i</code>.  
   * @param limit Position of last character to check in <code>i</code>.  
   *  
   * @return The index of the first character in the indicated range which  
   * cannot be converted to a glyph by this font, or <code>-1</code> if all  
   * characters can be mapped to glyphs.  
   *  
   * @since 1.2  
   *  
   * @throws IndexOutOfBoundsException if the range [start, limit] is  
   * invalid in <code>i</code>.  
   */  
   public int canDisplayUpTo (CharacterIterator i, int start, int limit)  
 {  
     return peer.canDisplayUpTo (this, i, start, limit);      
 }  
528    
529  /**    /**
530    * Creates a new font with point size 1 and {@link #PLAIN} style,     * Checks how much of a given sequence of text can be mapped to glyphs in
531    * reading font data from the provided input stream. The resulting font     * this font.
532    * can have further fonts derived from it using its     *
533    * <code>deriveFont</code> method.     * @param i Iterator over the text to check.
534    *     * @param start Position of first character to check in <code>i</code>.
535    * @param fontFormat Integer code indicating the format the font data is     * @param limit Position of last character to check in <code>i</code>.
536    * in.Currently this can only be {@link #TRUETYPE_FONT}.     *
537    * @param is {@link InputStream} from which font data will be read. This     * @return The index of the first character in the indicated range which
538    * stream is not closed after font data is extracted.     * cannot be converted to a glyph by this font, or <code>-1</code> if all
539    *     * characters can be mapped to glyphs.
540    * @return A new {@link Font} of the format indicated.     *
541    *     * @since 1.2
542    * @throws IllegalArgumentException if <code>fontType</code> is not     *
543    * recognized.     * @throws IndexOutOfBoundsException if the range [start, limit] is
544    * @throws FontFormatException if data in InputStream is not of format     * invalid in <code>i</code>.
545    * indicated.     */
546    * @throws IOException if insufficient data is present on InputStream.    public int canDisplayUpTo(CharacterIterator i, int start, int limit)
547    *    {
548    * @since 1.3      return peer.canDisplayUpTo(this, i, start, limit);    
549    */    }
   public static Font createFont (int fontFormat, InputStream is)  
   throws FontFormatException, IOException  
 {  
     return tk().createFont (fontFormat, is);  
 }  
550    
551  /**    /**
552    * Maps characters to glyphs in a one-to-one relationship, returning a new     * Creates a new font with point size 1 and {@link #PLAIN} style,
553    * {@link GlyphVector} with a mapped glyph for each input character. This     * reading font data from the provided input stream. The resulting font
554    * sort of mapping is often sufficient for some scripts such as Roman, but     * can have further fonts derived from it using its
555    * is inappropriate for scripts with special shaping or contextual layout     * <code>deriveFont</code> method.
556    * requirements such as Arabic, Indic, Hebrew or Thai.     *
557    *     * @param fontFormat Integer code indicating the format the font data is
558    * @param ctx The rendering context used for precise glyph placement.     * in.Currently this can only be {@link #TRUETYPE_FONT}.
559    * @param str The string to convert to Glyphs.     * @param is {@link InputStream} from which font data will be read. This
560    *     * stream is not closed after font data is extracted.
561    * @return A new {@link GlyphVector} containing glyphs mapped from str,     *
562    * through the font's cmap table.     * @return A new {@link Font} of the format indicated.
563    *     *
564    * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)     * @throws IllegalArgumentException if <code>fontType</code> is not
565    */     * recognized.
566    public GlyphVector createGlyphVector (FontRenderContext ctx, String str)     * @throws FontFormatException if data in InputStream is not of format
567  {     * indicated.
568      return peer.createGlyphVector (this, ctx, new StringCharacterIterator (str));     * @throws IOException if insufficient data is present on InputStream.
569  }     *
570       * @since 1.3
571       */
572      public static Font createFont (int fontFormat, InputStream is)
573        throws FontFormatException, IOException
574      {
575        return tk().createFont(fontFormat, is);
576      }
577    
578  /**    /**
579    * Maps characters to glyphs in a one-to-one relationship, returning a new     * Maps characters to glyphs in a one-to-one relationship, returning a new
580    * {@link GlyphVector} with a mapped glyph for each input character. This     * {@link GlyphVector} with a mapped glyph for each input character. This
581    * sort of mapping is often sufficient for some scripts such as Roman, but     * sort of mapping is often sufficient for some scripts such as Roman, but
582    * is inappropriate for scripts with special shaping or contextual layout     * is inappropriate for scripts with special shaping or contextual layout
583    * requirements such as Arabic, Indic, Hebrew or Thai.     * requirements such as Arabic, Indic, Hebrew or Thai.
584    *     *
585    * @param ctx The rendering context used for precise glyph placement.     * @param ctx The rendering context used for precise glyph placement.
586    * @param i Iterator over the text to convert to glyphs.     * @param str The string to convert to Glyphs.
587    *     *
588    * @return A new {@link GlyphVector} containing glyphs mapped from str,     * @return A new {@link GlyphVector} containing glyphs mapped from str,
589    * through the font's cmap table.     * through the font's cmap table.
590    *     *
591    * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)     * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)
592    */     */
593    public GlyphVector createGlyphVector (FontRenderContext ctx, CharacterIterator i)    public GlyphVector createGlyphVector(FontRenderContext ctx, String str)
594  {    {
595      return peer.createGlyphVector (this, ctx, i);      return peer.createGlyphVector(this, ctx, new StringCharacterIterator(str));
596  }    }
597    
598  /**    /**
599    * Maps characters to glyphs in a one-to-one relationship, returning a new     * Maps characters to glyphs in a one-to-one relationship, returning a new
600    * {@link GlyphVector} with a mapped glyph for each input character. This     * {@link GlyphVector} with a mapped glyph for each input character. This
601    * sort of mapping is often sufficient for some scripts such as Roman, but     * sort of mapping is often sufficient for some scripts such as Roman, but
602    * is inappropriate for scripts with special shaping or contextual layout     * is inappropriate for scripts with special shaping or contextual layout
603    * requirements such as Arabic, Indic, Hebrew or Thai.     * requirements such as Arabic, Indic, Hebrew or Thai.
604    *     *
605    * @param ctx The rendering context used for precise glyph placement.     * @param ctx The rendering context used for precise glyph placement.
606    * @param chars Array of characters to convert to glyphs.     * @param i Iterator over the text to convert to glyphs.
607    *     *
608    * @return A new {@link GlyphVector} containing glyphs mapped from str,     * @return A new {@link GlyphVector} containing glyphs mapped from str,
609    * through the font's cmap table.     * through the font's cmap table.
610    *     *
611    * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)     * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)
612    */     */
613    public GlyphVector createGlyphVector (FontRenderContext ctx, char[] chars)    public GlyphVector createGlyphVector(FontRenderContext ctx,
614  {                                         CharacterIterator i)
615      return peer.createGlyphVector    {
616        (this, ctx, new StringCharacterIterator (new String (chars)));      return peer.createGlyphVector(this, ctx, i);
617  }    }
618    
619  /**    /**
620    * Extracts a sequence of glyphs from a font, returning a new {@link     * Maps characters to glyphs in a one-to-one relationship, returning a new
621    * GlyphVector} with a mapped glyph for each input glyph code.     * {@link GlyphVector} with a mapped glyph for each input character. This
622    *     * sort of mapping is often sufficient for some scripts such as Roman, but
623    * @param ctx The rendering context used for precise glyph placement.     * is inappropriate for scripts with special shaping or contextual layout
624    * @param glyphCodes Array of characters to convert to glyphs.     * requirements such as Arabic, Indic, Hebrew or Thai.
625    *     *
626    * @return A new {@link GlyphVector} containing glyphs mapped from str,     * @param ctx The rendering context used for precise glyph placement.
627    * through the font's cmap table.     * @param chars Array of characters to convert to glyphs.
628    *     *
629    * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)     * @return A new {@link GlyphVector} containing glyphs mapped from str,
630    *     * through the font's cmap table.
631    * @specnote This method is documented to perform character-to-glyph     *
632    * conversions, in the Sun documentation, but its second parameter name is     * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)
633    * "glyphCodes" and it is not clear to me why it would exist if its     */
634    * purpose was to transport character codes inside integers. I assume it    public GlyphVector createGlyphVector(FontRenderContext ctx, char[] chars)
635    * is mis-documented in the Sun documentation.    {
636    */      return peer.createGlyphVector(this, ctx,
637                                   new StringCharacterIterator(new String(chars)));
638      }
639    
640    public GlyphVector createGlyphVector (FontRenderContext ctx, int[] glyphCodes)    /**
641  {     * Extracts a sequence of glyphs from a font, returning a new {@link
642      return peer.createGlyphVector (this, ctx, glyphCodes);     * GlyphVector} with a mapped glyph for each input glyph code.
643  }     *
644       * @param ctx The rendering context used for precise glyph placement.
645       * @param glyphCodes Array of characters to convert to glyphs.
646       *
647       * @return A new {@link GlyphVector} containing glyphs mapped from str,
648       * through the font's cmap table.
649       *
650       * @see #layoutGlyphVector(FontRenderContext, char[], int, int, int)
651       *
652       * @specnote This method is documented to perform character-to-glyph
653       * conversions, in the Sun documentation, but its second parameter name is
654       * "glyphCodes" and it is not clear to me why it would exist if its
655       * purpose was to transport character codes inside integers. I assume it
656       * is mis-documented in the Sun documentation.
657       */
658      public GlyphVector createGlyphVector(FontRenderContext ctx, int[] glyphCodes)
659      {
660        return peer.createGlyphVector(this, ctx, glyphCodes);
661      }
662    
663  /**    /**
664    * Produces a new {@link Font} based on the current font, adjusted to a     * Produces a new {@link Font} based on the current font, adjusted to a
665    * new size and style.     * new size and style.
666    *     *
667    * @param style The style of the newly created font.     * @param style The style of the newly created font.
668    * @param size The size of the newly created font.     * @param size The size of the newly created font.
669    *     *
670    * @return A clone of the current font, with the specified size and style.     * @return A clone of the current font, with the specified size and style.
671    *     *
672    * @since 1.2     * @since 1.2
673    */     */
674    public Font deriveFont (int style, float size)    public Font deriveFont(int style, float size)
675  {    {
676      return peer.deriveFont (this, style, size);      return peer.deriveFont(this, style, size);
677  }    }
678    
679  /**    /**
680    * Produces a new {@link Font} based on the current font, adjusted to a     * Produces a new {@link Font} based on the current font, adjusted to a
681    * new size.     * new size.
682    *     *
683    * @param size The size of the newly created font.     * @param size The size of the newly created font.
684    *     *
685    * @return A clone of the current font, with the specified size.     * @return A clone of the current font, with the specified size.
686    *     *
687    * @since 1.2     * @since 1.2
688    */     */
689    public Font deriveFont (float size)    public Font deriveFont(float size)
690  {    {
691      return peer.deriveFont (this, size);      return peer.deriveFont(this, size);
692  }    }
693    
694  /**    /**
695    * Produces a new {@link Font} based on the current font, adjusted to a     * Produces a new {@link Font} based on the current font, adjusted to a
696    * new style.     * new style.
697    *     *
698    * @param style The style of the newly created font.     * @param style The style of the newly created font.
699    *     *
700    * @return A clone of the current font, with the specified style.     * @return A clone of the current font, with the specified style.
701    *     *
702    * @since 1.2     * @since 1.2
703    */     */
704    public Font deriveFont (int style)    public Font deriveFont(int style)
705  {    {
706      return peer.deriveFont (this, style);      return peer.deriveFont(this, style);
707  }    }
708    
709  /**    /**
710    * Produces a new {@link Font} based on the current font, adjusted to a     * Produces a new {@link Font} based on the current font, adjusted to a
711    * new style and subjected to a new affine transformation.     * new style and subjected to a new affine transformation.
712    *     *
713    * @param style The style of the newly created font.     * @param style The style of the newly created font.
714    * @param a The transformation to apply.     * @param a The transformation to apply.
715    *     *
716    * @return A clone of the current font, with the specified style and     * @return A clone of the current font, with the specified style and
717    * transform.     * transform.
718    *     *
719    * @throws IllegalArgumentException If transformation is     * @throws IllegalArgumentException If transformation is
720    * <code>null</code>.     * <code>null</code>.
721    *     *
722    * @since 1.2     * @since 1.2
723    */     */
724    public Font deriveFont (int style, AffineTransform a)    public Font deriveFont(int style, AffineTransform a)
725  {    {
726      if (a == null)      if (a == null)
727        throw new IllegalArgumentException ("Affine transformation is null");        throw new IllegalArgumentException("Affine transformation is null");
728    
729      return peer.deriveFont (this, style, a);      return peer.deriveFont(this, style, a);
730  }    }
731    
732  /**    /**
733    * Produces a new {@link Font} based on the current font, subjected     * Produces a new {@link Font} based on the current font, subjected
734    * to a new affine transformation.     * to a new affine transformation.
735    *     *
736    * @param a The transformation to apply.     * @param a The transformation to apply.
737    *     *
738    * @return A clone of the current font, with the specified transform.     * @return A clone of the current font, with the specified transform.
739    *     *
740    * @throws IllegalArgumentException If transformation is     * @throws IllegalArgumentException If transformation is
741    * <code>null</code>.     * <code>null</code>.
742    *     *
743    * @since 1.2     * @since 1.2
744    */     */
745    public Font deriveFont (AffineTransform a)    public Font deriveFont(AffineTransform a)
746  {    {
747      if (a == null)      if (a == null)
748        throw new IllegalArgumentException ("Affine transformation is null");        throw new IllegalArgumentException("Affine transformation is null");
749    
750      return peer.deriveFont (this, a);      return peer.deriveFont(this, a);
751  }    }
752    
753  /**    /**
754    * Produces a new {@link Font} based on the current font, adjusted to a     * Produces a new {@link Font} based on the current font, adjusted to a
755    * new set of attributes.     * new set of attributes.
756    *     *
757    * @param attributes Attributes of the newly created font.     * @param attributes Attributes of the newly created font.
758    *     *
759    * @return A clone of the current font, with the specified attributes.     * @return A clone of the current font, with the specified attributes.
760    *     *
761    * @since 1.2     * @since 1.2
762    */     */
763    public Font deriveFont (Map<? extends Attribute, ?> attributes)    public Font deriveFont(Map attributes)
764  {    {
765      return peer.deriveFont (this, attributes);      return peer.deriveFont(this, attributes);
766  }    }
767    
768  /**    /**
769    * Returns a map of chracter attributes which this font currently has set.     * Returns a map of chracter attributes which this font currently has set.
770    *     *
771    * @return A map of chracter attributes which this font currently has set.     * @return A map of chracter attributes which this font currently has set.
772    *     *
773    * @see #getAvailableAttributes()     * @see #getAvailableAttributes()
774    * @see java.text.AttributedCharacterIterator.Attribute     * @see java.text.AttributedCharacterIterator.Attribute
775    * @see java.awt.font.TextAttribute     * @see java.awt.font.TextAttribute
776    */     */
777    public Map<TextAttribute,?> getAttributes ()    public Map getAttributes()
778  {    {
779    return peer.getAttributes (this);      return peer.getAttributes(this);
780  }    }
781    
782  /**    /**
783    * Returns an array of chracter attribute keys which this font understands.     * Returns an array of chracter attribute keys which this font understands.
784    *     *
785    * @return An array of chracter attribute keys which this font understands.     * @return An array of chracter attribute keys which this font understands.
786    *     *
787    * @see #getAttributes()     * @see #getAttributes()
788    * @see java.text.AttributedCharacterIterator.Attribute     * @see java.text.AttributedCharacterIterator.Attribute
789    * @see java.awt.font.TextAttribute     * @see java.awt.font.TextAttribute
790    */     */
791    public Attribute[] getAvailableAttributes()    public AttributedCharacterIterator.Attribute[] getAvailableAttributes()
792  {    {
793      return peer.getAvailableAttributes (this);      return peer.getAvailableAttributes(this);
794  }    }
795    
796  /**    /**
797    * Returns a baseline code (one of {@link #ROMAN_BASELINE}, {@link     * Returns a baseline code (one of {@link #ROMAN_BASELINE}, {@link
798    * #CENTER_BASELINE} or {@link #HANGING_BASELINE}) indicating which baseline     * #CENTER_BASELINE} or {@link #HANGING_BASELINE}) indicating which baseline
799    * this font will measure baseline offsets for, when presenting glyph     * this font will measure baseline offsets for, when presenting glyph
800    * metrics for a given character.     * metrics for a given character.
801    *     *
802    * Baseline offsets describe the position of a glyph relative to an     * Baseline offsets describe the position of a glyph relative to an
803    * invisible line drawn under, through the center of, or over a line of     * invisible line drawn under, through the center of, or over a line of
804    * rendered text, respectively. Different scripts use different baseline     * rendered text, respectively. Different scripts use different baseline
805    * modes, so clients should not assume all baseline offsets in a glyph     * modes, so clients should not assume all baseline offsets in a glyph
806    * vector are from a common baseline.     * vector are from a common baseline.
807    *     *
808    * @param c The character code to select a baseline mode for.     * @param c The character code to select a baseline mode for.
809    *     *
810    * @return The baseline mode which would be used in a glyph associated     * @return The baseline mode which would be used in a glyph associated
811    * with the provided character.     * with the provided character.
812    *     *
813    * @since 1.2     * @since 1.2
814    *     *
815    * @see LineMetrics#getBaselineOffsets()     * @see LineMetrics#getBaselineOffsets()
816    */     */
817    public byte getBaselineFor (char c)    public byte getBaselineFor(char c)
818  {    {
819      return peer.getBaselineFor (this, c);      return peer.getBaselineFor(this, c);
820  }    }
821    
822  /**    /**
823    * Returns the family name of this font. A family name describes a     * Returns the family name of this font. A family name describes a
824    * typographic style (such as Helvetica or Palatino). It is more specific     * typographic style (such as Helvetica or Palatino). It is more specific
825    * than a logical font name (such as Sans Serif) but less specific than a     * than a logical font name (such as Sans Serif) but less specific than a
826    * font face name (such as Helvetica Bold).     * font face name (such as Helvetica Bold).
827    *     *
828    * @param lc The locale in which to describe the name of the font family.     * @param lc The locale in which to describe the name of the font family.
829    *     *
830    * @return A string containing the font family name, localized for the     * @return A string containing the font family name, localized for the
831    * provided locale.     * provided locale.
832    *     *
833    * @since 1.2     * @since 1.2
834    *     *
835    * @see #getName()     * @see #getName()
836    * @see #getFontName()     * @see #getFontName()
837    * @see GraphicsEnvironment#getAvailableFontFamilyNames()     * @see GraphicsEnvironment#getAvailableFontFamilyNames()
838    * @see Locale     * @see Locale
839    */     */
840    public String getFamily (Locale lc)    public String getFamily(Locale lc)
841  {    {
842      return peer.getFamily (this, lc);      return peer.getFamily(this, lc);
843  }    }
844    
845  /**    /**
846    * Returns a font appropriate for the given attribute set.     * Returns a font appropriate for the given attribute set.
847    *     *
848    * @param attributes The attributes required for the new font.     * @param attributes The attributes required for the new font.
849    *     *
850    * @return A new Font with the given attributes.     * @return A new Font with the given attributes.
851    *     *
852    * @since 1.2     * @since 1.2
853    *     *
854    * @see java.awt.font.TextAttribute       * @see java.awt.font.TextAttribute  
855    */     */
856    public static Font getFont (Map<? extends Attribute, ?> attributes)    public static Font getFont(Map attributes)
857  {    {
858      return getFontFromToolkit (null, attributes);      return getFontFromToolkit(null, attributes);
859  }    }
860    
861  /**    /**
862    * Returns the font face name of the font.  A font face name describes a     * Returns the font face name of the font.  A font face name describes a
863    * specific variant of a font family (such as Helvetica Bold). It is more     * specific variant of a font family (such as Helvetica Bold). It is more
864    * specific than both a font family name (such as Helvetica) and a logical     * specific than both a font family name (such as Helvetica) and a logical
865    * font name (such as Sans Serif).     * font name (such as Sans Serif).
866    *     *
867    * @return The font face name of the font.     * @return The font face name of the font.
868    *     *
869    * @since 1.2     * @since 1.2
870    *     *
871    * @see #getName()     * @see #getName()
872    * @see #getFamily()     * @see #getFamily()
873    */     */
874    public String getFontName ()    public String getFontName()
875  {    {
876      return peer.getFontName (this);      return peer.getFontName(this);
877  }    }
878    
879  /**    /**
880    * Returns the font face name of the font.  A font face name describes a     * Returns the font face name of the font.  A font face name describes a
881    * specific variant of a font family (such as Helvetica Bold). It is more     * specific variant of a font family (such as Helvetica Bold). It is more
882     * specific than both a font family name (such as Helvetica).     * specific than both a font family name (such as Helvetica).
883    *     *
884    * @param lc The locale in which to describe the name of the font face.     * @param lc The locale in which to describe the name of the font face.
885    *     *
886    * @return A string containing the font face name, localized for the     * @return A string containing the font face name, localized for the
887    * provided locale.     * provided locale.
888    *     *
889    * @since 1.2     * @since 1.2
890    *     *
891    * @see #getName()     * @see #getName()
892    * @see #getFamily()     * @see #getFamily()
893    */     */
894    public String getFontName (Locale lc)    public String getFontName(Locale lc)
895  {    {
896      return peer.getFontName (this, lc);      return peer.getFontName(this, lc);
897  }    }
898    
899  /**    /**
900    * Returns the italic angle of this font, a measurement of its slant when     * Returns the italic angle of this font, a measurement of its slant when
901    * style is {@link #ITALIC}. The precise meaning is the inverse slope of a     * style is {@link #ITALIC}. The precise meaning is the inverse slope of a
902    * caret line which "best measures" the font's italic posture.     * caret line which "best measures" the font's italic posture.
903    *     *
904    * @return The italic angle.     * @return The italic angle.
905    *     *
906    * @see java.awt.font.TextAttribute#POSTURE     * @see java.awt.font.TextAttribute#POSTURE
907    */     */
908    public float getItalicAngle ()    public float getItalicAngle()
909  {    {
910      return peer.getItalicAngle (this);      return peer.getItalicAngle(this);
911  }    }
912    
913  /**    /**
914    * Returns a {@link LineMetrics} object constructed with the specified     * Returns a {@link LineMetrics} object constructed with the specified
915    * text and {@link FontRenderContext}.     * text and {@link FontRenderContext}.
916    *     *
917    * @param text The string to calculate metrics from.     * @param text The string to calculate metrics from.
918    * @param begin Index of first character in <code>text</code> to measure.     * @param begin Index of first character in <code>text</code> to measure.
919    * @param limit Index of last character in <code>text</code> to measure.     * @param limit Index of last character in <code>text</code> to measure.
920    * @param rc Context for calculating precise glyph placement and hints.     * @param rc Context for calculating precise glyph placement and hints.
921    *     *
922    * @return A new {@link LineMetrics} object.     * @return A new {@link LineMetrics} object.
923    *     *
924    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
925    * invalid in <code>text</code>.     * invalid in <code>text</code>.
926    */     */
927    public LineMetrics getLineMetrics(String text, int begin,    public LineMetrics getLineMetrics(String text, int begin,
928                                      int limit, FontRenderContext rc)                                      int limit, FontRenderContext rc)
929  {    {
930      return peer.getLineMetrics (this, new StringCharacterIterator (text),      return peer.getLineMetrics(this, new StringCharacterIterator(text),
931                                  begin, limit, rc);                                 begin, limit, rc);
932  }    }
933    
934  /**    /**
935    * Returns a {@link LineMetrics} object constructed with the specified     * Returns a {@link LineMetrics} object constructed with the specified
936    * text and {@link FontRenderContext}.     * text and {@link FontRenderContext}.
937    *     *
938    * @param chars The string to calculate metrics from.     * @param chars The string to calculate metrics from.
939    * @param begin Index of first character in <code>text</code> to measure.     * @param begin Index of first character in <code>text</code> to measure.
940    * @param limit Index of last character in <code>text</code> to measure.     * @param limit Index of last character in <code>text</code> to measure.
941    * @param rc Context for calculating precise glyph placement and hints.     * @param rc Context for calculating precise glyph placement and hints.
942    *     *
943    * @return A new {@link LineMetrics} object.     * @return A new {@link LineMetrics} object.
944    *     *
945    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
946    * invalid in <code>chars</code>.     * invalid in <code>chars</code>.
947    */     */
948    public LineMetrics getLineMetrics(char[] chars, int begin,    public LineMetrics getLineMetrics(char[] chars, int begin,
949                                      int limit, FontRenderContext rc)                                      int limit, FontRenderContext rc)
950  {    {
951      return peer.getLineMetrics (this, new StringCharacterIterator (new String(chars)),      return peer.getLineMetrics(this,
952                                  begin, limit, rc);                                 new StringCharacterIterator(new String(chars)),
953  }                                 begin, limit, rc);
954      }
955    
956  /**    /**
957    * Returns a {@link LineMetrics} object constructed with the specified     * Returns a {@link LineMetrics} object constructed with the specified
958    * text and {@link FontRenderContext}.     * text and {@link FontRenderContext}.
959    *     *
960    * @param ci The string to calculate metrics from.     * @param ci The string to calculate metrics from.
961    * @param begin Index of first character in <code>text</code> to measure.     * @param begin Index of first character in <code>text</code> to measure.
962    * @param limit Index of last character in <code>text</code> to measure.     * @param limit Index of last character in <code>text</code> to measure.
963    * @param rc Context for calculating precise glyph placement and hints.     * @param rc Context for calculating precise glyph placement and hints.
964    *     *
965    * @return A new {@link LineMetrics} object.     * @return A new {@link LineMetrics} object.
966    *     *
967    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
968    * invalid in <code>ci</code>.     * invalid in <code>ci</code>.
969    */     */
970    public LineMetrics getLineMetrics (CharacterIterator ci, int begin,    public LineMetrics getLineMetrics(CharacterIterator ci, int begin,
971                                       int limit, FontRenderContext rc)                                      int limit, FontRenderContext rc)
972  {    {
973      return peer.getLineMetrics (this, ci, begin, limit, rc);      return peer.getLineMetrics(this, ci, begin, limit, rc);
974  }    }
975    
976  /**    /**
977    * Returns the maximal bounding box of all the bounding boxes in this     * Returns the maximal bounding box of all the bounding boxes in this
978    * font, when the font's bounding boxes are evaluated in a given {@link     * font, when the font's bounding boxes are evaluated in a given {@link
979    * FontRenderContext}     * FontRenderContext}
980    *     *
981    * @param rc Context in which to evaluate bounding boxes.     * @param rc Context in which to evaluate bounding boxes.
982    *     *
983    * @return The maximal bounding box.     * @return The maximal bounding box.
984    */     */
985    public Rectangle2D getMaxCharBounds (FontRenderContext rc)    public Rectangle2D getMaxCharBounds(FontRenderContext rc)
986  {    {
987      return peer.getMaxCharBounds (this, rc);      return peer.getMaxCharBounds(this, rc);
988  }    }
989    
990  /**    /**
991    * Returns the glyph code this font uses to represent missing glyphs. This     * Returns the glyph code this font uses to represent missing glyphs. This
992    * code will be present in glyph vectors when the font was unable to     * code will be present in glyph vectors when the font was unable to
993    * locate a glyph to represent a particular character code.     * locate a glyph to represent a particular character code.
994    *     *
995    * @return The missing glyph code.     * @return The missing glyph code.
996    *     *
997    * @since 1.2     * @since 1.2
998    */     */
999    public int getMissingGlyphCode ()    public int getMissingGlyphCode()
1000  {    {
1001      return peer.getMissingGlyphCode (this);      return peer.getMissingGlyphCode(this);
1002  }    }
1003    
1004  /**    /**
1005    * Returns the overall number of glyphs in this font. This number is one     * Returns the overall number of glyphs in this font. This number is one
1006    * more than the greatest glyph code used in any glyph vectors this font     * more than the greatest glyph code used in any glyph vectors this font
1007    * produces. In other words, glyph codes are taken from the range     * produces. In other words, glyph codes are taken from the range
1008    * <code>[ 0, getNumGlyphs() - 1 ]</code>.     * <code>[ 0, getNumGlyphs() - 1 ]</code>.
1009    *     *
1010    * @return The number of glyphs in this font.     * @return The number of glyphs in this font.
1011    *     *
1012    * @since 1.2     * @since 1.2
1013    */     */
1014    public int getNumGlyphs ()    public int getNumGlyphs()
1015  {    {
1016      return peer.getMissingGlyphCode (this);      return peer.getMissingGlyphCode(this);
1017  }    }
1018    
1019  /**    /**
1020    * Returns the PostScript Name of this font.       * Returns the PostScript Name of this font.  
1021    *     *
1022    * @return The PostScript Name of this font.     * @return The PostScript Name of this font.
1023    *     *
1024    * @since 1.2     * @since 1.2
1025    *     *
1026    * @see #getName()     * @see #getName()
1027    * @see #getFamily()     * @see #getFamily()
1028    * @see #getFontName()     * @see #getFontName()
1029    */     */
1030    public String getPSName ()    public String getPSName()
1031  {    {
1032      return peer.getPostScriptName (this);      return peer.getPostScriptName(this);
1033  }    }
1034    
1035  /**    /**
1036    * Returns the logical bounds of the specified string when rendered with this     * Returns the logical bounds of the specified string when rendered with this
1037    * font in the specified {@link FontRenderContext}. This box will include the     * font in the specified {@link FontRenderContext}. This box will include the
1038    * glyph origin, ascent, advance, height, and leading, but may not include all     * glyph origin, ascent, advance, height, and leading, but may not include all
1039    * diacritics or accents. To get the complete visual bounding box of all the     * diacritics or accents. To get the complete visual bounding box of all the
1040    * glyphs in a run of text, use the {@link TextLayout#getBounds} method of     * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1041    * {@link TextLayout}.     * {@link TextLayout}.
1042    *     *
1043    * @param str The string to measure.     * @param str The string to measure.
1044    * @param frc The context in which to make the precise glyph measurements.     * @param frc The context in which to make the precise glyph measurements.
1045    *     *
1046    * @return A bounding box covering the logical bounds of the specified text.     * @return A bounding box covering the logical bounds of the specified text.
1047    *     *
1048    * @see #createGlyphVector(FontRenderContext, String)     * @see #createGlyphVector(FontRenderContext, String)
1049    */     */
1050    public Rectangle2D getStringBounds (String str, FontRenderContext frc)    public Rectangle2D getStringBounds(String str, FontRenderContext frc)
1051  {    {
1052      return getStringBounds (str, 0, str.length () - 1, frc);      return getStringBounds(str, 0, str.length() - 1, frc);
1053  }    }
1054    
1055  /**    /**
1056    * Returns the logical bounds of the specified string when rendered with this     * Returns the logical bounds of the specified string when rendered with this
1057    * font in the specified {@link FontRenderContext}. This box will include the     * font in the specified {@link FontRenderContext}. This box will include the
1058    * glyph origin, ascent, advance, height, and leading, but may not include all     * glyph origin, ascent, advance, height, and leading, but may not include all
1059    * diacritics or accents. To get the complete visual bounding box of all the     * diacritics or accents. To get the complete visual bounding box of all the
1060    * glyphs in a run of text, use the {@link TextLayout#getBounds} method of     * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1061    * {@link TextLayout}.     * {@link TextLayout}.
1062    *     *
1063    * @param str The string to measure.     * @param str The string to measure.
1064    * @param begin Index of the first character in <code>str</code> to measure.     * @param begin Index of the first character in <code>str</code> to measure.
1065    * @param limit Index of the last character in <code>str</code> to measure.     * @param limit Index of the last character in <code>str</code> to measure.
1066    * @param frc The context in which to make the precise glyph measurements.     * @param frc The context in which to make the precise glyph measurements.
1067    *     *
1068    * @return A bounding box covering the logical bounds of the specified text.     * @return A bounding box covering the logical bounds of the specified text.
1069    *     *
1070    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
1071    * invalid in <code>str</code>.     * invalid in <code>str</code>.
1072    *     *
1073    * @since 1.2     * @since 1.2
1074    *     *
1075    * @see #createGlyphVector(FontRenderContext, String)     * @see #createGlyphVector(FontRenderContext, String)
1076    */     */
1077    public Rectangle2D getStringBounds (String str, int begin,    public Rectangle2D getStringBounds(String str, int begin,
1078                                        int limit, FontRenderContext frc)                                       int limit, FontRenderContext frc)
1079  {    {
1080      return peer.getStringBounds (this, new StringCharacterIterator(str), begin, limit, frc);      return peer.getStringBounds(this, new StringCharacterIterator(str), begin,
1081  }                                  limit, frc);
1082      }
1083    
1084  /**    /**
1085    * Returns the logical bounds of the specified string when rendered with this     * Returns the logical bounds of the specified string when rendered with this
1086    * font in the specified {@link FontRenderContext}. This box will include the     * font in the specified {@link FontRenderContext}. This box will include the
1087    * glyph origin, ascent, advance, height, and leading, but may not include all     * glyph origin, ascent, advance, height, and leading, but may not include all
1088    * diacritics or accents. To get the complete visual bounding box of all the     * diacritics or accents. To get the complete visual bounding box of all the
1089    * glyphs in a run of text, use the {@link TextLayout#getBounds} method of     * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1090    * {@link TextLayout}.     * {@link TextLayout}.
1091    *     *
1092    * @param ci The text to measure.     * @param ci The text to measure.
1093    * @param begin Index of the first character in <code>ci</code> to measure.     * @param begin Index of the first character in <code>ci</code> to measure.
1094    * @param limit Index of the last character in <code>ci</code> to measure.     * @param limit Index of the last character in <code>ci</code> to measure.
1095    * @param frc The context in which to make the precise glyph measurements.     * @param frc The context in which to make the precise glyph measurements.
1096    *     *
1097    * @return A bounding box covering the logical bounds of the specified text.     * @return A bounding box covering the logical bounds of the specified text.
1098    *     *
1099    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
1100    * invalid in <code>ci</code>.     * invalid in <code>ci</code>.
1101    *     *
1102    * @since 1.2     * @since 1.2
1103    *     *
1104    * @see #createGlyphVector(FontRenderContext, CharacterIterator)     * @see #createGlyphVector(FontRenderContext, CharacterIterator)
1105    */     */
1106    public Rectangle2D getStringBounds (CharacterIterator ci, int begin,    public Rectangle2D getStringBounds(CharacterIterator ci, int begin,
1107                                        int limit, FontRenderContext frc)                                       int limit, FontRenderContext frc)
1108  {    {
1109      return peer.getStringBounds (this, ci, begin, limit, frc);      return peer.getStringBounds(this, ci, begin, limit, frc);
1110  }    }
1111    
1112  /**    /**
1113    * Returns the logical bounds of the specified string when rendered with this     * Returns the logical bounds of the specified string when rendered with this
1114    * font in the specified {@link FontRenderContext}. This box will include the     * font in the specified {@link FontRenderContext}. This box will include the
1115    * glyph origin, ascent, advance, height, and leading, but may not include all     * glyph origin, ascent, advance, height, and leading, but may not include all
1116    * diacritics or accents. To get the complete visual bounding box of all the     * diacritics or accents. To get the complete visual bounding box of all the
1117    * glyphs in a run of text, use the {@link TextLayout#getBounds} method of     * glyphs in a run of text, use the {@link TextLayout#getBounds} method of
1118    * {@link TextLayout}.     * {@link TextLayout}.
1119    *     *
1120    * @param chars The text to measure.     * @param chars The text to measure.
1121    * @param begin Index of the first character in <code>ci</code> to measure.     * @param begin Index of the first character in <code>ci</code> to measure.
1122    * @param limit Index of the last character in <code>ci</code> to measure.     * @param limit Index of the last character in <code>ci</code> to measure.
1123    * @param frc The context in which to make the precise glyph measurements.     * @param frc The context in which to make the precise glyph measurements.
1124    *     *
1125    * @return A bounding box covering the logical bounds of the specified text.     * @return A bounding box covering the logical bounds of the specified text.
1126    *     *
1127    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
1128    * invalid in <code>chars</code>.     * invalid in <code>chars</code>.
1129    *     *
1130    * @since 1.2     * @since 1.2
1131    *     *
1132    * @see #createGlyphVector(FontRenderContext, char[])     * @see #createGlyphVector(FontRenderContext, char[])
1133    */     */
1134    public Rectangle2D getStringBounds (char[] chars, int begin,    public Rectangle2D getStringBounds(char[] chars, int begin,
1135                                        int limit, FontRenderContext frc)                                       int limit, FontRenderContext frc)
1136  {    {
1137      return peer.getStringBounds (this, new StringCharacterIterator (new String (chars)),      return peer.getStringBounds(this,
1138                                   begin, limit, frc);                                  new StringCharacterIterator(new String(chars)),
1139  }                                  begin, limit, frc);
1140      }
1141    
1142  /**    /**
1143    * Returns a copy of the affine transformation this font is currently     * Returns a copy of the affine transformation this font is currently
1144    * subject to, if any.     * subject to, if any.
1145    *     *
1146    * @return The current transformation.     * @return The current transformation.
1147   */     */
1148    public AffineTransform getTransform ()    public AffineTransform getTransform()
1149  {    {
1150      return peer.getTransform (this);      return peer.getTransform(this);
1151  }    }
1152    
1153  /**    /**
1154    * Indicates whether this font's line metrics are uniform. A font may be     * Indicates whether this font's line metrics are uniform. A font may be
1155    * composed of several "subfonts", each covering a different code range,     * composed of several "subfonts", each covering a different code range,
1156    * and each with their own line metrics. A font with no subfonts, or     * and each with their own line metrics. A font with no subfonts, or
1157    * subfonts with identical line metrics, is said to have "uniform" line     * subfonts with identical line metrics, is said to have "uniform" line
1158    * metrics.     * metrics.
1159    *     *
1160    * @return Whether this font has uniform line metrics.     * @return Whether this font has uniform line metrics.
1161    *     *
1162    * @see LineMetrics     * @see LineMetrics
1163    * @see #getLineMetrics(String, FontRenderContext)     * @see #getLineMetrics(String, FontRenderContext)
1164    */     */
1165    public boolean hasUniformLineMetrics ()    public boolean hasUniformLineMetrics()
1166  {    {
1167      return peer.hasUniformLineMetrics (this);      return peer.hasUniformLineMetrics(this);
1168  }    }
1169    
1170  /**    /**
1171    * Indicates whether this font is subject to a non-identity affine     * Indicates whether this font is subject to a non-identity affine
1172    * transformation.     * transformation.
1173    *     *
1174    * @return <code>true</code> iff the font has a non-identity affine     * @return <code>true</code> iff the font has a non-identity affine
1175    * transformation applied to it.     * transformation applied to it.
1176    */     */
1177    public boolean isTransformed ()    public boolean isTransformed()
1178  {    {
1179      return peer.isTransformed (this);      return peer.isTransformed(this);
1180  }    }
1181    
1182  /**    /**
1183    * Produces a glyph vector representing a full layout fo the specified     * Produces a glyph vector representing a full layout fo the specified
1184    * text in this font. Full layouts may include complex shaping and     * text in this font. Full layouts may include complex shaping and
1185    * reordering operations, for scripts such as Arabic or Hindi.     * reordering operations, for scripts such as Arabic or Hindi.
1186    *     *
1187    * Bidirectional (bidi) layout is not performed in this method; text     * Bidirectional (bidi) layout is not performed in this method; text
1188    * should have its bidi direction specified with one of the flags {@link     * should have its bidi direction specified with one of the flags {@link
1189    * #LAYOUT_LEFT_TO_RIGHT} or {@link #LAYOUT_RIGHT_TO_LEFT}.     * #LAYOUT_LEFT_TO_RIGHT} or {@link #LAYOUT_RIGHT_TO_LEFT}.
1190    *     *
1191    * Some types of layout (notably Arabic glyph shaping) may examine context     * Some types of layout (notably Arabic glyph shaping) may examine context
1192    * characters beyond the bounds of the indicated range, in order to select     * characters beyond the bounds of the indicated range, in order to select
1193    * an appropriate shape. The flags {@link #LAYOUT_NO_START_CONTEXT} and     * an appropriate shape. The flags {@link #LAYOUT_NO_START_CONTEXT} and
1194    * {@link #LAYOUT_NO_LIMIT_CONTEXT} can be provided to prevent these extra     * {@link #LAYOUT_NO_LIMIT_CONTEXT} can be provided to prevent these extra
1195    * context areas from being examined, for instance if they contain invalid     * context areas from being examined, for instance if they contain invalid
1196    * characters.     * characters.
1197    *     *
1198    * @param frc Context in which to perform the layout.     * @param frc Context in which to perform the layout.
1199    * @param chars Text to perform layout on.     * @param chars Text to perform layout on.
1200    * @param start Index of first character to perform layout on.     * @param start Index of first character to perform layout on.
1201    * @param limit Index of last character to perform layout on.     * @param limit Index of last character to perform layout on.
1202    * @param flags Combination of flags controlling layout.     * @param flags Combination of flags controlling layout.
1203    *     *
1204    * @return A new {@link GlyphVector} representing the specified text.     * @return A new {@link GlyphVector} representing the specified text.
1205    *     *
1206    * @throws IndexOutOfBoundsException if the range [begin, limit] is     * @throws IndexOutOfBoundsException if the range [begin, limit] is
1207    * invalid in <code>chars</code>.     * invalid in <code>chars</code>.
1208    */     */
1209    public GlyphVector layoutGlyphVector (FontRenderContext frc,    public GlyphVector layoutGlyphVector(FontRenderContext frc,
1210                                          char[] chars, int start,                                         char[] chars, int start,
1211                                          int limit, int flags)                                         int limit, int flags)
1212  {    {
1213      return peer.layoutGlyphVector (this, frc, chars, start, limit, flags);      return peer.layoutGlyphVector(this, frc, chars, start, limit, flags);
1214  }    }
1215    
1216    
1217  /**    /**
1218    * Returns a native peer object for this font.     * Returns a native peer object for this font.
1219    *     *
1220    * @return A native peer object for this font.     * @return A native peer object for this font.
1221    *     *
1222    * @deprecated     * @deprecated
1223    */     */
1224    public FontPeer getPeer ()    public FontPeer getPeer()
1225  {    {
1226      return peer;      return peer;
1227  }    }
1228    
1229    
1230  /**    /**
1231    * Returns a hash value for this font.     * Returns a hash value for this font.
1232    *     *
1233    * @return A hash for this font.     * @return A hash for this font.
1234    */     */
1235    public int hashCode()    public int hashCode()
1236  {    {
1237      return this.toString().hashCode();      return this.toString().hashCode();
1238  }    }
   
   
 /**  
   * Tests whether or not the specified object is equal to this font.  This  
   * will be true if and only if:  
   * <P>  
   * <ul>  
   * <li>The object is not <code>null</code>.  
   * <li>The object is an instance of <code>Font</code>.  
   * <li>The object has the same names, style, size, and transform as this object.  
   * </ul>  
   *  
   * @return <code>true</code> if the specified object is equal to this  
   * object, <code>false</code> otherwise.  
   */  
 public boolean  
 equals(Object obj)  
 {  
   if (obj == null)  
     return(false);  
1239    
   if (!(obj instanceof Font))  
     return(false);  
1240    
1241    Font f = (Font)obj;    /**
1242       * Tests whether or not the specified object is equal to this font.  This
1243       * will be true if and only if:
1244       * <P>
1245       * <ul>
1246       * <li>The object is not <code>null</code>.
1247       * <li>The object is an instance of <code>Font</code>.
1248       * <li>The object has the same names, style, size, and transform as this object.
1249       * </ul>
1250       *
1251       * @return <code>true</code> if the specified object is equal to this
1252       * object, <code>false</code> otherwise.
1253       */
1254      public boolean equals(Object obj)
1255      {
1256        if (obj == null)
1257          return false;
1258    
1259    return (f.getName ().equals (this.getName ()) &&      if (! (obj instanceof Font))
1260            f.getFamily ().equals (this.getFamily ()) &&        return false;
           f.getFontName ().equals (this.getFontName ()) &&  
           f.getTransform ().equals (this.getTransform ()) &&  
           f.getSize() == this.getSize() &&  
           f.getStyle() == this.getStyle());  
 }  
1261    
1262  /*************************************************************************/      Font f = (Font) obj;
1263    
1264  /**      return (f.getName().equals(this.getName())
1265    * Returns a string representation of this font.              && f.getFamily().equals(this.getFamily())
1266    *              && f.getFontName().equals(this.getFontName())
1267    * @return A string representation of this font.              && f.getTransform().equals(this.getTransform ())
1268    */              && f.getSize() == this.getSize()
1269  public String              && f.getStyle() == this.getStyle());
1270  toString()    }
 {  
   String styleString = "";  
1271    
1272    switch (getStyle ())    /**
1273      {     * Returns a string representation of this font.
1274      case 0:     *
1275        styleString = "plain";     * @return A string representation of this font.
1276        break;     */
1277      case 1:    public String toString()
1278        styleString = "bold";    {
1279        break;      String styleString = "";
     case 2:  
       styleString = "italic";  
       break;  
     default:  
       styleString = "unknown";  
     }  
1280    
1281    return getClass ().getName ()      switch (getStyle())
1282      + "[family=" + getFamily ()        {
1283      + ",name=" + getFontName ()        case 0:
1284      + ",style=" + styleString          styleString = "plain";
1285      + ",size=" + getSize () + "]";          break;
1286  }        case 1:
1287            styleString = "bold";
1288            break;
1289          case 2:
1290            styleString = "italic";
1291            break;
1292          default:
1293            styleString = "unknown";
1294         }
1295        
1296        return getClass().getName()
1297                 + "[family=" + getFamily ()
1298                 + ",name=" + getFontName ()
1299                 + ",style=" + styleString
1300                 + ",size=" + getSize () + "]";
1301      }
1302    
1303    
1304    /**    /**
# Line 1332  toString() Line 1321  toString()
1321     */     */
1322    public LineMetrics getLineMetrics(String str, FontRenderContext frc)    public LineMetrics getLineMetrics(String str, FontRenderContext frc)
1323    {    {
1324      return getLineMetrics (str, 0, str.length () - 1, frc);      return getLineMetrics(str, 0, str.length() - 1, frc);
1325    }    }
1326    
1327  } // class Font    /**
1328       * Reads the normal fields from the stream and then constructs the
1329       * peer from the style and size through getPeerFromToolkit().
1330       */
1331      private void readObject(ObjectInputStream ois)
1332        throws IOException, ClassNotFoundException
1333      {
1334        ois.defaultReadObject();
1335    
1336        HashMap attrs = new HashMap();
1337        ClasspathFontPeer.copyStyleToAttrs(style, attrs);
1338        ClasspathFontPeer.copySizeToAttrs(size, attrs);
1339        peer = getPeerFromToolkit(name, attrs);
1340    
1341      }
1342    }

Legend:
Removed from v.1.18.2.7  
changed lines
  Added in v.1.18.2.8

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