de.enough.polish.processing
Class PFont

java.lang.Object
  extended by de.enough.polish.processing.PFont

public class PFont
extends Object

Placeholder class that emulates the behavior of a Mobile Processing PFont, for compatibility with existing Mobile Processing scripts. The class actually uses J2ME Polish bitmap fonts instead.

Author:
Ovidiu

Field Summary
protected  int bgColor
           
protected  BitMapFont bitmapFont
           
protected  int color
           
static int FACE_MONOSPACE
           
static int FACE_PROPORTIONAL
           
static int FACE_SYSTEM
           
protected  Font platformFont
           
static int SIZE_LARGE
           
static int SIZE_MEDIUM
           
static int SIZE_SMALL
           
static int STYLE_BOLD
           
static int STYLE_ITALIC
           
static int STYLE_PLAIN
           
static int STYLE_UNDERLINED
           
protected  boolean useNativeFontColor
           
 
Constructor Summary
PFont(Font font)
          Creates a new PFont instance
PFont(String fontUrl)
          Creates a new PFont instance from a J2MEPolish font
PFont(String fontUrl, color textColor, color bgColor)
          Creates a new PFont instance from a J2MEPolish font
 
Method Summary
 int charsWidth(char[] ch, int offset, int length)
          Returns the width of the given char arary or of a sub-array of thereof when drawn with the given font
 int charWidth(char ch)
          Returns the width of the given char when drawn with the current font
 void draw(Graphics g, String str, int x, int y, int textAlign)
          Draws a string at the specified position
 int getBaseline()
          Returns the font's baseline position
 int getHeight()
          Gets the font height
 boolean isBitmapFont()
          Returns if the current font is a bitmap one or not
 int stringWidth(String str)
          Returns the width of the given string when drawn with the current font
 int substringWidth(String str, int offset, int length)
          Returns the width of a substring when drawn with the current font
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

platformFont

protected Font platformFont

bitmapFont

protected BitMapFont bitmapFont

color

protected int color

bgColor

protected int bgColor

useNativeFontColor

protected boolean useNativeFontColor

FACE_SYSTEM

public static int FACE_SYSTEM

FACE_MONOSPACE

public static int FACE_MONOSPACE

FACE_PROPORTIONAL

public static int FACE_PROPORTIONAL

SIZE_LARGE

public static int SIZE_LARGE

SIZE_MEDIUM

public static int SIZE_MEDIUM

SIZE_SMALL

public static int SIZE_SMALL

STYLE_PLAIN

public static int STYLE_PLAIN

STYLE_BOLD

public static int STYLE_BOLD

STYLE_ITALIC

public static int STYLE_ITALIC

STYLE_UNDERLINED

public static int STYLE_UNDERLINED
Constructor Detail

PFont

public PFont(Font font)
Creates a new PFont instance

Parameters:
font - the font to use

PFont

public PFont(String fontUrl)
Creates a new PFont instance from a J2MEPolish font

Parameters:
fontUrl - the URL from where to load the font

PFont

public PFont(String fontUrl,
             color textColor,
             color bgColor)
Creates a new PFont instance from a J2MEPolish font

Parameters:
fontUrl - the URL from where to load the font
textColor - the text color
bgColor - the background color
Method Detail

getHeight

public int getHeight()
Gets the font height

Returns:
the font height

getBaseline

public int getBaseline()
Returns the font's baseline position

Returns:
the baseline position of the font

charsWidth

public int charsWidth(char[] ch,
                      int offset,
                      int length)
Returns the width of the given char arary or of a sub-array of thereof when drawn with the given font

Parameters:
ch - the char array in question
offset - the offset at which to start the subset
length - the length of the subset
Returns:
the width in pixels

charWidth

public int charWidth(char ch)
Returns the width of the given char when drawn with the current font

Parameters:
ch - the char in question
Returns:
the width in pixels

stringWidth

public int stringWidth(String str)
Returns the width of the given string when drawn with the current font

Parameters:
str - the string in question
Returns:
the width in pixels

substringWidth

public int substringWidth(String str,
                          int offset,
                          int length)
Returns the width of a substring when drawn with the current font

Parameters:
str - the whole string
offset - the offset of the desired substring
length - the substring length
Returns:
the width

draw

public void draw(Graphics g,
                 String str,
                 int x,
                 int y,
                 int textAlign)
Draws a string at the specified position

Parameters:
g - the Graphics object to draw on
str - the string to draw
x - the x-coordinate of the drawing position
y - the y-coordinate of the drawing position
textAlign - the text alignment to use

isBitmapFont

public boolean isBitmapFont()
Returns if the current font is a bitmap one or not

Returns:
true if the font is a bitmap font, false otherwise