public class Font extends Object
A bitmap font can be created manually but that is tedious, normally you would use
the Ant task as illustrated bellow to produce a resource file containing
the supported bitmap font. For further detail read the overview document and
Resources
.
<target name="pre-init"> <taskdef classpath="ImageUnifier.jar" classname="com.sun.jwt.resource.Builder" name="build" /> <build dest="src/font.res"> <font src="images/arial.ttf" bold="true" italic="true" size="11" /> <font logicalName="Dialog" /> </build> </target>
The following attributes can be expressed for a font ant task:
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dialog, DialogInput, Monospaced, Serif, or SansSerif
Modifier and Type | Field and Description |
---|---|
static int |
FACE_MONOSPACE
Constant allowing us to author portable system fonts
|
static int |
FACE_PROPORTIONAL
Constant allowing us to author portable system fonts
|
static int |
FACE_SYSTEM
Constant allowing us to author portable system fonts
|
static int |
SIZE_LARGE
Constant allowing us to author portable system fonts
|
static int |
SIZE_MEDIUM
Constant allowing us to author portable system fonts
|
static int |
SIZE_SMALL
Constant allowing us to author portable system fonts
|
static int |
STYLE_BOLD
Constant allowing us to author portable system fonts
|
static int |
STYLE_ITALIC
Constant allowing us to author portable system fonts
|
static int |
STYLE_PLAIN
Constant allowing us to author portable system fonts
|
static int |
STYLE_UNDERLINED
Constant allowing us to author portable system fonts
|
Modifier and Type | Method and Description |
---|---|
void |
addContrast(byte value)
Deprecated.
bitmap font functionality is now deprecated
|
int |
charsWidth(char[] ch,
int offset,
int length)
Return the width of the given characters in this font instance
|
int |
charWidth(char ch)
Return the width of the specific character when rendered alone
|
static void |
clearBitmapCache()
Deprecated.
bitmap font functionality is now deprecated
|
static Font |
create(String lookup)
Creates a new font instance based on the platform specific string name of the
font.
|
static Font |
createBitmapFont(Image bitmap,
int[] cutOffsets,
int[] charWidth,
String charsets)
Deprecated.
bitmap font functionality is now deprecated
|
static Font |
createBitmapFont(String name,
Image bitmap,
int[] cutOffsets,
int[] charWidth,
String charsets)
Deprecated.
bitmap font functionality is now deprecated
|
static Font |
createSystemFont(int face,
int style,
int size)
Creates a system native font in a similar way to common MIDP fonts
|
static Font |
createTrueTypeFont(String fontName,
String fileName)
Creates a true type font with the given name/filename (font name might be different from the file name
and is required by some devices e.g.
|
Font |
derive(float sizePixels,
int weight)
Creates a font based on this truetype font with the given pixel, WARNING! This method
will only work in the case of truetype fonts!
Important some platforms e.g. |
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
int |
getAscent() |
static Font |
getBitmapFont(String fontName)
Deprecated.
bitmap font functionality is now deprecated
|
String |
getCharset()
Returns a string containing all the characters supported by this font.
|
static Font |
getDefaultFont()
Return the global default font instance
|
int |
getDescent() |
int |
getFace()
Return Optional operation returning the font face for system fonts
|
int |
getHeight()
Return the total height of the font
|
Object |
getNativeFont()
Returns the internal implementation specific font object
|
int |
getSize()
Return Optional operation returning the font size for system fonts
|
int |
getStyle()
Return Optional operation returning the font style for system fonts
|
static boolean |
isBitmapFontEnabled()
Indicates whether bitmap fonts should be enabled when loading or
the fallback system font should be used instead.
|
static boolean |
isCreationByStringSupported()
Returns true if the underlying platform allows creating a font based on a
user submitted string.
|
static boolean |
isTrueTypeFileSupported()
Returns true if the underlying platform supports loading truetype fonts from
a file.
|
static void |
setBitmapFontEnabled(boolean enabled)
Indicates whether bitmap fonts should be enabled by default when loading or
the fallback system font should be used instead.
|
static void |
setDefaultFont(Font f)
Sets the global default font instance
|
int |
stringWidth(String str)
Return the width of the given string in this font instance
|
int |
substringWidth(String str,
int offset,
int len)
Return the width of the given string subset in this font instance
|
public static final int FACE_MONOSPACE
public static final int FACE_PROPORTIONAL
public static final int FACE_SYSTEM
public static final int SIZE_LARGE
public static final int SIZE_MEDIUM
public static final int SIZE_SMALL
public static final int STYLE_BOLD
public static final int STYLE_ITALIC
public static final int STYLE_UNDERLINED
public static final int STYLE_PLAIN
public static Font getBitmapFont(String fontName)
fontName
- the font name is the logical name of the fontclearBitmapCache()
public static void clearBitmapCache()
public static boolean isTrueTypeFileSupported()
public static boolean isCreationByStringSupported()
public static Font createTrueTypeFont(String fontName, String fileName)
fontName
- the name of the fontfileName
- the file name of the font as it appears in the src directory of the project, it MUST end with the .ttf extension!public Font derive(float sizePixels, int weight)
sizePixels
- the size of the font in pixelsweight
- PLAIN, BOLD or ITALIC weight based on the constants in this classpublic static Font create(String lookup)
lookup
- a set of platform specific names delimited by commas, the first succefully
loaded font will be usedpublic void addContrast(byte value)
Notice that this method only works in one way, contrast cannot be decreased properly in a font and it should be cleared and reloaed with a Look and Feel switch.
value
- the value to increasepublic static Font createBitmapFont(String name, Image bitmap, int[] cutOffsets, int[] charWidth, String charsets)
name
- the name for the font in the cachebitmap
- a transparency map in red and black that indicates the characterscutOffsets
- character offsets matching the bitmap pixels and characters in the fontcharWidth
- The width of the character when drawing... this should not be confused with
the number of cutOffset[o + 1] - cutOffset[o]. They are completely different
since a character can be "wider" and "seep" into the next region. This is
especially true with italic characters all of which "lean" outside of their
bounds.charsets
- the set of characters in the fontpublic static Font createBitmapFont(Image bitmap, int[] cutOffsets, int[] charWidth, String charsets)
bitmap
- a transparency map in red and black that indicates the characterscutOffsets
- character offsets matching the bitmap pixels and characters in the fontcharWidth
- The width of the character when drawing... this should not be confused with
the number of cutOffset[o + 1] - cutOffset[o]. They are completely different
since a character can be "wider" and "seep" into the next region. This is
especially true with italic characters all of which "lean" outside of their
bounds.charsets
- the set of characters in the fontpublic static Font createSystemFont(int face, int style, int size)
face
- One of FACE_SYSTEM, FACE_PROPORTIONAL, FACE_MONOSPACEstyle
- one of STYLE_PLAIN, STYLE_ITALIC, STYLE_BOLDsize
- One of SIZE_SMALL, SIZE_MEDIUM, SIZE_LARGEpublic int charsWidth(char[] ch, int offset, int length)
ch
- array of charactersoffset
- characters offsetslength
- characters lengthpublic int substringWidth(String str, int offset, int len)
str
- the given stringoffset
- the string offsetlen
- the len od stringpublic int stringWidth(String str)
str
- the given string *public int charWidth(char ch)
ch
- the specific characterpublic int getHeight()
public static Font getDefaultFont()
public static void setDefaultFont(Font f)
f
- the global default font instancepublic int getFace()
public int getSize()
public int getStyle()
public String getCharset()
public static void setBitmapFontEnabled(boolean enabled)
enabled
- true to enable bitmap font loading (if they exist in the resource)public static boolean isBitmapFontEnabled()
public Object getNativeFont()
public boolean equals(Object o)
Object
public int getAscent()
public int getDescent()