mhframework.media
Class MHImageFont

java.lang.Object
  extended by mhframework.media.MHImageFont

public class MHImageFont
extends java.lang.Object

The MHImageFont class allows loading and drawing of text using images for the characters. Reads all the png images in a directory in the form "charXX.png" where "XX" is a decimal unicode value. Characters can have different widths and heights.


Field Summary
static int BOTTOM
           
static int HCENTER
           
static int LEFT
           
static int RIGHT
           
static int TOP
           
static int VCENTER
           
 
Constructor Summary
MHImageFont()
          Creates a new MHImageFont with no characters.
MHImageFont(java.lang.String path)
          Creates a new MHImageFont and loads character images from the specified path.
 
Method Summary
 int charHeight(char ch)
          Gets the char height, in pixels, for the specified char.
 int charWidth(char ch)
          Gets the char width, in pixels, for the specified char.
 void drawChar(java.awt.Graphics g, char ch, int x, int y)
          Draws the specified character at the (x, y) location.
 void drawChar(java.awt.Graphics g, char ch, int x, int y, int anchor)
          Draws the specified character at the (x, y) location.
 void drawString(java.awt.Graphics g, java.lang.String s, int x, int y)
          Draws the specified string at the (x, y) location.
 void drawString(java.awt.Graphics g, java.lang.String s, int x, int y, int anchor)
          Draws the specified string at the (x, y) location.
 java.awt.Image getImage(char ch)
          Gets the image for a specific character.
 void load(java.lang.String path)
          Loads the image files for each character from the specified path.
 int stringWidth(java.lang.String s)
          Gets the string width, in pixels, for the specified string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HCENTER

public static final int HCENTER
See Also:
Constant Field Values

VCENTER

public static final int VCENTER
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

TOP

public static final int TOP
See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
See Also:
Constant Field Values
Constructor Detail

MHImageFont

public MHImageFont()
Creates a new MHImageFont with no characters.


MHImageFont

public MHImageFont(java.lang.String path)
Creates a new MHImageFont and loads character images from the specified path.

Method Detail

load

public void load(java.lang.String path)
          throws java.lang.NumberFormatException
Loads the image files for each character from the specified path. For example, if "../fonts/large" is the path, this method searches for all the images names "charXX.png" in that path, where "XX" is a decimal unicode value. Not every character image needs to exist; you can only do numbers or uppercase letters, for example.

Throws:
java.lang.NumberFormatException

getImage

public java.awt.Image getImage(char ch)
Gets the image for a specific character. If no image for the character exists, a special "invalid" character image is returned.


stringWidth

public int stringWidth(java.lang.String s)
Gets the string width, in pixels, for the specified string.


charWidth

public int charWidth(char ch)
Gets the char width, in pixels, for the specified char.


charHeight

public int charHeight(char ch)
Gets the char height, in pixels, for the specified char.


drawString

public void drawString(java.awt.Graphics g,
                       java.lang.String s,
                       int x,
                       int y)
Draws the specified string at the (x, y) location.


drawString

public void drawString(java.awt.Graphics g,
                       java.lang.String s,
                       int x,
                       int y,
                       int anchor)
Draws the specified string at the (x, y) location.


drawChar

public void drawChar(java.awt.Graphics g,
                     char ch,
                     int x,
                     int y)
Draws the specified character at the (x, y) location.


drawChar

public void drawChar(java.awt.Graphics g,
                     char ch,
                     int x,
                     int y,
                     int anchor)
Draws the specified character at the (x, y) location.