|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.sun.lwuit.Font
public class Font
A simple abstraction of platform fonts and library fonts that enables the library to use more elaborate fonts unsupported by a specific device. This abstraction also supports bitmap fonts using an Ant task (more details about the unifier are explained in the javadoc overview document).
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
Field Summary | |
---|---|
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 |
Method Summary | |
---|---|
void |
addContrast(byte value)
Increase the contrast of the bitmap font for rendering on top of a surface whose color is darker. |
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()
Bitmap fonts are cached this method allows us to flush the cache thus allows us to reload a font |
static Font |
create(java.lang.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,
java.lang.String charsets)
Creates a bitmap font with the given arguments |
static Font |
createBitmapFont(java.lang.String name,
Image bitmap,
int[] cutOffsets,
int[] charWidth,
java.lang.String charsets)
Creates a bitmap font with the given arguments and places said font in the cache |
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(java.io.InputStream stream)
Creates a true type font from the given stream if the underlying platform supports truetype font loading. |
boolean |
equals(java.lang.Object o)
|
static Font |
getBitmapFont(java.lang.String fontName)
Returns a previously loaded bitmap font from cache |
java.lang.String |
getCharset()
Returns a string containing all the characters supported by this font. |
static Font |
getDefaultFont()
Return the global default font instance |
int |
getFace()
Return Optional operation returning the font face for system fonts |
int |
getHeight()
Return the total height of the font |
java.lang.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 stream. |
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(java.lang.String str)
Return the width of the given string in this font instance |
int |
substringWidth(java.lang.String str,
int offset,
int len)
Return the width of the given string subset in this font instance |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Method Detail |
---|
public static Font getBitmapFont(java.lang.String fontName)
fontName
- the font name is the logical name of the font
clearBitmapCache()
public static void clearBitmapCache()
public static boolean isTrueTypeFileSupported()
public static boolean isCreationByStringSupported()
public static Font createTrueTypeFont(java.io.InputStream stream) throws java.io.IOException
stream
- input stream containing the font
java.io.IOException
- if font loading failspublic static Font create(java.lang.String lookup)
lookup
- a set of platform specific names delimited by commas, the first succefully
loaded font will be used
public 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(java.lang.String name, Image bitmap, int[] cutOffsets, int[] charWidth, java.lang.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 font
public static Font createBitmapFont(Image bitmap, int[] cutOffsets, int[] charWidth, java.lang.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 font
public 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_LARGE
public int charsWidth(char[] ch, int offset, int length)
ch
- array of charactersoffset
- characters offsetslength
- characters length
public int substringWidth(java.lang.String str, int offset, int len)
str
- the given stringoffset
- the string offsetlen
- the len od string
public int stringWidth(java.lang.String str)
str
- the given string *
public int charWidth(char ch)
ch
- the specific character
public 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 java.lang.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 java.lang.Object getNativeFont()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |