< prev index next >

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

Print this page




 300         }
 301 
 302         if (codePoint < 256) {
 303             return getWidths()[codePoint];
 304         } else {
 305             char[] buffer = new char[2];
 306             int len = Character.toChars(codePoint, buffer, 0);
 307             return charsWidth(buffer, 0, len);
 308         }
 309     }
 310 
 311     /**
 312      * Returns the advance width of the specified character in this
 313      * {@code Font}.  The advance is the
 314      * distance from the leftmost point to the rightmost point on the
 315      * character's baseline.  Note that the advance of a
 316      * {@code String} is not necessarily the sum of the advances
 317      * of its characters.
 318      *
 319      * <p><b>Note:</b> This method cannot handle <a
 320      * href="../../../java.base/java/lang/Character.html#supplementary">
 321      * supplementary characters</a>.
 322      * To support all Unicode characters, including
 323      * supplementary characters, use the {@link #charWidth(int)} method.
 324      *
 325      * @param ch the character to be measured
 326      * @return     the advance width of the specified character
 327      *                  in the {@code Font} described by this
 328      *                  {@code FontMetrics} object.
 329      * @see        #charsWidth(char[], int, int)
 330      * @see        #stringWidth(String)
 331      */
 332     public int charWidth(char ch) {
 333         if (ch < 256) {
 334             return getWidths()[ch];
 335         }
 336         char[] data = {ch};
 337         return charsWidth(data, 0, 1);
 338     }
 339 
 340     /**
 341      * Returns the total advance width for showing the specified
 342      * {@code String} in this {@code Font}.  The advance




 300         }
 301 
 302         if (codePoint < 256) {
 303             return getWidths()[codePoint];
 304         } else {
 305             char[] buffer = new char[2];
 306             int len = Character.toChars(codePoint, buffer, 0);
 307             return charsWidth(buffer, 0, len);
 308         }
 309     }
 310 
 311     /**
 312      * Returns the advance width of the specified character in this
 313      * {@code Font}.  The advance is the
 314      * distance from the leftmost point to the rightmost point on the
 315      * character's baseline.  Note that the advance of a
 316      * {@code String} is not necessarily the sum of the advances
 317      * of its characters.
 318      *
 319      * <p><b>Note:</b> This method cannot handle <a
 320      * href="../lang/Character.html#supplementary"> supplementary
 321      * characters</a>. To support all Unicode characters, including

 322      * supplementary characters, use the {@link #charWidth(int)} method.
 323      *
 324      * @param ch the character to be measured
 325      * @return     the advance width of the specified character
 326      *                  in the {@code Font} described by this
 327      *                  {@code FontMetrics} object.
 328      * @see        #charsWidth(char[], int, int)
 329      * @see        #stringWidth(String)
 330      */
 331     public int charWidth(char ch) {
 332         if (ch < 256) {
 333             return getWidths()[ch];
 334         }
 335         char[] data = {ch};
 336         return charsWidth(data, 0, 1);
 337     }
 338 
 339     /**
 340      * Returns the total advance width for showing the specified
 341      * {@code String} in this {@code Font}.  The advance


< prev index next >