throw new IndexOutOfBoundsException("len="+len); } int limit = off + len; for (int i=off; i < limit; i++) { char ch = data[i]; if (ch < 0x100) { width += getLatinCharWidth(ch); } else if (FontUtilities.isNonSimpleChar(ch)) { String str = new String(data, off, len); width = new TextLayout(str, font, frc).getAdvance(); break; } else { width += handleCharWidth(ch); } } } return (int) (0.5 + width); } /** * Gets the advance widths of the first 256 characters in the * <code>Font</code>. The advance is the * distance from the leftmost point to the rightmost point on the * character's baseline. Note that the advance of a * <code>String</code> is not necessarily the sum of the advances * of its characters. * @return an array storing the advance widths of the * characters in the <code>Font</code> * described by this <code>FontMetrics</code> object. */ // More efficient than base class implementation - reuses existing cache public int[] getWidths() { int[] widths = new int[256]; for (char ch = 0 ; ch < 256 ; ch++) { float w = advCache[ch]; if (w == UNKNOWN_WIDTH) { w = advCache[ch] = handleCharWidth(ch); } widths[ch] = (int) (0.5 + w); } return widths; } public int getMaxAdvance() { return (int)(0.99f + this.maxAdvance); } /* * Returns the typographic ascent of the font. This is the maximum distance * glyphs in this font extend above the base line (measured in typographic * units). */ public int getAscent() { return (int)(roundingUpValue + this.ascent); } /* * Returns the typographic descent of the font. This is the maximum distance * glyphs in this font extend below the base line. */ public int getDescent() { return (int)(roundingUpValue + this.descent); } public int getLeading() { // nb this ensures the sum of the results of the public methods // for leading, ascent & descent sum to height. // if the calculations in any other methods change this needs // to be changed too. // the 0.95 value used here and in the other methods allows some // tiny fraction of leeway before rouding up. A higher value (0.99) // caused some excessive rounding up. return (int)(roundingUpValue + descent + leading) - (int)(roundingUpValue + descent); } // height is calculated as the sum of two separately rounded up values // because typically clients use ascent to determine the y location to // pass to drawString etc and we need to ensure that the height has enough // space below the baseline to fully contain any descender. public int getHeight() { if (height < 0) { height = getAscent() + (int)(roundingUpValue + descent + leading); } return height; }}Lines 501–590 of 590. Previous lines
throw new IndexOutOfBoundsException("len="+len); } int limit = off + len; for (int i=off; i < limit; i++) { char ch = data[i]; if (ch < 0x100) { width += getLatinCharWidth(ch); } else if (FontUtilities.isNonSimpleChar(ch)) { String str = new String(data, off, len); width = new TextLayout(str, font, frc).getAdvance(); break; } else { width += handleCharWidth(ch); } } } return (int) (0.5 + width); } /** * Gets the advance widths of the first 256 characters in the * <code>Font</code>. The advance is the * distance from the leftmost point to the rightmost point on the * character's baseline. Note that the advance of a * <code>String</code> is not necessarily the sum of the advances * of its characters. * @return an array storing the advance widths of the * characters in the <code>Font</code> * described by this <code>FontMetrics</code> object. */ // More efficient than base class implementation - reuses existing cache public int[] getWidths() { int[] widths = new int[256]; for (char ch = 0 ; ch < 256 ; ch++) { float w = advCache[ch]; if (w == UNKNOWN_WIDTH) { w = advCache[ch] = handleCharWidth(ch); } widths[ch] = (int) (0.5 + w); } return widths; } public int getMaxAdvance() { return (int)(0.99f + this.maxAdvance); } /* * Returns the typographic ascent of the font. This is the maximum distance * glyphs in this font extend above the base line (measured in typographic * units). */ public int getAscent() { return (int)(roundingUpValue + this.ascent); } /* * Returns the typographic descent of the font. This is the maximum distance * glyphs in this font extend below the base line. */ public int getDescent() { return (int)(roundingUpValue + this.descent); } public int getLeading() { // nb this ensures the sum of the results of the public methods // for leading, ascent & descent sum to height. // if the calculations in any other methods change this needs // to be changed too. // the 0.95 value used here and in the other methods allows some // tiny fraction of leeway before rouding up. A higher value (0.99) // caused some excessive rounding up. return (int)(roundingUpValue + descent + leading) - (int)(roundingUpValue + descent); } // height is calculated as the sum of two separately rounded up values // because typically clients use ascent to determine the y location to // pass to drawString etc and we need to ensure that the height has enough // space below the baseline to fully contain any descender. public int getHeight() { if (height < 0) { height = getAscent() + (int)(roundingUpValue + descent + leading); } return height; } }