503 int limit = off + len; 504 for (int i=off; i < limit; i++) { 505 char ch = data[i]; 506 if (ch < 0x100) { 507 width += getLatinCharWidth(ch); 508 } else if (FontUtilities.isNonSimpleChar(ch)) { 509 String str = new String(data, off, len); 510 width = new TextLayout(str, font, frc).getAdvance(); 511 break; 512 } else { 513 width += handleCharWidth(ch); 514 } 515 } 516 } 517 518 return (int) (0.5 + width); 519 } 520 521 /** 522 * Gets the advance widths of the first 256 characters in the 523 * <code>Font</code>. The advance is the 524 * distance from the leftmost point to the rightmost point on the 525 * character's baseline. Note that the advance of a 526 * <code>String</code> is not necessarily the sum of the advances 527 * of its characters. 528 * @return an array storing the advance widths of the 529 * characters in the <code>Font</code> 530 * described by this <code>FontMetrics</code> object. 531 */ 532 // More efficient than base class implementation - reuses existing cache 533 public int[] getWidths() { 534 int[] widths = new int[256]; 535 for (char ch = 0 ; ch < 256 ; ch++) { 536 float w = advCache[ch]; 537 if (w == UNKNOWN_WIDTH) { 538 w = advCache[ch] = handleCharWidth(ch); 539 } 540 widths[ch] = (int) (0.5 + w); 541 } 542 return widths; 543 } 544 545 public int getMaxAdvance() { 546 return (int)(0.99f + this.maxAdvance); 547 } 548 549 /* 550 * Returns the typographic ascent of the font. This is the maximum distance | 503 int limit = off + len; 504 for (int i=off; i < limit; i++) { 505 char ch = data[i]; 506 if (ch < 0x100) { 507 width += getLatinCharWidth(ch); 508 } else if (FontUtilities.isNonSimpleChar(ch)) { 509 String str = new String(data, off, len); 510 width = new TextLayout(str, font, frc).getAdvance(); 511 break; 512 } else { 513 width += handleCharWidth(ch); 514 } 515 } 516 } 517 518 return (int) (0.5 + width); 519 } 520 521 /** 522 * Gets the advance widths of the first 256 characters in the 523 * {@code Font}. The advance is the 524 * distance from the leftmost point to the rightmost point on the 525 * character's baseline. Note that the advance of a 526 * {@code String} is not necessarily the sum of the advances 527 * of its characters. 528 * @return an array storing the advance widths of the 529 * characters in the {@code Font} 530 * described by this {@code FontMetrics} object. 531 */ 532 // More efficient than base class implementation - reuses existing cache 533 public int[] getWidths() { 534 int[] widths = new int[256]; 535 for (char ch = 0 ; ch < 256 ; ch++) { 536 float w = advCache[ch]; 537 if (w == UNKNOWN_WIDTH) { 538 w = advCache[ch] = handleCharWidth(ch); 539 } 540 widths[ch] = (int) (0.5 + w); 541 } 542 return widths; 543 } 544 545 public int getMaxAdvance() { 546 return (int)(0.99f + this.maxAdvance); 547 } 548 549 /* 550 * Returns the typographic ascent of the font. This is the maximum distance |