java.awt
public abstract class FontMetrics extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
protected Font |
font
This is the font for which metrics will be returned.
|
Modifier | Constructor and Description |
---|---|
protected |
FontMetrics(Font font)
Initializes a new instance of
FontMetrics for the
specified font. |
Modifier and Type | Method and Description |
---|---|
int |
bytesWidth(byte[] buf,
int offset,
int len)
Returns the total width of the specified byte array.
|
int |
charsWidth(char[] buf,
int offset,
int len)
Returns the total width of the specified character array.
|
int |
charWidth(char ch)
Returns the width of the specified character.
|
int |
charWidth(int ch)
Returns the width of the specified character.
|
int |
getAscent()
Returns the ascent of the font, which is the distance from the base
to the top of the majority of characters in the set.
|
int |
getDescent()
Returns the descent of the font, which is the distance from the base
to the bottom of the majority of characters in the set.
|
Font |
getFont()
Returns the font that this object is creating metric information fo.
|
int |
getHeight()
Returns the height of a line in this font.
|
int |
getLeading()
Returns the leading, or spacing between lines, for this font.
|
LineMetrics |
getLineMetrics(char[] chars,
int begin,
int limit,
Graphics g)
Returns a
LineMetrics object constructed with the
specified text and the FontRenderContext of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics. |
LineMetrics |
getLineMetrics(CharacterIterator ci,
int begin,
int limit,
Graphics g)
Returns a
LineMetrics object constructed with the
specified text and the FontRenderContext of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics. |
LineMetrics |
getLineMetrics(String text,
Graphics g)
Returns a
LineMetrics object constructed with the
specified text and the FontRenderContext of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics. |
LineMetrics |
getLineMetrics(String text,
int begin,
int limit,
Graphics g)
Returns a
LineMetrics object constructed with the
specified text and the FontRenderContext of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics. |
int |
getMaxAdvance()
Returns the width of the widest character in the font.
|
int |
getMaxAscent()
Returns the maximum ascent value.
|
Rectangle2D |
getMaxCharBounds(Graphics context)
Returns the bounds of the largest character in a Graphics context.
|
int |
getMaxDecent()
Deprecated.
This method is deprecated in favor of
getMaxDescent() . |
int |
getMaxDescent()
Returns the maximum descent value.
|
Rectangle2D |
getStringBounds(char[] chars,
int beginIndex,
int limit,
Graphics context) |
Rectangle2D |
getStringBounds(CharacterIterator ci,
int beginIndex,
int limit,
Graphics context) |
Rectangle2D |
getStringBounds(String str,
Graphics context) |
Rectangle2D |
getStringBounds(String str,
int beginIndex,
int limit,
Graphics context) |
int[] |
getWidths()
Returns the widths of the first 256 characters in the font.
|
boolean |
hasUniformLineMetrics()
Returns if the font has uniform line metrics.
|
int |
stringWidth(String str)
Returns the total width of the specified string
|
String |
toString()
Returns a string representation of this object.
|
protected FontMetrics(Font font)
FontMetrics
for the
specified font.font
- The font to return metric information for.public Font getFont()
public int getLeading()
public int getAscent()
public int getDescent()
public int getHeight()
public int getMaxAscent()
public int getMaxDescent()
public int getMaxDecent()
getMaxDescent()
.public int getMaxAdvance()
public int charWidth(int ch)
ch
- The character to return the width of.public int charWidth(char ch)
ch
- The character to return the width of.public int stringWidth(String str)
str
- The string to return the width of.public int charsWidth(char[] buf, int offset, int len)
buf
- The character array containing the data.offset
- The offset into the array to start calculating from.len
- The total number of bytes to process.public int bytesWidth(byte[] buf, int offset, int len)
buf
- The byte array containing the data.offset
- The offset into the array to start calculating from.len
- The total number of bytes to process.public int[] getWidths()
public String toString()
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public LineMetrics getLineMetrics(String text, Graphics g)
LineMetrics
object constructed with the
specified text and the FontRenderContext
of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics.text
- The string to calculate metrics from.g
- The Graphics object that will be used.LineMetrics
object.public LineMetrics getLineMetrics(String text, int begin, int limit, Graphics g)
LineMetrics
object constructed with the
specified text and the FontRenderContext
of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics.text
- The string to calculate metrics from.begin
- Index of first character in text
to measure.limit
- Index of last character in text
to measure.g
- The Graphics object that will be used.LineMetrics
object.IndexOutOfBoundsException
- if the range [begin, limit] is
invalid in text
.public LineMetrics getLineMetrics(char[] chars, int begin, int limit, Graphics g)
LineMetrics
object constructed with the
specified text and the FontRenderContext
of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics.chars
- The string to calculate metrics from.begin
- Index of first character in text
to measure.limit
- Index of last character in text
to measure.g
- The Graphics object that will be used.LineMetrics
object.IndexOutOfBoundsException
- if the range [begin, limit] is
invalid in text
.public Rectangle2D getMaxCharBounds(Graphics context)
context
- the Graphics context object.Rectangle2D
representing the boundspublic LineMetrics getLineMetrics(CharacterIterator ci, int begin, int limit, Graphics g)
LineMetrics
object constructed with the
specified text and the FontRenderContext
of the Graphics
object when it is an instance of Graphics2D or a generic
FontRenderContext with a null transform, not anti-aliased and not
using fractional metrics.ci
- An iterator over the string to calculate metrics from.begin
- Index of first character in text
to measure.limit
- Index of last character in text
to measure.g
- The Graphics object that will be used.LineMetrics
object.IndexOutOfBoundsException
- if the range [begin, limit] is
invalid in text
.public Rectangle2D getStringBounds(String str, Graphics context)
public Rectangle2D getStringBounds(String str, int beginIndex, int limit, Graphics context)
public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, Graphics context)
public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, int limit, Graphics context)
public boolean hasUniformLineMetrics()
Font.hasUniformLineMetrics()