waba.fx
Class FontMetrics

waba.lang.Object
  |
  +--waba.fx.FontMetrics

public class FontMetrics
extends Object

FontMetrics computes font metrics including string width and height.

FontMetrics are usually used to obtain information about the widths and heights of characters and strings when drawing text on a surface. A FontMetrics object references a font and surface since fonts may have different metrics on different surfaces.

Here is an example that uses FontMetrics to get the width of a string:

 ...
 Font font = new Font("Helvetica", Font.BOLD, 10);
 FontMetrics fm = getFontMetrics();
 String s = "This is a line of text.";
 int stringWidth = fm.getTextWidth(s);
 ...
 


Constructor Summary
FontMetrics(Font font, ISurface surface)
          Constructs a font metrics object referencing the given font and surface.
 
Method Summary
 int getAscent()
          Returns the ascent of the font.
 int getCharWidth(char c)
          Returns the width of the given character in pixels.
 int getDescent()
          Returns the descent of a font.
 int getHeight()
          Returns the height of the referenced font.
 int getLeading()
          Returns the external leading which is the space between lines.
 int getTextWidth(char[] chars, int start, int count)
          Returns the width of the given text in pixels.
 int getTextWidth(String s)
          Returns the width of the given text string in pixels.
 
Methods inherited from class waba.lang.Object
toString
 

Constructor Detail

FontMetrics

public FontMetrics(Font font,
                   ISurface surface)
Constructs a font metrics object referencing the given font and surface.

If you are trying to create a font metrics object in a Control subclass, use the getFontMetrics() method in the Control class.

See Also:
Control.getFontMetrics(waba.fx.Font font)
Method Detail

getAscent

public int getAscent()
Returns the ascent of the font. This is the distance from the baseline of a character to its top.

getCharWidth

public int getCharWidth(char c)
Returns the width of the given character in pixels.

getDescent

public int getDescent()
Returns the descent of a font. This is the distance from the baseline of a character to the bottom of the character.

getHeight

public int getHeight()
Returns the height of the referenced font. This is equal to the font's ascent plus its descent. This does not include leading (the space between lines).

getLeading

public int getLeading()
Returns the external leading which is the space between lines.

getTextWidth

public int getTextWidth(String s)
Returns the width of the given text string in pixels.

getTextWidth

public int getTextWidth(char[] chars,
                        int start,
                        int count)
Returns the width of the given text in pixels.
Parameters:
chars - the text character array
start - the start position in array
count - the number of characters