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
|
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"> 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
|