danger.ui
Class Font

java.lang.Object
  extended by danger.ui.Font


public abstract class Font
extends Object

The Font class provides methods for obtaining fonts, and to query fonts for their characteristics. Once obtained, the most common use for a font is to use it in a call to Pen.setFont(danger.ui.Font).


Nested Class Summary
static class Font.GlyphMetrics
          The metrics of a glyph in this font.
 
Field Summary
static int F_BOLD
           
static int F_CONDENSED
          Deprecated. This is no longer used.
static int F_HOLLOW
           
static int F_ITALIC
           
static int F_MONOSPACE
           
static int F_OUTLINE
           
static int F_PALETTIZED
           
static int F_STRIKETHROUGH
           
static int F_UNDERLINE
           
static int FLAG_FONT_FAMILIES_ONLY
           
static int FLAG_FONT_NAMES_SORTED
           
static char GLYPH_ALT
           
static char GLYPH_BACK
           
static char GLYPH_CANCEL
           
static char GLYPH_DELETE
           
static char GLYPH_DOWN_ARROW
           
static char GLYPH_END_CALL
           
static char GLYPH_HIPTOP_LARGE
           
static char GLYPH_HIPTOP_SMALL
           
static char GLYPH_JUMP
           
static char GLYPH_LEFT_ARROW
           
static char GLYPH_LEFT_SHOULDER
           
static char GLYPH_MENU
           
static char GLYPH_PAGE_DOWN
           
static char GLYPH_PAGE_UP
           
static char GLYPH_POWER
           
static char GLYPH_RETURN
           
static char GLYPH_RIGHT_ARROW
           
static char GLYPH_RIGHT_SHOULDER
           
static char GLYPH_SEND_CALL
           
static char GLYPH_SHIFT
           
static char GLYPH_SHIFT_DE
           
static char GLYPH_SHIFT_ES
           
static char GLYPH_SHIFT_FR
           
static char GLYPH_SIM_LARGE
           
static char GLYPH_SIM_SMALL
           
static char GLYPH_SLASHED_ZERO
           
static char GLYPH_SYM
           
static char GLYPH_UP_ARROW
           
static char GLYPH_VOLUME_DOWN
           
static char GLYPH_VOLUME_UP
           
static char GLYPH_WHEEL
           
 
Method Summary
static void addFontsToMenu(Menu fontMenu, Listener listener)
          Add to the provided Menu new items naming well-known fonts available on the device.
 int charWidth(int c)
          Return the number of pixels by which a Pen would advance horizontally when drawing the specified character in this font.
static Font findBoldFont(String name)
          Find the bold font corresponding to the named font.
static Font findBoldItalicFont(String name)
          Find the bold-italic font corresponding to the named font.
static Font findBoldItalicSystemFont()
          Return the bold-italic variant of the standard system font.
static Font findBoldOutlineSystemFont()
           
static Font findBoldSystemFont()
          Return the boldface variant of the standard system font.
static Font findFont(String str)
          Return the Font with the specified name.
static Font findItalicFont(String name)
          Find the italic font corresponding to the named font.
static Font findItalicOutlineSystemFont()
           
static Font findItalicSystemFont()
          Return the italic variant of the standard system font.
static Font findOutlineSystemFont()
           
static Font findSystemFont()
          Return the standard system font.
 Font findVariant(String newFamily, int newSize, int newStyle)
          Return a Font that corresponds to this one, modified according to the specified properties.
 int getAdvance(byte[] s, int offset, int len)
          Return the number of pixels by which a Pen would advance horizontally when drawing the characters corresponding to the specified sequence of UTF-8-encoded bytes in this font.
 int getAdvance(char[] s, int offset, int len)
          Return the number of pixels by which a Pen would advance horizontally when drawing the specified sequence of characters in this font.
 int getAdvance(CharSequence s)
          Return the number of pixels by which a Pen would advance horizontally when drawing the specified sequence of characters in this font.
 int getAdvance(CharSequence s, int offset, int len)
          Return the number of pixels by which a Pen would advance horizontally when drawing the specified subsequence of characters in this font.
 int getAscent()
          Return the ascent (in pixels) of the tallest character in this font above the baseline.
 int getDescent()
          Return the descent (in pixels) of the character in this font that extends the furthest below the baseline.
abstract  String getFamily()
          Return the family of this font ("bort", "twig", or whatever)
 int getFitLtoR(CharSequence s, int start_index, int max_width)
          Return the number of characters from the specified sequence beginning at the specified start_index whose total advance is less than the specified max_width.
 int getFitLtoR(String s, int start_index, int max_width)
          Return the number of characters from the specified sequence beginning at the specified start_index whose total advance is less than the specified max_width.
 int getFitRtoL(String s, int start_index, int max_width)
          Return the number of characters from the specified sequence ending at (not just after) the specified start_index whose total advance is less than the specified max_width.
static Menu getFontMenu(Listener listener)
          Return a Menu containing items naming well-known fonts available on the device.
static String[] getFontNames(int flags)
          Return a list of the names of all the fonts available on the system.
 int getGap()
          Deprecated. Use getMetrics(char, danger.ui.Font.GlyphMetrics) Return the gap (in pixels) between characters in this font. This may be negative if characters can overlap. This value is not generally actually very meaningful because often fonts will require different spacing between different characters. This default implementation returns 0, so subclasses need to do something more sensible.
 boolean getMetrics(char c, Font.GlyphMetrics m)
          Fetch the metrics in a fractional 16.16 format of a glyph that would represent the given unicode character.
abstract  String getName()
          Return the name of this font ("BortBoldItalic9" or whatever)
abstract  int getSize()
          Return the size of this font (9, 12, etc.)
abstract  int getStyle()
          Return the style of this font (0, F_BOLD, F_BOLD | F_ITALIC, etc.)
 int getWidth(byte[] data, int offset, int len)
          Return the visual width in pixels of the sequence of characters corresponding to the specified sequence of UTF-8-encoded bytes this Font.
 int getWidth(char[] data, int offset, int len)
          Return the visual width in pixels of the specified sequence of characters in this Font.
 int getWidth(CharSequence cs)
          Return the visual width in pixels of the specified sequence of characters in this Font.
 int getWidth(CharSequence cs, int offset, int len)
          Return the visual width in pixels of the specified subsequence of characters in this Font.
 int getWidth(String s)
          Return the visual width in pixels of the specified sequence of characters in this Font.
 int getWidth(String s, int offset, int len)
          Return the visual width in pixels of the specified subsequence of characters in this Font.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GLYPH_RETURN

public static final char GLYPH_RETURN
See Also:
Constant Field Values

GLYPH_DELETE

public static final char GLYPH_DELETE
See Also:
Constant Field Values

GLYPH_ALT

public static final char GLYPH_ALT
See Also:
Constant Field Values

GLYPH_UP_ARROW

public static final char GLYPH_UP_ARROW
See Also:
Constant Field Values

GLYPH_BACK

public static final char GLYPH_BACK
See Also:
Constant Field Values

GLYPH_JUMP

public static final char GLYPH_JUMP
See Also:
Constant Field Values

GLYPH_MENU

public static final char GLYPH_MENU
See Also:
Constant Field Values

GLYPH_SLASHED_ZERO

public static final char GLYPH_SLASHED_ZERO
See Also:
Constant Field Values

GLYPH_SHIFT

public static final char GLYPH_SHIFT
See Also:
Constant Field Values

GLYPH_WHEEL

public static final char GLYPH_WHEEL
See Also:
Constant Field Values

GLYPH_LEFT_ARROW

public static final char GLYPH_LEFT_ARROW
See Also:
Constant Field Values

GLYPH_RIGHT_ARROW

public static final char GLYPH_RIGHT_ARROW
See Also:
Constant Field Values

GLYPH_DOWN_ARROW

public static final char GLYPH_DOWN_ARROW
See Also:
Constant Field Values

GLYPH_POWER

public static final char GLYPH_POWER
See Also:
Constant Field Values

GLYPH_CANCEL

public static final char GLYPH_CANCEL
See Also:
Constant Field Values

GLYPH_PAGE_UP

public static final char GLYPH_PAGE_UP
See Also:
Constant Field Values

GLYPH_PAGE_DOWN

public static final char GLYPH_PAGE_DOWN
See Also:
Constant Field Values

GLYPH_LEFT_SHOULDER

public static final char GLYPH_LEFT_SHOULDER
See Also:
Constant Field Values

GLYPH_RIGHT_SHOULDER

public static final char GLYPH_RIGHT_SHOULDER
See Also:
Constant Field Values

GLYPH_END_CALL

public static final char GLYPH_END_CALL
See Also:
Constant Field Values

GLYPH_SEND_CALL

public static final char GLYPH_SEND_CALL
See Also:
Constant Field Values

GLYPH_VOLUME_DOWN

public static final char GLYPH_VOLUME_DOWN
See Also:
Constant Field Values

GLYPH_VOLUME_UP

public static final char GLYPH_VOLUME_UP
See Also:
Constant Field Values

GLYPH_HIPTOP_LARGE

public static final char GLYPH_HIPTOP_LARGE
See Also:
Constant Field Values

GLYPH_HIPTOP_SMALL

public static final char GLYPH_HIPTOP_SMALL
See Also:
Constant Field Values

GLYPH_SIM_LARGE

public static final char GLYPH_SIM_LARGE
See Also:
Constant Field Values

GLYPH_SIM_SMALL

public static final char GLYPH_SIM_SMALL
See Also:
Constant Field Values

GLYPH_SYM

public static final char GLYPH_SYM
See Also:
Constant Field Values

GLYPH_SHIFT_FR

public static final char GLYPH_SHIFT_FR
See Also:
Constant Field Values

GLYPH_SHIFT_DE

public static final char GLYPH_SHIFT_DE
See Also:
Constant Field Values

GLYPH_SHIFT_ES

public static final char GLYPH_SHIFT_ES
See Also:
Constant Field Values

FLAG_FONT_NAMES_SORTED

public static final int FLAG_FONT_NAMES_SORTED
See Also:
Constant Field Values

FLAG_FONT_FAMILIES_ONLY

public static final int FLAG_FONT_FAMILIES_ONLY
See Also:
Constant Field Values

F_UNDERLINE

public static final int F_UNDERLINE
See Also:
Constant Field Values

F_BOLD

public static final int F_BOLD
See Also:
Constant Field Values

F_ITALIC

public static final int F_ITALIC
See Also:
Constant Field Values

F_OUTLINE

public static final int F_OUTLINE
See Also:
Constant Field Values

F_HOLLOW

public static final int F_HOLLOW
See Also:
Constant Field Values

F_CONDENSED

public static final int F_CONDENSED
Deprecated. This is no longer used.
See Also:
Constant Field Values

F_PALETTIZED

public static final int F_PALETTIZED
See Also:
Constant Field Values

F_MONOSPACE

public static final int F_MONOSPACE
See Also:
Constant Field Values

F_STRIKETHROUGH

public static final int F_STRIKETHROUGH
See Also:
Constant Field Values
Method Detail

getName

public abstract String getName()
Return the name of this font ("BortBoldItalic9" or whatever)


getFamily

public abstract String getFamily()
Return the family of this font ("bort", "twig", or whatever)


getSize

public abstract int getSize()
Return the size of this font (9, 12, etc.)


getStyle

public abstract int getStyle()
Return the style of this font (0, F_BOLD, F_BOLD | F_ITALIC, etc.)


getFontNames

public static String[] getFontNames(int flags)
Return a list of the names of all the fonts available on the system. If we have scalable fonts in the future there may be some fonts available that do not appear on this list.


getFontMenu

public static Menu getFontMenu(Listener listener)
Return a Menu containing items naming well-known fonts available on the device. This menu may take a different form in the future. The events associated with the menu items send to the specified Listener the event SystemEventIds.FONT_MENU_SELECTED with the "argument" field set to the corresponding Font object.


addFontsToMenu

public static void addFontsToMenu(Menu fontMenu,
                                  Listener listener)
Add to the provided Menu new items naming well-known fonts available on the device. This menu may take a different form in the future. The events associated with the menu items send to the specified Listener the event SystemEventIds.FONT_MENU_SELECTED with the "argument" field set to the corresponding Font object.


findFont

public static Font findFont(String str)
Return the Font with the specified name.


findSystemFont

public static Font findSystemFont()
Return the standard system font.


findBoldSystemFont

public static Font findBoldSystemFont()
Return the boldface variant of the standard system font.


findItalicSystemFont

public static Font findItalicSystemFont()
Return the italic variant of the standard system font.


findBoldItalicSystemFont

public static Font findBoldItalicSystemFont()
Return the bold-italic variant of the standard system font.


findOutlineSystemFont

public static Font findOutlineSystemFont()

findItalicOutlineSystemFont

public static Font findItalicOutlineSystemFont()

findBoldOutlineSystemFont

public static Font findBoldOutlineSystemFont()

findBoldFont

public static Font findBoldFont(String name)
Find the bold font corresponding to the named font.

Parameters:
name - non-null; the name of the non-bold font
Returns:
null-ok; the bold font, or null if there is none

findItalicFont

public static Font findItalicFont(String name)
Find the italic font corresponding to the named font.

Parameters:
name - non-null; the name of the non-italic font
Returns:
null-ok; the italic font, or null if there is none

findBoldItalicFont

public static Font findBoldItalicFont(String name)
Find the bold-italic font corresponding to the named font.

Parameters:
name - non-null; the name of the non-bold non-italic font
Returns:
null-ok; the bold-italic font, or null if there is none

findVariant

public Font findVariant(String newFamily,
                        int newSize,
                        int newStyle)
Return a Font that corresponds to this one, modified according to the specified properties. The returned Font may lack some of the desired properties if no such font is available in the system. The current implementation knows way too much about the list of available fonts and should be implemented in some more parametric way.

Parameters:
newFamily - if non-null, the name of the font family ("bort", "twig", etc.)
newSize - if not -1, the desired size of the font (9, 12, etc.)
newStyle - if not 0, the style properties to add to the font (F_BOLD, F_ITALIC, etc.)

charWidth

public int charWidth(int c)
Return the number of pixels by which a Pen would advance horizontally when drawing the specified character in this font. This default implementation returns 0, so subclasses need to do something more sensible.


getAdvance

public int getAdvance(CharSequence s)
Return the number of pixels by which a Pen would advance horizontally when drawing the specified sequence of characters in this font. This will currently always be the sum of charWidth(int) of the individual characters in the sequence, but may change in the future when we have kerning and fractional pixel spacing.

If your CharSequence may be Spanned, you probably want CharacterSpan.Series.getAdvance(danger.ui.Font, java.lang.CharSequence) instead, which takes font changes, etc., into account.


getWidth

public int getWidth(String s)
Return the visual width in pixels of the specified sequence of characters in this Font. This will frequently be the same as would be returned by getAdvance(java.lang.CharSequence) but may be slightly larger in fonts where some characters extend further to the right than they advance the pen.


getWidth

public int getWidth(CharSequence cs)
Return the visual width in pixels of the specified sequence of characters in this Font. This will frequently be the same as would be returned by getAdvance(java.lang.CharSequence) but may be slightly larger in fonts where some characters extend further to the right than they advance the pen.

If your CharSequence may be Spanned, you probably want CharacterSpan.Series.getWidth(danger.ui.Font, java.lang.CharSequence) instead, which takes font changes, etc., into account.


getAdvance

public int getAdvance(CharSequence s,
                      int offset,
                      int len)
Return the number of pixels by which a Pen would advance horizontally when drawing the specified subsequence of characters in this font. This will currently always be the sum of charWidth(int) of the individual characters in the sequence, but may change in the future when we have kerning and fractional pixel spacing.

If your CharSequence may be Spanned, you probably want CharacterSpan.Series.getAdvance(danger.ui.Font, java.lang.CharSequence) instead, which takes font changes, etc., into account.


getWidth

public int getWidth(String s,
                    int offset,
                    int len)
Return the visual width in pixels of the specified subsequence of characters in this Font. This will frequently be the same as would be returned by getAdvance(java.lang.CharSequence) but may be slightly larger in fonts where some characters extend further to the right than they advance the pen.


getWidth

public int getWidth(CharSequence cs,
                    int offset,
                    int len)
Return the visual width in pixels of the specified subsequence of characters in this Font. This will frequently be the same as would be returned by getAdvance(java.lang.CharSequence) but may be slightly larger in fonts where some characters extend further to the right than they advance the pen.

If your CharSequence may be Spanned, you probably want CharacterSpan.Series.getWidth(danger.ui.Font, java.lang.CharSequence) instead, which takes font changes, etc., into account.


getAdvance

public int getAdvance(byte[] s,
                      int offset,
                      int len)
Return the number of pixels by which a Pen would advance horizontally when drawing the characters corresponding to the specified sequence of UTF-8-encoded bytes in this font. This will currently always be the sum of charWidth(int) of the individual characters in the sequence, but may change in the future when we have kerning and fractional pixel spacing.


getWidth

public int getWidth(byte[] data,
                    int offset,
                    int len)
Return the visual width in pixels of the sequence of characters corresponding to the specified sequence of UTF-8-encoded bytes this Font. This will frequently be the same as would be returned by getAdvance(java.lang.CharSequence) but may be slightly larger in fonts where some characters extend further to the right than they advance the pen.


getAdvance

public int getAdvance(char[] s,
                      int offset,
                      int len)
Return the number of pixels by which a Pen would advance horizontally when drawing the specified sequence of characters in this font. This will currently always be the sum of charWidth(int) of the individual characters in the sequence, but may change in the future when we have kerning and fractional pixel spacing.


getWidth

public int getWidth(char[] data,
                    int offset,
                    int len)
Return the visual width in pixels of the specified sequence of characters in this Font. This will frequently be the same as would be returned by getAdvance(java.lang.CharSequence) but may be slightly larger in fonts where some characters extend further to the right than they advance the pen.


getFitLtoR

public int getFitLtoR(String s,
                      int start_index,
                      int max_width)
Return the number of characters from the specified sequence beginning at the specified start_index whose total advance is less than the specified max_width.


getFitLtoR

public int getFitLtoR(CharSequence s,
                      int start_index,
                      int max_width)
Return the number of characters from the specified sequence beginning at the specified start_index whose total advance is less than the specified max_width.


getFitRtoL

public int getFitRtoL(String s,
                      int start_index,
                      int max_width)
Return the number of characters from the specified sequence ending at (not just after) the specified start_index whose total advance is less than the specified max_width.


getAscent

public int getAscent()
Return the ascent (in pixels) of the tallest character in this font above the baseline. This default implementation returns 0, so subclasses need to do something more sensible.


getDescent

public int getDescent()
Return the descent (in pixels) of the character in this font that extends the furthest below the baseline. This default implementation returns 0, so subclasses need to do something more sensible.


getMetrics

public boolean getMetrics(char c,
                          Font.GlyphMetrics m)
Fetch the metrics in a fractional 16.16 format of a glyph that would represent the given unicode character.

Parameters:
c - The character code to fetch glyph metrics for.
m - The structure to fill in with the metrics
Returns:
true if there was a glyph available to represent the given character code, false otherwise. The contents of the metrics structure m should be considered invalid if false is returned.

getGap

public int getGap()
Deprecated. Use getMetrics(char, danger.ui.Font.GlyphMetrics) Return the gap (in pixels) between characters in this font. This may be negative if characters can overlap. This value is not generally actually very meaningful because often fonts will require different spacing between different characters. This default implementation returns 0, so subclasses need to do something more sensible.