src/share/classes/java/awt/FontMetrics.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  77  * maximum descent of any character in the array. The advance width
  78  * is the sum of the advance widths of each of the characters in the
  79  * character array.  The advance of a <code>String</code> is the
  80  * distance along the baseline of the <code>String</code>.  This
  81  * distance is the width that should be used for centering or
  82  * right-aligning the <code>String</code>.
  83  * <p>Note that the advance of a <code>String</code> is not necessarily
  84  * the sum of the advances of its characters measured in isolation
  85  * because the width of a character can vary depending on its context.
  86  * For example, in Arabic text, the shape of a character can change
  87  * in order to connect to other characters.  Also, in some scripts,
  88  * certain character sequences can be represented by a single shape,
  89  * called a <em>ligature</em>.  Measuring characters individually does
  90  * not account for these transformations.
  91  * <p>Font metrics are baseline-relative, meaning that they are
  92  * generally independent of the rotation applied to the font (modulo
  93  * possible grid hinting effects).  See {@link java.awt.Font Font}.
  94  *
  95  * @author      Jim Graham
  96  * @see         java.awt.Font
  97  * @since       JDK1.0
  98  */
  99 public abstract class FontMetrics implements java.io.Serializable {
 100 
 101     static {
 102         /* ensure that the necessary native libraries are loaded */
 103         Toolkit.loadLibraries();
 104         if (!GraphicsEnvironment.isHeadless()) {
 105             initIDs();
 106         }
 107     }
 108 
 109     private static final FontRenderContext
 110         DEFAULT_FRC = new FontRenderContext(null, false, false);
 111 
 112     /**
 113      * The actual {@link Font} from which the font metrics are
 114      * created.
 115      * This cannot be null.
 116      *
 117      * @serial


 608      * bounding box for the character with the maximum bounds.
 609      * @see java.awt.Font#getMaxCharBounds(FontRenderContext)
 610      */
 611     public Rectangle2D getMaxCharBounds(Graphics context) {
 612         return font.getMaxCharBounds(myFRC(context));
 613     }
 614 
 615     private FontRenderContext myFRC(Graphics context) {
 616         if (context instanceof Graphics2D) {
 617             return ((Graphics2D)context).getFontRenderContext();
 618         }
 619         return DEFAULT_FRC;
 620     }
 621 
 622 
 623     /**
 624      * Returns a representation of this <code>FontMetrics</code>
 625      * object's values as a <code>String</code>.
 626      * @return    a <code>String</code> representation of this
 627      * <code>FontMetrics</code> object.
 628      * @since     JDK1.0.
 629      */
 630     public String toString() {
 631         return getClass().getName() +
 632             "[font=" + getFont() +
 633             "ascent=" + getAscent() +
 634             ", descent=" + getDescent() +
 635             ", height=" + getHeight() + "]";
 636     }
 637 
 638     /**
 639      * Initialize JNI field and method IDs
 640      */
 641     private static native void initIDs();
 642 }


  77  * maximum descent of any character in the array. The advance width
  78  * is the sum of the advance widths of each of the characters in the
  79  * character array.  The advance of a <code>String</code> is the
  80  * distance along the baseline of the <code>String</code>.  This
  81  * distance is the width that should be used for centering or
  82  * right-aligning the <code>String</code>.
  83  * <p>Note that the advance of a <code>String</code> is not necessarily
  84  * the sum of the advances of its characters measured in isolation
  85  * because the width of a character can vary depending on its context.
  86  * For example, in Arabic text, the shape of a character can change
  87  * in order to connect to other characters.  Also, in some scripts,
  88  * certain character sequences can be represented by a single shape,
  89  * called a <em>ligature</em>.  Measuring characters individually does
  90  * not account for these transformations.
  91  * <p>Font metrics are baseline-relative, meaning that they are
  92  * generally independent of the rotation applied to the font (modulo
  93  * possible grid hinting effects).  See {@link java.awt.Font Font}.
  94  *
  95  * @author      Jim Graham
  96  * @see         java.awt.Font
  97  * @since       1.0
  98  */
  99 public abstract class FontMetrics implements java.io.Serializable {
 100 
 101     static {
 102         /* ensure that the necessary native libraries are loaded */
 103         Toolkit.loadLibraries();
 104         if (!GraphicsEnvironment.isHeadless()) {
 105             initIDs();
 106         }
 107     }
 108 
 109     private static final FontRenderContext
 110         DEFAULT_FRC = new FontRenderContext(null, false, false);
 111 
 112     /**
 113      * The actual {@link Font} from which the font metrics are
 114      * created.
 115      * This cannot be null.
 116      *
 117      * @serial


 608      * bounding box for the character with the maximum bounds.
 609      * @see java.awt.Font#getMaxCharBounds(FontRenderContext)
 610      */
 611     public Rectangle2D getMaxCharBounds(Graphics context) {
 612         return font.getMaxCharBounds(myFRC(context));
 613     }
 614 
 615     private FontRenderContext myFRC(Graphics context) {
 616         if (context instanceof Graphics2D) {
 617             return ((Graphics2D)context).getFontRenderContext();
 618         }
 619         return DEFAULT_FRC;
 620     }
 621 
 622 
 623     /**
 624      * Returns a representation of this <code>FontMetrics</code>
 625      * object's values as a <code>String</code>.
 626      * @return    a <code>String</code> representation of this
 627      * <code>FontMetrics</code> object.

 628      */
 629     public String toString() {
 630         return getClass().getName() +
 631             "[font=" + getFont() +
 632             "ascent=" + getAscent() +
 633             ", descent=" + getDescent() +
 634             ", height=" + getHeight() + "]";
 635     }
 636 
 637     /**
 638      * Initialize JNI field and method IDs
 639      */
 640     private static native void initIDs();
 641 }