Class GraphicFont

Class GraphicFont

java.lang.Object
   |
   +----GraphicFont

public class GraphicFont
extends Object
A class that allows the use of a font encoded in the GraphicFont format. It allows much of the same functionality as Sun's Font and FontMetrics classes. For example:
  g = getGraphics();
  GraphicFont gf = new GraphicFont(fontImage);
  gf.setFgColor(Color.green);
  gf.drawString(g, "This is a string drawn with GraphicFont.", 10, 10);
  int ascent = gf.getAscent();
See Also:
Font, FontMetrics

Constructor Index

 o GraphicFont(Image)
Initializes a new GraphicFont with the encoded font passed to it.

Method Index

 o charImage(int)
Returns a rendered image given a character.
 o charWidth(int)
Returns the width in pixels of a given character.
 o drawString(Graphics, String, int, int)
Draws a rendered image of a string given a graphics context, a string, and the coordinates to draw at.
 o drawString(Graphics, String, int, int, int)
Draws a rendered image of a left-justified text block given a graphics context, a string, the coordinates to draw at, and a width in pixels.
 o getAscent()
Gets the ascent of the current font, the distance from the baseline to the top of the regular characters (typically A-Z, a-z, 0-9).
 o getCharSpace()
Gets the space between non-space characters.
 o getDescent()
Gets the descent of the current font, the distance from the baseline to the bottom of the regular characters (typically A-Z, a-z, 0-9).
 o getHeight()
Gets the total height of the current font, which amounts to the ascent plus the descent plus the leading.
 o getLeading()
Gets the leading of the current font, the space between the descent of one line and the ascent of the line below it.
 o getMaxAscent()
Gets the maximum ascent of the current font.
 o getMaxDescent()
Gets the maximum descent of the current font.
 o getTabWidth()
Gets the tab width in how many space characters make up a tab character.
 o getWordSpace()
Gets the word spacing of the current font.
 o setBgColor(Color)
Sets the background color the font characters are drawn against.
 o setCharSpace(int)
Sets the character spacing in pixels.
 o setColor(Color)
Sets the foreground color, the color the font characters are drawn in.
 o setFgColor(Color)
Sets the foreground color.
 o setFont(Image)
Sets a new font.
 o setLeading(int)
Sets the leading in pixels.
 o setTabWidth(int)
Sets the tab width as the number of spaces that make up a tab character.
 o setWordSpace(int)
Sets the word spacing in pixels.
 o stringImage(String)
Returns a rendered image given a string using the current font.
 o stringImage(String, int)
Returns a rendered image of a left-justified text block given a string and a width in pixels.
 o stringWidth(String)
Returns the width in pixels of a given string.

Constructors

 o GraphicFont
  public GraphicFont(Image loadedImage)
Initializes a new GraphicFont with the encoded font passed to it. Font metrics information is initialized with the default values as suggested by the font's author. The font image must be completely loaded beforehand.
Parameters:
loadedImage - An image encoded in the GraphicFont format

Methods

 o setFont
  public void setFont(Image loadedImage)
Sets a new font. Font metrics information is set to the default values as suggested by the font's author. The font image must be completely loaded beforehand.
Parameters:
loadedImage - An image encoded in the GraphicFont format
 o getHeight
  public int getHeight()
Gets the total height of the current font, which amounts to the ascent plus the descent plus the leading.
Returns:
The total height of the font in pixels
 o getAscent
  public int getAscent()
Gets the ascent of the current font, the distance from the baseline to the top of the regular characters (typically A-Z, a-z, 0-9).
Returns:
The typical ascent in pixels
 o getDescent
  public int getDescent()
Gets the descent of the current font, the distance from the baseline to the bottom of the regular characters (typically A-Z, a-z, 0-9).
Returns:
The typical descent in pixels
 o getMaxAscent
  public int getMaxAscent()
Gets the maximum ascent of the current font. No character in the font extends above the baseline further than this.
Returns:
The maximum ascent in pixels
 o getMaxDescent
  public int getMaxDescent()
Gets the maximum descent of the current font. No character in the font descends below the baseline further than this.
Returns:
The maximum descent in pixels
 o getLeading
  public int getLeading()
Gets the leading of the current font, the space between the descent of one line and the ascent of the line below it.
Returns:
The leading in pixels
 o getWordSpace
  public int getWordSpace()
Gets the word spacing of the current font. The space character is remapped to this.
Returns:
The typical space between words in pixels
 o getCharSpace
  public int getCharSpace()
Gets the space between non-space characters.
Returns:
The typical space between characters in pixels
 o getTabWidth
  public int getTabWidth()
Gets the tab width in how many space characters make up a tab character. The default is five - five spaces per tab.
Returns:
The tab width
 o setLeading
  public void setLeading(int i)
Sets the leading in pixels. The setting will only be visible when creating text blocks. The leading can be set to a negative value.
Parameters:
i - The leading to set the font to
 o setWordSpace
  public void setWordSpace(int i)
Sets the word spacing in pixels. The space character is remapped to this. Negative values can be used.
Parameters:
i - The amount of word spacing used in drawing strings.
 o setCharSpace
  public void setCharSpace(int i)
Sets the character spacing in pixels. Negative values can be used.
Parameters:
i - The amount of space between individual characters.
 o setTabWidth
  public void setTabWidth(int i)
Sets the tab width as the number of spaces that make up a tab character.
Parameters:
i - The number of spaces that comprise a tab character
 o setColor
  public void setColor(Color c)
Sets the foreground color, the color the font characters are drawn in.
Parameters:
c - The color characters will be drawn in
 o setFgColor
  public void setFgColor(Color c)
Sets the foreground color. Same as setColor(Color).
Parameters:
c - The color characters will be drawn in
 o setBgColor
  public void setBgColor(Color c)
Sets the background color the font characters are drawn against. This is very useful for displaying different backgrounds for antialiased fonts.
Parameters:
c - The color characters will be drawn against. If the background is set to null, the background will be transparent.
 o stringWidth
  public int stringWidth(String s)
Returns the width in pixels of a given string. If a character is unsupported in the font, the width of an asterisk character or suitable substitue is used.
Parameters:
s - The desired string
Returns:
The width of the string after rendering
 o charWidth
  public int charWidth(int c)
Returns the width in pixels of a given character. If the character is unknown, the width of an asterix character or suitable substitue is used.
Parameters:
c - The desired character
Returns:
The width of the character after rendering
 o stringImage
  public Image stringImage(String s)
Returns a rendered image given a string using the current font. If a character is unknown, an asterisk character is substituted. Non-US characters that are not supported in the font may be substituted for simpler ASCII characters.
Parameters:
s - The desired string
Returns:
The final rendered image. If no background is set, the background will be transparent.
 o stringImage
  public Image stringImage(String s,
                           int width)
Returns a rendered image of a left-justified text block given a string and a width in pixels. Only spaces are wrapped. Newline characters (\n) create hard breaks.
Parameters:
s - The desired string
width - The maximum width of the text block
Returns:
The final rendered image. If no background is set, the background will be transparent.
 o drawString
  public void drawString(Graphics g,
                         String s,
                         int x,
                         int y)
Draws a rendered image of a string given a graphics context, a string, and the coordinates to draw at. Similar to Font.drawString(), the Y coordinate starts at the baseline of the font.
Parameters:
g - The graphic context to draw into
s - The desired string to render
x - The X coordinate
y - The Y coordinate
 o drawString
  public void drawString(Graphics g,
                         String s,
                         int x,
                         int y,
                         int width)
Draws a rendered image of a left-justified text block given a graphics context, a string, the coordinates to draw at, and a width in pixels. The Y coordinate starts at the baseline of the first line.
Parameters:
g - The graphic context to draw into
s - The desired string to render
x - The X coordinate
y - The Y coordinate
width - The maximum width of the text block
 o charImage
  public Image charImage(int c)
Returns a rendered image given a character. If the character is unknown, an asterix or appropriate substitute is returned.
Parameters:
c - The desired character
Returns:
The rendered image of the character. If no background is set, the background will be transparent.