PenProfile 2.x

com.livescribe.display
Class Font

java.lang.Object
  extended by com.livescribe.display.Font

public abstract class Font
extends Object

Font encapsulates the metrics as well as support for rendering (see TextRenderer ) text on a destination surface. The following methods allows the application to access the platform fonts

The application could also create their own fonts by extending this class.

The method Graphics.setFont(Font) is used by the application to set the font to be used for any graphics operations.


Field Summary
protected  int face
           
static int FACE_MONOSPACE
           
static int FACE_PROPORTIONAL
           
static int FACE_SYSTEM
           
protected  String faceName
           
static int FONT_INPUT_TEXT
           
static int FONT_STATIC_TEXT
           
protected  int size
           
static int SIZE_LARGE
           
static int SIZE_MEDIUM
           
static int SIZE_SMALL
           
protected  int style
           
static int STYLE_BOLD
           
static int STYLE_ITALIC
           
static int STYLE_PLAIN
           
 
Constructor Summary
protected Font(int face, int style, int size, String faceName)
          Construct an instance of Font with the attributes specified.
 
Method Summary
 int charsWidth(char[] cs, int offset, int length)
          Gets the width of the characters in the array passed.
abstract  int charWidth(char ch)
          Gets the width of the character based on the metrics.
abstract  int getBaselinePosition()
          Gets the baseline position for this font.
static Font getDefaultFont()
          Returns the default font for the current locale.
static Font getDefaultFont(Locale locale)
          Returns the default font for the locale specified.
 int getFace()
          Gets the face type of the font.
static Font getFont(int face, int style, int size)
          Gets the font for the attributes specified for the current locale.
static Font getFont(Locale locale, int face, int style, int size)
          Returns the font for the locale and the attributes specified.
static Font getFont(Locale locale, String faceName, int style, int size)
          Returns the font for the locale and the attributes specified.
static Font getFont(String faceName, int style, int size)
          Returns the font for the attributes specified for the current locale.
abstract  int getHeight()
          Gets the height of the font.
protected abstract  TextRenderer getRenderer()
          Gets the renderer that can render text using this font.
 int getSize()
          Gets the size of the font.
 int getStyle()
          Gets the style of the font.
 boolean isBold()
          Deprecated. use getStyle()
 boolean isItalic()
          Deprecated. use getStyle()
 boolean isPlain()
          Deprecated. use getStyle()
protected static void render(Font font, Graphics destination, String text, int offset, int len, int x, int y)
          Renders the text on the destination graphics using the font's renderer.
abstract  int stringWidth(String text)
          Gets the string width using based on the metrics of the font.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STYLE_PLAIN

public static final int STYLE_PLAIN
See Also:
Constant Field Values

STYLE_BOLD

public static final int STYLE_BOLD
See Also:
Constant Field Values

STYLE_ITALIC

public static final int STYLE_ITALIC
See Also:
Constant Field Values

SIZE_SMALL

public static final int SIZE_SMALL
See Also:
Constant Field Values

SIZE_MEDIUM

public static final int SIZE_MEDIUM
See Also:
Constant Field Values

SIZE_LARGE

public static final int SIZE_LARGE
See Also:
Constant Field Values

FACE_SYSTEM

public static final int FACE_SYSTEM
See Also:
Constant Field Values

FACE_MONOSPACE

public static final int FACE_MONOSPACE
See Also:
Constant Field Values

FACE_PROPORTIONAL

public static final int FACE_PROPORTIONAL
See Also:
Constant Field Values

FONT_STATIC_TEXT

public static final int FONT_STATIC_TEXT
See Also:
Constant Field Values

FONT_INPUT_TEXT

public static final int FONT_INPUT_TEXT
See Also:
Constant Field Values

face

protected final int face

style

protected final int style

size

protected final int size

faceName

protected final String faceName
Constructor Detail

Font

protected Font(int face,
               int style,
               int size,
               String faceName)
Construct an instance of Font with the attributes specified.

Parameters:
face - face type. This should be one of the constants ( FACE_MONOSPACE,FACE_PROPORTIONAL, FACE_SYSTEM)
style - style of the font. This should be one of the constants ( STYLE_BOLD,STYLE_ITALIC, STYLE_PLAIN)
size - the font size. This should be one of the constants ( SIZE_MEDIUM,SIZE_LARGE, SIZE_SMALL)
faceName - name of the font face. This cannot be null.
Method Detail

getDefaultFont

public static Font getDefaultFont()
Returns the default font for the current locale. A default font will have the following attributes

To get to the default font for the default locale, use getDefaultFont(Locale)(Locale.getDefault())

Returns:
font instance.

getFont

public static Font getFont(String faceName,
                           int style,
                           int size)
Returns the font for the attributes specified for the current locale. If a font does not exist for the faceName then null would be returned.

Parameters:
faceName - the face name
style - the font style
size - the font size
Returns:
the font for the face name and other attributes or null if a suitable font cannot be found that match the attributes.

getFont

public static Font getFont(int face,
                           int style,
                           int size)
Gets the font for the attributes specified for the current locale.

Parameters:
face - face type. This should be one of the constants ( FACE_MONOSPACE,FACE_PROPORTIONAL, FACE_SYSTEM)
style - style of the font. This should be one of the constants ( STYLE_BOLD,STYLE_ITALIC, STYLE_PLAIN)
size - the font size. This should be one of the constants ( SIZE_MEDIUM,SIZE_LARGE, SIZE_SMALL)
Returns:
font instance.

getDefaultFont

public static Font getDefaultFont(Locale locale)
Returns the default font for the locale specified. If the locale specified is null then default locale is used. It would be equivalent to calling this as getDefaultFont(Locale.getDefault()).

Parameters:
locale - locale
Returns:
default font for the locale
Since:
0.4

getFont

public static Font getFont(Locale locale,
                           int face,
                           int style,
                           int size)
Returns the font for the locale and the attributes specified. If the locale specified is null then default locale is used. It would be equivalent to calling this as Font.getFont(Locale.getDefault(),...)

Parameters:
locale - the locale
face - face type. This should be one of the constants ( FACE_MONOSPACE,FACE_PROPORTIONAL, FACE_SYSTEM)
style - style of the font. This should be one of the constants ( STYLE_BOLD,STYLE_ITALIC, STYLE_PLAIN)
size - the font size. This should be one of the constants ( SIZE_MEDIUM,SIZE_LARGE, SIZE_SMALL)
Returns:
font instance.
Since:
0.4

getFont

public static Font getFont(Locale locale,
                           String faceName,
                           int style,
                           int size)
Returns the font for the locale and the attributes specified. If the locale specified is null then default locale is used. It would be equivalent to calling this as Font.getFont(Locale.getDefault(),...)

Parameters:
locale - the locale
faceName - face name of the font. This cannot be null.
style - style of the font. This should be one of the constants ( STYLE_BOLD,STYLE_ITALIC, STYLE_PLAIN)
size - the font size. This should be one of the constants ( SIZE_MEDIUM,SIZE_LARGE, SIZE_SMALL)
Returns:
font instance.
Since:
0.4

getStyle

public int getStyle()
Gets the style of the font.

Returns:
font style
See Also:
STYLE_BOLD, STYLE_ITALIC, STYLE_PLAIN

getSize

public int getSize()
Gets the size of the font.

Returns:
font size.
See Also:
SIZE_LARGE, SIZE_MEDIUM, SIZE_SMALL

getFace

public int getFace()
Gets the face type of the font.

Returns:
face type.
See Also:
FACE_MONOSPACE, FACE_PROPORTIONAL, FACE_SYSTEM

isPlain

public boolean isPlain()
Deprecated. use getStyle()

Returns:
whether this font has the plain style.

isBold

public boolean isBold()
Deprecated. use getStyle()

Returns:
whether this font has the bold style.

isItalic

public boolean isItalic()
Deprecated. use getStyle()

Returns:
whether this font has the italic style.

getHeight

public abstract int getHeight()
Gets the height of the font.

Returns:
the font height.

getBaselinePosition

public abstract int getBaselinePosition()
Gets the baseline position for this font. The value should be greater than or equal to 0 and less than the font's height.

Returns:
the baseline position.

charWidth

public abstract int charWidth(char ch)
Gets the width of the character based on the metrics.

Parameters:
ch - character whose width
Returns:
character width.

charsWidth

public int charsWidth(char[] cs,
                      int offset,
                      int length)
Gets the width of the characters in the array passed.

Parameters:
cs - character array containing text.
offset - offset within the character array
length - number if characters from the offset specified.
Returns:
0 if any of the arguments are invalid and non-zero width based on the font's metrics.

stringWidth

public abstract int stringWidth(String text)
Gets the string width using based on the metrics of the font.

Parameters:
text - text whose width needs to be computed. This should not be a null value.
Returns:
the width of the text based on the font's metrics.

getRenderer

protected abstract TextRenderer getRenderer()
Gets the renderer that can render text using this font.

Returns:
non-null instance of TextRenderer
Since:
0.4

render

protected static void render(Font font,
                             Graphics destination,
                             String text,
                             int offset,
                             int len,
                             int x,
                             int y)
Renders the text on the destination graphics using the font's renderer.

Parameters:
font -
destination -
text -
offset -
len -
x -
y -
Since:
0.4

PenProfile 2.x

Copyright © 2010 Livescribe Inc. All Rights Reserved.
Confidential and subject to NDA.