Fontpublic final class Font extends Object The Font class represents fonts and font
metrics. Fonts cannot be
created by applications. Instead, applications query for fonts
based on
font attributes and the system will attempt to provide a font that
matches
the requested attributes as closely as possible.
A Font's attributes are style, size, and face. Values for
attributes must be specified in terms of symbolic constants. Values for
the style attribute may be combined using the bit-wise
OR operator,
whereas values for the other attributes may not be combined. For example,
the value
STYLE_BOLD | STYLE_ITALIC
may be used to specify a bold-italic font; however
SIZE_LARGE | SIZE_SMALL
is illegal.
The values of these constants are arranged so that zero is valid for
each attribute and can be used to specify a reasonable default font
for the system. For clarity of programming, the following symbolic
constants are provided and are defined to have values of zero:
-
STYLE_PLAIN
-
SIZE_MEDIUM
-
FACE_SYSTEM
Values for other attributes are arranged to have disjoint bit patterns
in order to raise errors if they are inadvertently misused (for example,
using FACE_PROPORTIONAL where a style is
required). However, the values
for the different attributes are not intended to be combined with each
other. |
Fields Summary |
---|
public static final int | STYLE_PLAINThe plain style constant. This may be combined with the
other style constants for mixed styles.
Value 0 is assigned to STYLE_PLAIN . | public static final int | STYLE_BOLDThe bold style constant. This may be combined with the
other style constants for mixed styles.
Value 1 is assigned to STYLE_BOLD . | public static final int | STYLE_ITALICThe italicized style constant. This may be combined with
the other style constants for mixed styles.
Value 2 is assigned to STYLE_ITALIC . | public static final int | STYLE_UNDERLINEDThe underlined style constant. This may be combined with
the other style constants for mixed styles.
Value 4 is assigned to STYLE_UNDERLINED . | public static final int | SIZE_SMALLThe "small" system-dependent font size.
Value 8 is assigned to STYLE_SMALL . | public static final int | SIZE_MEDIUMThe "medium" system-dependent font size.
Value 0 is assigned to STYLE_MEDIUM . | public static final int | SIZE_LARGEThe "large" system-dependent font size.
Value 16 is assigned to SIZE_LARGE . | public static final int | FACE_SYSTEMThe "system" font face.
Value 0 is assigned to FACE_SYSTEM . | public static final int | FACE_MONOSPACEThe "monospace" font face.
Value 32 is assigned to FACE_MONOSPACE . | public static final int | FACE_PROPORTIONALThe "proportional" font face.
Value 64 is assigned to
FACE_PROPORTIONAL . | public static final int | FONT_STATIC_TEXTDefault font specifier used to draw Item and Screen contents.
FONT_STATIC_TEXT has the value 0 . | public static final int | FONT_INPUT_TEXTFont specifier used by the implementation to draw text input by
a user.
FONT_INPUT_TEXT has the value 1 . | private int | faceThe face of this Font | private int | styleThe style of this Font | private int | sizeThe point size of this Font | private int | baselineThe baseline of this Font | private int | heightThe height of this Font | private static Font | DEFAULT_FONTThe "default" font, constructed from the 'system' face,
plain style, and 'medium' size point. | private static Hashtable | tableA hashtable used to maintain a store of created Fonts
so they are not re-created in the future |
Constructors Summary |
---|
private Font(int inp_face, int inp_style, int inp_size)Construct a new Font object
face = inp_face;
style = inp_style;
size = inp_size;
init(inp_face, inp_style, inp_size);
|
Methods Summary |
---|
public native int | charWidth(char ch)Gets the advance width of the specified character in this Font.
The advance width is the horizontal distance that would be occupied if
ch were to be drawn using this Font ,
including inter-character spacing following
ch necessary for proper positioning of subsequent text.
| public native int | charsWidth(char[] ch, int offset, int length)Returns the advance width of the characters in ch ,
starting at the specified offset and for the specified number of
characters (length).
The advance width is the horizontal distance that would be occupied if
the characters were to be drawn using this Font ,
including inter-character spacing following
the characters necessary for proper positioning of subsequent text.
The offset and length parameters must
specify a valid range of characters
within the character array ch . The offset
parameter must be within the
range [0..(ch.length)] , inclusive.
The length parameter must be a non-negative
integer such that (offset + length) <= ch.length .
| public int | getBaselinePosition()Gets the distance in pixels from the top of the text to the text's
baseline.
// SYNC NOTE: return of atomic value, no locking necessary
return baseline;
| public static javax.microedition.lcdui.Font | getDefaultFont()Gets the default font of the system.
synchronized (Display.LCDUILock) {
if (DEFAULT_FONT == null)
DEFAULT_FONT = new Font(FACE_SYSTEM, STYLE_PLAIN, SIZE_MEDIUM);
return DEFAULT_FONT;
}
| public int | getFace()Gets the face of the font.
// SYNC NOTE: return of atomic value, no locking necessary
return face;
| public static javax.microedition.lcdui.Font | getFont(int fontSpecifier)Gets the Font used by the high level user interface
for the fontSpecifier passed in. It should be used
by subclasses of
CustomItem and Canvas to match user
interface on the device.
Font font;
switch (fontSpecifier) {
case FONT_STATIC_TEXT:
case FONT_INPUT_TEXT:
font = getDefaultFont();
break;
default:
throw new IllegalArgumentException();
}
return font;
| public static javax.microedition.lcdui.Font | getFont(int inp_face, int inp_style, int inp_size)Obtains an object representing a font having the specified face, style,
and size. If a matching font does not exist, the system will
attempt to provide the closest match. This method always
returns
a valid font object, even if it is not a close match to the request.
if ((inp_face != FACE_SYSTEM)
&& (inp_face != FACE_MONOSPACE)
&& (inp_face != FACE_PROPORTIONAL)) {
throw new IllegalArgumentException("Unsupported face");
}
if ((inp_style & ((STYLE_UNDERLINED << 1) - 1)) != inp_style) {
throw new IllegalArgumentException("Illegal style");
}
if ((inp_size != SIZE_SMALL)
&& (inp_size != SIZE_MEDIUM)
&& (inp_size != SIZE_LARGE)) {
throw new IllegalArgumentException("Unsupported size");
}
synchronized (Display.LCDUILock) {
/* IMPL_NOTE: this makes garbage. But hashtables need Object keys. */
Integer key = new Integer(inp_face | inp_style | inp_size);
Font f = (Font)table.get(key);
if (f == null) {
f = new Font(inp_face, inp_style, inp_size);
table.put(key, f);
}
return f;
}
| public int | getHeight()Gets the standard height of a line of text in this font. This value
includes sufficient spacing to ensure that lines of text painted this
distance from anchor point to anchor point are spaced as intended by the
font designer and the device. This extra space (leading) occurs below
the text.
// SYNC NOTE: return of atomic value, no locking necessary
return height;
| public int | getSize()Gets the size of the font.
// SYNC NOTE: return of atomic value, no locking necessary
return size;
| public int | getStyle()Gets the style of the font. The value is an OR'ed
combination of
STYLE_BOLD , STYLE_ITALIC , and
STYLE_UNDERLINED ; or the value is
zero (STYLE_PLAIN ).
// SYNC NOTE: return of atomic value, no locking necessary
return style;
| private native void | init(int inp_face, int inp_style, int inp_size)Natively initialize this Font object's peer
| public boolean | isBold()Returns true if the font is bold.
// SYNC NOTE: return of atomic value, no locking necessary
return (style & STYLE_BOLD) == STYLE_BOLD;
| public boolean | isItalic()Returns true if the font is italic.
// SYNC NOTE: return of atomic value, no locking necessary
return (style & STYLE_ITALIC) == STYLE_ITALIC;
| public boolean | isPlain()Returns true if the font is plain.
// SYNC NOTE: return of atomic value, no locking necessary
return style == STYLE_PLAIN;
| public boolean | isUnderlined()Returns true if the font is underlined.
// SYNC NOTE: return of atomic value, no locking necessary
return (style & STYLE_UNDERLINED) == STYLE_UNDERLINED;
| public native int | stringWidth(java.lang.String str)Gets the total advance width for showing the specified
String
in this Font .
The advance width is the horizontal distance that would be occupied if
str were to be drawn using this Font ,
including inter-character spacing following
str necessary for proper positioning of subsequent text.
| public native int | substringWidth(java.lang.String str, int offset, int len)Gets the total advance width for showing the specified substring in this
Font .
The advance width is the horizontal distance that would be occupied if
the substring were to be drawn using this Font ,
including inter-character spacing following
the substring necessary for proper positioning of subsequent text.
The offset and len parameters must
specify a valid range of characters
within str . The offset parameter must
be within the
range [0..(str.length())] , inclusive.
The len parameter must be a non-negative
integer such that (offset + len) <= str.length() .
|
|