com.golden.gamedev.object.font
Class BitmapFont

java.lang.Object
  |
  +--com.golden.gamedev.object.font.BitmapFont
All Implemented Interfaces:
GameFont
Direct Known Subclasses:
AdvanceBitmapFont

public class BitmapFont
extends Object
implements GameFont


Field Summary
 
Fields inherited from interface com.golden.gamedev.object.GameFont
CENTER, JUSTIFY, LEFT, RIGHT
 
Constructor Summary
BitmapFont(BufferedImage[] imagefont)
          Constructs new BitmapFont with specified images, all images must have same width and height.
 
Method Summary
 int drawString(Graphics2D g, String s, int x, int y)
          Draw single line text into graphics context.
 int drawString(Graphics2D g, String s, int alignment, int x, int y, int width)
           
 int drawText(Graphics2D g, String text, int alignment, int x, int y, int width, int vspace, int firstIndent)
          Draw multiple line text into graphics context.
 int getHeight()
          Returns height of this font.
 BufferedImage[] getImageFont()
           
 BufferedImage getImageFont(int i)
           
 int getWidth(char c)
          Returns width of char c using this font.
 int getWidth(String st)
          Returns width of String st using this font.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BitmapFont

public BitmapFont(BufferedImage[] imagefont)
Constructs new BitmapFont with specified images, all images must have same width and height.
To create BitmapFont that have different width, use AdvanceBitmapFont instead.

The right image font sequence:

         ! " # $ % & ' ( ) * + , - . / 0 1 2 3
       4 5 6 7 8 9 : ; < = > ? @ A B C D E F G
       H I J K L M N O P Q R S T U V W X Y Z [
       \ ] ^ _ ' a b c d e f g h i j k l m n o
       p q r s t u v w x y z { | } ~
 

Parameters:
imagefont - font images in sequence
See Also:
AdvanceBitmapFont
Method Detail

drawString

public int drawString(Graphics2D g,
                      String s,
                      int x,
                      int y)
Description copied from interface: GameFont
Draw single line text into graphics context.

Specified by:
drawString in interface GameFont
Returns:
bottom x coordinate, used to draw next text.

drawString

public int drawString(Graphics2D g,
                      String s,
                      int alignment,
                      int x,
                      int y,
                      int width)
Specified by:
drawString in interface GameFont

drawText

public int drawText(Graphics2D g,
                    String text,
                    int alignment,
                    int x,
                    int y,
                    int width,
                    int vspace,
                    int firstIndent)
Description copied from interface: GameFont
Draw multiple line text into graphics context.

Example to write two paragraph text:

    // creates bounding box, to ensure the paragraph exactly in the box
    g.drawRect(10, 10, 620, 100);

    int nexty = GameFont.drawText(g,
        "Paragraph one, sample paragraph using GameFont drawText.",
        GameFont.LEFT, 10, 10, 620, 0, 50);

    GameFont.drawText(g,
        "Paragraph two, notice that each paragraph have 50 pixel indentation.",
        GameFont.LEFT,    // left alignment
        10,               // x
        nexty,            // y
        620,              // width
        0,                // no additional vertical spacing
        50);              // 50 pixel indentation
 

Specified by:
drawText in interface GameFont
Parameters:
g - graphics context where the text will be drawn.
text - text to be drawn.
alignment - text alignment: LEFT, RIGHT, CENTER, or JUSTIFY.
x - text x coordinate.
y - text y coordinate.
width - width per line.
vspace - additional vertical spacing, in pixel.
firstIndent - first line indentation, in pixel.
Returns:
bottom y coordinate, used to draw next paragraph.
See Also:
GameFont.LEFT, GameFont.RIGHT, GameFont.CENTER, GameFont.JUSTIFY

getImageFont

public BufferedImage[] getImageFont()

getImageFont

public BufferedImage getImageFont(int i)

getWidth

public int getWidth(char c)
Description copied from interface: GameFont
Returns width of char c using this font.

Specified by:
getWidth in interface GameFont
Returns:
char width, in pixel

getWidth

public int getWidth(String st)
Description copied from interface: GameFont
Returns width of String st using this font.

Specified by:
getWidth in interface GameFont
Returns:
String width, in pixel

getHeight

public int getHeight()
Description copied from interface: GameFont
Returns height of this font.

Specified by:
getHeight in interface GameFont
Returns:
font height, in pixel

toString

public String toString()
Overrides:
toString in class Object