|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mwt.Font
public class Font
The font class represents fonts, which are used to render text in a visible way.
MWT allows to use custom bitmap fonts or system fonts, depending on how the font is created.
System native fonts are created using Font(int, int, int, int)
.
You can change the size, color, face and style using the appropriate values.
The main drawback of system fonts is that they may not fit with the look and feel of your application as they are device dependent.
A system native font uses internally Font
.
Custom bitmap fonts are created using Font(Image, char[], int[], int)
or Font(Image[], char[], int)
.
Classes that extend a Font must override the following methods:
The contructor must call the system native fontFont(InputStream, char[], int, int, int)
.
Example:
class MyFont extends Font { int newAttribute = ...; public MyFont(int newAttribute) { super(0,0,0,0); this.newAttribute = newAttribute; } protected void copy(MyFont f) { super.copy(f); f.newAttribute = this.newAttribute; } private MyFont() {} public Font clone() { MyFont f = new MyFont(); copy(f); return f; } public int getHeight() { // new implementation } public int getWidth(String s) { // new implementation } protected void write(Graphics g, String text, int x, int y, int anchor) { // new implementation } }
Field Summary | |
---|---|
static int |
FACE_MONOSPACE
The "monospace" font face. |
static int |
FACE_PROPORTIONAL
The "proportional" font face. |
static int |
FACE_SYSTEM
The "system" font face. |
static int |
SIZE_LARGE
The "large" system-dependent font size. |
static int |
SIZE_MEDIUM
The "medium" system-dependent font size. |
static int |
SIZE_SMALL
The "small" system-dependent font size. |
static int |
STYLE_BOLD
The bold style constant. |
static int |
STYLE_ITALIC
The italicized style constant. |
static int |
STYLE_PLAIN
The plain style constant. |
static int |
STYLE_UNDERLINED
The underlined style constant. |
static int |
TYPE_MAPPED
|
static int |
TYPE_STRIP
|
static int |
TYPE_SYSTEM
|
Constructor Summary | |
---|---|
Font(javax.microedition.lcdui.Image[] images,
char[] charset,
int charSpacing)
Creates a font giving the char images and specifying the charset. |
|
Font(javax.microedition.lcdui.Image img,
char[] charset,
int[] widths,
int charSpacing)
Creates a font-strip. |
|
Font(java.io.InputStream is,
char[] charset,
int charSpacing,
int size,
int color)
Deprecated. |
|
Font(int color,
int face,
int size,
int style)
Creates a system native font. |
Method Summary | |
---|---|
Font |
clone()
Gets a clone of this font. |
protected void |
copy(Font font)
Copies this font into the given font. |
void |
getCharset(char[] buffer,
int offset,
int length)
Copies the charset into the given buffer at the current offset. |
int |
getCharsetLength()
Gets the charset length or -1 if it is not available. |
int |
getColor()
Gets the color of the font. |
int |
getFace()
Gets the face of the font. |
int |
getHeight()
Gets the font height. |
void |
getImages(javax.microedition.lcdui.Image[] images,
int offset,
int length)
Only for TYPE_MAPPED fonts, otherwise throws a RuntimeException
Copies the images into the given image array at the current offset. |
int |
getSize()
Gets the size of the font. |
int |
getStyle()
Gets the style of the font. |
int |
getType()
Gets the font type: TYPE_MAPPED , TYPE_STRIP or TYPE_SYSTEM |
int |
getWidth(java.lang.String s)
Gets the width for the given string. |
boolean |
isBitmapFont()
Checks if this font is a bitmap font. |
void |
setColor(int color)
Sets the color of the font if it's not a bitmap font |
void |
setFace(int face)
Sets the face of the font. |
void |
setSize(int size)
Sets the size of the font if it's not a bitmap font |
void |
setStyle(int style)
Sets the style of the font. |
protected void |
write(javax.microedition.lcdui.Graphics g,
java.lang.String s,
int x,
int y,
int anchor)
Writes the string into the given graphics object. |
void |
write(javax.microedition.lcdui.Graphics g,
java.lang.String s,
int x,
int y,
int width,
int height,
int anchor)
Writes the string into the given graphics object. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STYLE_PLAIN
public static final int STYLE_BOLD
public static final int STYLE_ITALIC
public static final int STYLE_UNDERLINED
public static final int SIZE_SMALL
public static final int SIZE_MEDIUM
public static final int SIZE_LARGE
public static final int FACE_SYSTEM
public static final int FACE_MONOSPACE
public static final int FACE_PROPORTIONAL
public static final int TYPE_SYSTEM
public static final int TYPE_MAPPED
public static final int TYPE_STRIP
Constructor Detail |
---|
public Font(int color, int face, int size, int style)
public Font(java.io.InputStream is, char[] charset, int charSpacing, int size, int color) throws java.io.IOException
InputStream
formatted using
MicroFont-Maker
tool.Image.createImage(javax.microedition.lcdui.Image)
implementation which in some devices causes problems.
Un such case, use Font(Image[], char[], int)
instead.
is
- the InputStream
formatted using MicroFont-Maker toolcharset
- The charset specifying which chars must be loaded or null to load the entire charsetcharSpacing
- The space within chars (negative values are valid)size
- The size value or 0 to use default sizecolor
- The color value
java.io.IOException
- might be thrown by the InputStream
public Font(javax.microedition.lcdui.Image[] images, char[] charset, int charSpacing)
images
- charset
- The charsetcharSpacing
- The space within chars (negative values are valid)public Font(javax.microedition.lcdui.Image img, char[] charset, int[] widths, int charSpacing)
img
- widths
- array of each char widthcharset
- charSpacing
- Method Detail |
---|
public Font clone()
clone
in class java.lang.Object
protected void copy(Font font)
public final boolean isBitmapFont()
public final int getType()
TYPE_MAPPED
, TYPE_STRIP
or TYPE_SYSTEM
public final int getColor()
public final void setColor(int color)
public final int getFace()
public final void setFace(int face)
public final int getSize()
public final void setSize(int size)
public final int getStyle()
public final void setStyle(int style)
public int getCharsetLength()
public void getCharset(char[] buffer, int offset, int length)
getCharsetLength()
returns -1, this does nothing.
public void getImages(javax.microedition.lcdui.Image[] images, int offset, int length)
TYPE_MAPPED
fonts, otherwise throws a RuntimeException
Copies the images into the given image array at the current offset.getCharsetLength()
images
- offset
- length
- public int getHeight()
public int getWidth(java.lang.String s)
public final void write(javax.microedition.lcdui.Graphics g, java.lang.String s, int x, int y, int width, int height, int anchor)
write(Graphics, String, int, int, int)
.
protected void write(javax.microedition.lcdui.Graphics g, java.lang.String s, int x, int y, int anchor)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |