|
Java DTV API 1.3 18-Nov-2009 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.dtv.lwuit.Font
public abstract 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
Font
object always wraps an instance of java.awt.Font
. The access to
the wrapped object is encouraged only if this is really necessary in order to
handle a specific LWUIT vs. AWT integration issue. It should not be used for
ordinary tasks.
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. |
Constructor Summary | |
---|---|
protected |
Font()
Constructs a Font object. |
|
Font(Font f)
Create a LWUIT Font object using an AWT Font instance to be wrapped. |
|
Font(String name,
int style,
int size)
Constructs a Font object. |
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. |
abstract int |
charWidth(char ch)
Return the width of the specific character when rendered alone. |
static void |
clearBitmapCache()
Bitmap fonts are cached. |
static Font |
createBitmapFont(Image bitmap,
int[] cutOffsets,
int[] charWidth,
String charsets)
Creates a bitmap font with the given arguments. |
static Font |
createBitmapFont(String name,
Image bitmap,
int[] cutOffsets,
int[] charWidth,
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 |
decode(String str)
Returns the Font described by the argument. |
abstract void |
drawChar(Graphics g,
char character,
int x,
int y)
Draw the given char using the current font and color in the x,y coordinates. |
boolean |
equals(Object obj)
Compares this Font object to the specified. |
Map |
getAttributes()
Returns a map of attributes available in this Font . |
Font |
getAWTFont()
Obtains the java.awt.Font object wrapped by this
Font instance. |
static Font |
getBitmapFont(String fontName)
Returns a previously loaded bitmap font from cache. |
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. |
String |
getFamily()
Returns the family name of this Font . |
static Font |
getFont(Map attributes)
Returns a Font appropriate to this attribute set. |
static Font |
getFont(String nm)
Returns a Font object from the system properties
list. |
static Font |
getFont(String nm,
Font font)
Gets the specified Font from the system. |
abstract int |
getHeight()
Return the total height of the font. |
String |
getName()
Returns the logical name of this Font . |
int |
getSize()
Return Optional operation returning the font size for system fonts. |
int |
getStyle()
Return Optional operation returning the font style for system fonts. |
int |
hashCode()
Returns a hash code for this Font . |
boolean |
isBold()
Indicates whether this Font is BOLD. |
boolean |
isItalic()
Indicates whether this Font is ITALIC. |
boolean |
isPlain()
Indicates whether this Font is PLAIN. |
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. |
String |
toString()
Converts this Font object into a String. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, 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
Constructor Detail |
---|
protected Font()
public Font(String name, int style, int size)
name
- the font's namestyle
- the font's stylesize
- the font's sizepublic Font(Font f)
f
- an AWT Font instance to be wrappedMethod Detail |
---|
public static Font getBitmapFont(String fontName)
fontName
- the font name is the logical name of the font
clearBitmapCache()
public static void clearBitmapCache()
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 reloaded 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 font
public 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 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(String str, int offset, int len)
str
- the given stringoffset
- the string offsetlen
- the len od string
public int stringWidth(String str)
str
- the given string *
public abstract int charWidth(char ch)
ch
- the specific character
public abstract int getHeight()
public abstract void drawChar(Graphics g, char character, int x, int y)
g
- the graphics objectcharacter
- the given characterx
- the x coordinate to draw the chary
- the y coordinate to draw the charpublic static Font getDefaultFont()
setDefaultFont(com.sun.dtv.lwuit.Font)
public static void setDefaultFont(Font f)
f
- the global default font instancegetDefaultFont()
public int getFace()
public int getSize()
public int getStyle()
public String getCharset()
public Font getAWTFont()
java.awt.Font
object wrapped by this
Font
instance.
java.awt.Font
objectpublic static Font decode(String str)
Font
described by the argument.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
str
- the description
Font
to be foundpublic boolean equals(Object obj)
Font
object to the specified.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
equals
in class Object
obj
- the object to compare with.
true
if equals, false
otherwise.public Map getAttributes()
Font
.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
public String getFamily()
Font
.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
public static Font getFont(Map attributes)
Font
appropriate to this attribute set.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
attributes
- the attribute set
Font
public static Font getFont(String nm)
Font
object from the system properties
list.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
nm
- the property name
Font
public static Font getFont(String nm, Font font)
Font
from the system.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
nm
- the property namefont
- a default Font
to be returned if the
property name does not exist
Font
foundpublic String getName()
Font
.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
public int hashCode()
Font
.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
hashCode
in class Object
public boolean isBold()
Font
is BOLD.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
Font
is BOLD, false otherwisepublic boolean isItalic()
Font
is ITALIC.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
Font
is ITALIC, false otherwisepublic boolean isPlain()
Font
is PLAIN.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
Font
is PLAIN, false otherwisepublic String toString()
Font
object into a String.
IMPLEMENTATION NOTE: Delegate to the wrapped AWT font object.
toString
in class Object
Font
|
Java DTV API 1.3 18-Nov-2009 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |