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
-
GraphicFont(Image)
- Initializes a new GraphicFont with the encoded font passed to it.
-
charImage(int)
- Returns a rendered image given a character.
-
charWidth(int)
- Returns the width in pixels of a given character.
-
drawString(Graphics, String, int, int)
- Draws a rendered image of a string given a graphics context, a string,
and the coordinates to draw at.
-
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.
-
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).
-
getCharSpace()
- Gets the space between non-space characters.
-
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).
-
getHeight()
- Gets the total height of the current font, which amounts to the
ascent plus the descent plus the leading.
-
getLeading()
- Gets the leading of the current font, the space between the
descent of one line and the ascent of the line below it.
-
getMaxAscent()
- Gets the maximum ascent of the current font.
-
getMaxDescent()
- Gets the maximum descent of the current font.
-
getTabWidth()
- Gets the tab width in how many space characters make up a tab
character.
-
getWordSpace()
- Gets the word spacing of the current font.
-
setBgColor(Color)
- Sets the background color the font characters are drawn against.
-
setCharSpace(int)
- Sets the character spacing in pixels.
-
setColor(Color)
- Sets the foreground color, the color the font characters are drawn in.
-
setFgColor(Color)
- Sets the foreground color.
-
setFont(Image)
- Sets a new font.
-
setLeading(int)
- Sets the leading in pixels.
-
setTabWidth(int)
- Sets the tab width as the number of spaces that make up a tab character.
-
setWordSpace(int)
- Sets the word spacing in pixels.
-
stringImage(String)
- Returns a rendered image given a string using the current font.
-
stringImage(String, int)
- Returns a rendered image of a left-justified text block given a string
and a width in pixels.
-
stringWidth(String)
- Returns the width in pixels of a given string.
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
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
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
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
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
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
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
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
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
getCharSpace
public int getCharSpace()
- Gets the space between non-space characters.
- Returns:
- The typical space between characters in pixels
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
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
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.
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.
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
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
setFgColor
public void setFgColor(Color c)
- Sets the foreground color. Same as setColor(Color).
- Parameters:
- c - The color characters will be drawn in
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.
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
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
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.
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.
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
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
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.