java.awt
Class FontMetrics
- Serializable
This class returns information about the display characteristics of
a font. It is abstract, and concrete subclasses should implement at
least the following methods:
- getAscent()
- getDescent()
- getLeading()
- getMaxAdvance()
- charWidth(char)
- charsWidth(char[], int, int)
protected Font | font - This is the font for which metrics will be returned.
|
FontMetrics(Font font) - Initializes a new instance of
FontMetrics for the
specified font.
|
int | bytesWidth(byte[] buf, int offset, int len) - Returns the total width of the specified byte array.
|
int | charWidth(char ch) - Returns the width of the specified character.
|
int | charWidth(int ch) - Returns the width of the specified character.
|
int | charsWidth(char[] buf, int offset, int len) - Returns the total width of the specified character array.
|
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(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.
|
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(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.
|
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() - 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(String str, int beginIndex, int limit, Graphics context)
|
Rectangle2D | getStringBounds(String str, Graphics context)
|
Rectangle2D | getStringBounds(CharacterIterator ci, 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.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
font
protected Font font
This is the font for which metrics will be returned.
FontMetrics
protected FontMetrics(Font font)
Initializes a new instance of FontMetrics
for the
specified font.
font
- The font to return metric information for.
bytesWidth
public int bytesWidth(byte[] buf,
int offset,
int len)
Returns the total width of the specified byte array.
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.
- The width of the requested characters.
charWidth
public int charWidth(char ch)
Returns the width of the specified character.
ch
- The character to return the width of.
- The width of the specified character.
charWidth
public int charWidth(int ch)
Returns the width of the specified character.
ch
- The character to return the width of.
- The width of the specified character.
charsWidth
public int charsWidth(char[] buf,
int offset,
int len)
Returns the total width of the specified character array.
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.
- The width of the requested characters.
getAscent
public 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. Some characters
can exceed this value however.
getDescent
public 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. Some characters
can exceed this value however.
getFont
public Font getFont()
Returns the font that this object is creating metric information fo.
- The font for this object.
getHeight
public int getHeight()
Returns the height of a line in this font. This will be the sum
of the leading, the ascent, and the descent.
getLeading
public int getLeading()
Returns the leading, or spacing between lines, for this font.
getLineMetrics
public 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.
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.
getLineMetrics
public 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.
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.
getLineMetrics
public 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.
text
- The string to calculate metrics from.g
- The Graphics object that will be used.
getLineMetrics
public 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.
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.
getMaxAdvance
public int getMaxAdvance()
Returns the width of the widest character in the font.
- The width of the widest character in the font.
getMaxAscent
public int getMaxAscent()
Returns the maximum ascent value. This is the maximum distance any
character in the font rised above the baseline.
- The maximum ascent for this font.
getMaxCharBounds
public Rectangle2D getMaxCharBounds(Graphics context)
Returns the bounds of the largest character in a Graphics context.
context
- the Graphics context object.
- a
Rectangle2D
representing the bounds
getMaxDecent
public int getMaxDecent()
This method is deprecated in favor of
getMaxDescent()
.
Returns the maximum descent value. This is the maximum distance any
character in the font extends below the baseline.
- The maximum descent for this font.
getMaxDescent
public int getMaxDescent()
Returns the maximum descent value. This is the maximum distance any
character in the font extends below the baseline.
- The maximum descent for this font.
getWidths
public int[] getWidths()
Returns the widths of the first 256 characters in the font.
- The widths of the first 256 characters in the font.
hasUniformLineMetrics
public boolean hasUniformLineMetrics()
Returns if the font has uniform line metrics.
stringWidth
public int stringWidth(String str)
Returns the total width of the specified string
str
- The string to return the width of.
toString
public String toString()
Returns a string representation of this object.
- toString in interface Object
- A string representation of this object.
FontMetrics.java -- Information about about a fonts display characteristics
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.