public final class

FontDesignMetrics

extends FontMetrics
java.lang.Object
   ↳ java.awt.FontMetrics
     ↳ sun.font.FontDesignMetrics

Summary

[Expand]
Inherited Fields
From class java.awt.FontMetrics
Public Methods
int charWidth(int ch)
Returns the advance width of the specified character in this Font.
int charWidth(char ch)
Returns the advance width of the specified character in this Font.
int charsWidth(char[] data, int off, int len)
Returns the total advance width for showing the specified array of characters in this Font.
int getAscent()
Determines the font ascent of the Font described by this FontMetrics object.
int getDescent()
Determines the font descent of the Font described by this FontMetrics object.
FontRenderContext getFontRenderContext()
Gets the FontRenderContext used by this FontMetrics object to measure text.
int getHeight()
Gets the standard height of a line of text in this font.
int getLeading()
Determines the standard leading of the Font described by this FontMetrics object.
int getMaxAdvance()
Gets the maximum advance width of any character in this Font.
static FontDesignMetrics getMetrics(Font font, FontRenderContext frc)
static FontDesignMetrics getMetrics(Font font)
int[] getWidths()
Gets the advance widths of the first 256 characters in the Font.
int stringWidth(String str)
Returns the total advance width for showing the specified String in this Font.
[Expand]
Inherited Methods
From class java.awt.FontMetrics
From class java.lang.Object

Public Methods

public int charWidth (int ch)

Returns the advance width of the specified character in this Font. The advance is the distance from the leftmost point to the rightmost point on the character's baseline. Note that the advance of a String is not necessarily the sum of the advances of its characters.

This method doesn't validate the specified character to be a valid Unicode code point. The caller must validate the character value using Character.isValidCodePoint if necessary.

Parameters
ch the character (Unicode code point) to be measured
Returns
  • the advance width of the specified character in the Font described by this FontMetrics object.

public int charWidth (char ch)

Returns the advance width of the specified character in this Font. The advance is the distance from the leftmost point to the rightmost point on the character's baseline. Note that the advance of a String is not necessarily the sum of the advances of its characters.

Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the charWidth(int) method.

Parameters
ch the character to be measured
Returns
  • the advance width of the specified character in the Font described by this FontMetrics object.

public int charsWidth (char[] data, int off, int len)

Returns the total advance width for showing the specified array of characters in this Font. The advance is the distance from the leftmost point to the rightmost point on the string's baseline. The advance of a String is not necessarily the sum of the advances of its characters. This is equivalent to measuring a String of the characters in the specified range.

Parameters
data the array of characters to be measured
off the start offset of the characters in the array
len the number of characters to be measured from the array
Returns
  • the advance width of the subarray of the specified char array in the font described by this FontMetrics object.

public int getAscent ()

Determines the font ascent of the Font described by this FontMetrics object. The font ascent is the distance from the font's baseline to the top of most alphanumeric characters. Some characters in the Font might extend above the font ascent line.

Returns
  • the font ascent of the Font.

public int getDescent ()

Determines the font descent of the Font described by this FontMetrics object. The font descent is the distance from the font's baseline to the bottom of most alphanumeric characters with descenders. Some characters in the Font might extend below the font descent line.

Returns
  • the font descent of the Font.

public FontRenderContext getFontRenderContext ()

Gets the FontRenderContext used by this FontMetrics object to measure text.

Note that methods in this class which take a Graphics parameter measure text using the FontRenderContext of that Graphics object, and not this FontRenderContext

Returns
  • the FontRenderContext used by this FontMetrics object.

public int getHeight ()

Gets the standard height of a line of text in this font. This is the distance between the baseline of adjacent lines of text. It is the sum of the leading + ascent + descent. Due to rounding this may not be the same as getAscent() + getDescent() + getLeading(). There is no guarantee that lines of text spaced at this distance are disjoint; such lines may overlap if some characters overshoot either the standard ascent or the standard descent metric.

Returns
  • the standard height of the font.

public int getLeading ()

Determines the standard leading of the Font described by this FontMetrics object. The standard leading, or interline spacing, is the logical amount of space to be reserved between the descent of one line of text and the ascent of the next line. The height metric is calculated to include this extra space.

Returns
  • the standard leading of the Font.

public int getMaxAdvance ()

Gets the maximum advance width of any character in this Font. The advance is the distance from the leftmost point to the rightmost point on the string's baseline. The advance of a String is not necessarily the sum of the advances of its characters.

Returns
  • the maximum advance width of any character in the Font, or -1 if the maximum advance width is not known.

public static FontDesignMetrics getMetrics (Font font, FontRenderContext frc)

public static FontDesignMetrics getMetrics (Font font)

public int[] getWidths ()

Gets the advance widths of the first 256 characters in the Font. The advance is the distance from the leftmost point to the rightmost point on the character's baseline. Note that the advance of a String is not necessarily the sum of the advances of its characters.

Returns
  • an array storing the advance widths of the characters in the Font described by this FontMetrics object.

public int stringWidth (String str)

Returns the total advance width for showing the specified String in this Font. The advance is the distance from the leftmost point to the rightmost point on the string's baseline.

Note that the advance of a String is not necessarily the sum of the advances of its characters.

Parameters
str the String to be measured
Returns
  • the advance width of the specified String in the Font described by this FontMetrics.