totalcross.ui.font
Class Font

totalcross.lang.Object
  extended by totalcross.ui.font.Font

public final class Font
extends totalcross.lang.Object

Font is the character font used when drawing text on a surface. Fonts can be antialiased, and usually range from size 6 to 22.

  1. To see if the font you created is installed in the target device, query its name after the creation. If the font is not found, its name is changed to match the default font.
  2. You may create new fonts based on the TrueType fonts using the tool tc.tools.FontGenerator.


Field Summary
static int BIG_SIZE
          A big-sized font (2 above the normal size)
static String DEFAULT
          The default font name: "TCFont".
 FontMetrics fm
           
 Object hv_UserFont
           
static int MAX_FONT_SIZE
          The maximum font size: 22.
static int MIN_FONT_SIZE
          The minimum font size: 6.
 String name
          Read only field that contains the font's name.
static int NORMAL_SIZE
          A normal-sized font
 int size
          Read only field that contains the font's size.
 int style
          Read only field that contains the font's style.
static int TAB_SIZE
          The tab size will be TAB_SIZE * font's max width.
 
Method Summary
 Font asBold()
          Returns this font as Bold
static int getDefaultFontSize()
          Returns the default font size, based on the screen's size.
static Font getFont(boolean boldStyle, int size)
          Gets the instance of the default font, with the given style and size.
static Font getFont(String name, boolean boldStyle, int size)
          Gets the instance of a font of the given name, style and size.
 
Methods inherited from class totalcross.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

public String name
Read only field that contains the font's name. Note that changing this directly will have no effect.


style

public int style
Read only field that contains the font's style. Note that changing this directly will have no effect. For bold fonts, style == 1.


size

public int size
Read only field that contains the font's size. Note that changing this directly will have no effect.


hv_UserFont

public Object hv_UserFont

fm

public FontMetrics fm

NORMAL_SIZE

public static final int NORMAL_SIZE
A normal-sized font


BIG_SIZE

public static final int BIG_SIZE
A big-sized font (2 above the normal size)


DEFAULT

public static final String DEFAULT
The default font name: "TCFont". If a specified font is not found, this one is used instead.


MIN_FONT_SIZE

public static final int MIN_FONT_SIZE
The minimum font size: 6.

See Also:
Constant Field Values

MAX_FONT_SIZE

public static final int MAX_FONT_SIZE
The maximum font size: 22.

See Also:
Constant Field Values

TAB_SIZE

public static int TAB_SIZE
The tab size will be TAB_SIZE * font's max width. Defaults to 3, but you can change at any time.

Method Detail

getDefaultFontSize

public static int getDefaultFontSize()
Returns the default font size, based on the screen's size.


getFont

public static Font getFont(boolean boldStyle,
                           int size)
Gets the instance of the default font, with the given style and size.

Parameters:
boldStyle - If true, a bold font is used. Otherwise, a plain font is used.
size - If you want a text bigger than the standard size, use Font.NORMAL_SIZE+x; or if you want a text smaller than the standard size, use Font.NORMAL_SIZE-x. Size is adjusted to be in the range Font.MIN_FONT_SIZE ... Font.MAX_FONT_SIZE.

getFont

public static Font getFont(String name,
                           boolean boldStyle,
                           int size)
Gets the instance of a font of the given name, style and size. Font styles are defined in this class. BlackBerry supports the use of native system fonts, which are formed by the font family name preceded by a '$' (e.g.: "$BBCasual"). You can also specify only "$" for the font name, which means the default system font. "TCFont" will be used in place of native fonts for all platforms that do not support them.

Parameters:
name - "TCFont" is the default font. You must install other fonts if you want to use them.
boldStyle - If true, a bold font is used. Otherwise, a plain font is used.
size - If you want a text bigger than the standard size, use Font.NORMAL_SIZE+x; or if you want a text smaller than the standard size, use Font.NORMAL_SIZE-x. Size is adjusted to be in the range Font.MIN_FONT_SIZE ... Font.MAX_FONT_SIZE.

asBold

public Font asBold()
Returns this font as Bold