|
MIDP3.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.microedition.lcdui.Font
public final class Font
The Font
class represents fonts, which are used to render text
in a visible way. A font provides the information needed to map sequences of
characters to sequences of glyphs and to render
sequences of glyphs on Graphics
and Component
objects.
A character is a symbol that represents a unit of text content - an item such as a letter, a digit, or punctuation represented in an abstract way by its character code. For example, 'g', LATIN SMALL LETTER G, is a character.
A glyph is a shape that is used to render a character, and represents a unit of text display. Each character may be represented using one of many possible glyphs that differ in appearance and style. Collections of glyphs designed in the same style are called typefaces, and are represented by different fonts.
A glyph may represent a single character or a sequence of characters. In simple writing systems, such as Latin, typically one glyph represents one character. In general, however, characters and glyphs do not have one-to-one correspondence. For example, the character 'á' LATIN SMALL LETTER A WITH ACUTE, can be represented by two glyphs: one for 'a' and one for '´'. On the other hand, the two-character string "fi" can be represented by a single glyph, a "fi" ligature. In complex writing systems, such as Arabic or the South and South-East Asian writing systems, the relationship between characters and glyphs can be more complicated and involve context-dependent selection of glyphs as well as glyph reordering. A font encapsulates the collection of glyphs needed to render a selected set of characters as well as the tables needed to map sequences of characters to corresponding sequences of glyphs.
Each glyph has a set of metrics that summarize the geometry of the glyph.
The methods to get the metrics are:
getHeight
,
getAscent
,
getMaxAscent
,
getDescent
,
getMaxDescent
, and
getBaselinePosition
,
getLeading
.
The metrics are illustrated below:
The Java 2 platform distinguishes between two kinds of fonts: physical fonts and logical fonts.
Physical fonts are the actual font files containing glyph data and
tables to map from character sequences to glyph sequences, using a font
technology such as OpenType, TrueType or PostScript Type 1. All
implementations MUST support OpenType fonts with TrueType outlines.
Implementations SHOULD support TrueType hinting and MAY support advanced
typographic functions. Support for other font
technologies is optional and implementation dependent. Physical fonts use
distinct (and, sometimes, trademarked) names such as Helvetica, Palatino,
HonMincho, or any other font names. Typically, each physical font supports
only a limited character set, for example, only Latin characters or only
Japanese and Basic Latin. The set of available physical fonts varies between
configurations. Applications that require specific fonts can bundle them and
instantiate them using the
getFont
or
createFont
methods.
Logical fonts are the five font families defined by the Java platform which must be supported by any Java runtime environment: Serif, SansSerif, Monospaced, Dialog, and DialogInput. These logical fonts are not actual font libraries. Instead, the logical font names are mapped to physical fonts by the Java runtime environment. The mapping is implementation- and (usually) locale- dependent, so the look and the metrics provided by them vary. Typically, each logical font name maps to several physical fonts in order to cover a large range of characters.
A font (typeface) can have many styles and/or weights, such as heavy, medium, oblique, gothic and regular. All of these faces have similar typographic design.
There are three different names that application can get from a Font
object. The logical font name is simply the name that was used to
construct the font. The font face name, or just
font name for short, is the name of a particular font that
specifies its family and style, like "Helvetica Bold". The
family name is the name of the font family that determines the
typographic design across several faces, like "Helvetica".
The Font
class represents an instance of a font face from a
collection of font faces that are present in the system resources of the host
system. As examples, Arial Bold and Courier Bold Italic are font faces. There
can be several Font objects associated with a font face, each differing in
size, style and font features.
A Font's
attributes are style, size (or pixelSize) and font
name (or font specifier). Values for size
attribute may be
specified as either integer or symbolic constant; values for
pixelSize
shall always be specified as positive, non-zero
integer. Values for style
attribute 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 symbolic 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.
Most users are familiar with the idea of using point size to specify the size of glyphs in a font, which is based on typographic points, approximately 1/72 of an inch. The use of point size allows creating text documents that preserve the absolute size of the text, regardless of whether a document is reproduced in print or displayed on a computer screen. However, in some circumstances, a relative size of different objects of multimedia content (e.g. graphics, images and text) needs to be preserved in order to assure the content layout and appearance, especially, if scalable media content is intended to be displayed on screens with different sizes and resolutions.
Mobile devices have a wide variety of display sizes and resolutions. MIDlets
can query the display size and resolution of a particular device, and can
calculate the required size of graphics, text and image objects. For this
reason, the size of MIDP Font objects is always calculated and defined as
device-specific, in pixels. Implementations SHOULD map the values of symbolic
constants SIZE_LARGE, SIZE_MEDIUM and SIZE_SMALL to actual pixel sizes, based
on the primary device screen size and resolution. The default size of a new
Font object (when it's not specified) is SIZE_MEDIUM
.
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 |
FONT_IDLE_HIGHLIGHTED_TEXT
Font specifier for focused text on the idle screen. |
static int |
FONT_IDLE_TEXT
Font specifier for unfocused text on the idle screen. |
static int |
FONT_INPUT_TEXT
Font specifier used by the implementation to draw text input by a user. |
static int |
FONT_STATIC_TEXT
Default font specifier used to draw Item and Screen contents. |
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. |
Method Summary | |
---|---|
int |
charsWidth(char[] ch,
int offset,
int length)
Returns the advance width for showing a substring of the array ch in this Font ; starting at the specified
offset and for the specified number of characters (length). |
int |
charWidth(char ch)
Gets the advance width of the specified character in this Font . |
static Font |
createFont(java.io.InputStream fontData)
Returns a new Font using the specified font input data. |
Font |
deriveFont(int pixelSize)
Creates a new Font object by replicating this
Font object and applying a new size to it. |
Font |
deriveFont(int style,
int pixelSize)
Creates a new Font object by replicating this
Font object and applying a new style and size. |
boolean |
equals(java.lang.Object obj)
Compares this Font object to the specified
Object . |
int |
getAscent()
Gets the font ascent of this Font object. |
static Font[] |
getAvailableFonts()
Returns an array of Font where each Font object represents
a physical font available in the system. |
static Font[] |
getAvailableFonts(int style)
Returns an array of Font objects where each object
represents a physical font having specified style . |
static Font[] |
getAvailableFonts(int face,
int style,
int pixelSize)
Returns an array of Font objects where each object
represents a physical font having specified face ,
style and pixelSize . |
int |
getBaselinePosition()
Gets the distance in pixels from the top of the text to the text's baseline, which is defined by the MaxAscent value of a font. |
static Font |
getDefaultFont()
Gets the default font of the system. |
int |
getDescent()
Gets the font descent of this Font object. |
int |
getFace()
Gets the face of the font. |
java.lang.String |
getFamily()
Gets the family name of this Font . |
static Font |
getFont(int fontSpecifier)
Gets the Font used by the high level user interface for
the fontSpecifier passed in. |
static Font |
getFont(int face,
int style,
int size)
Obtains an object representing a font (including custom fonts that are either packaged with a MIDlet or downloaded at run-time, if applicable) having the specified face, style and size. |
static Font |
getFont(java.lang.String name,
int style,
int pixelSize)
Returns a new Font object from the font specified by name,
style and size in pixels. |
java.lang.String |
getFontName()
Gets the font face name of this Font . |
int |
getHeight()
Gets the standard height of a line of text in this font. |
int |
getLeading()
Gets the standard leading, in pixels, of this Font object. |
int |
getMaxAscent()
Gets the maximum ascent of this Font . |
int |
getMaxDescent()
Gets the maximum descent of this Font . |
java.lang.String |
getName()
Gets the logical name of this Font . |
int |
getPixelSize()
Gets the pixelSize of this Font . |
static int |
getPixelSize(java.lang.String name)
Gets the pixelSize supported by the font specified by
name , in pixels. |
int |
getSize()
Gets the size of this Font . |
int |
getStyle()
Gets the style of this Font . |
static int |
getStyle(java.lang.String name)
Gets the style of the font specified by name . |
boolean |
isBold()
Returns true if the font is bold. |
boolean |
isItalic()
Returns true if the font is italic. |
boolean |
isPlain()
Returns true if the font is plain. |
boolean |
isUnderlined()
Returns true if the font is underlined. |
int |
stringWidth(java.lang.String str)
Gets the total advance width for showing the specified String in this Font . |
int |
substringWidth(java.lang.String str,
int offset,
int len)
Gets the total advance width for showing the specified substring in this Font . |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int STYLE_PLAIN
Value 0
is assigned to STYLE_PLAIN
.
public static final int STYLE_BOLD
Value 1
is assigned to STYLE_BOLD
.
public static final int STYLE_ITALIC
Value 2
is assigned to STYLE_ITALIC
.
public static final int STYLE_UNDERLINED
Value 4
is assigned to STYLE_UNDERLINED
.
public static final int SIZE_LARGE
Value 16
is assigned to SIZE_LARGE
.
Implementations SHOULD map this value to a particular font size in pixels,
depending on device screen resolution and size.
public static final int SIZE_MEDIUM
Value 0
is assigned to SIZE_MEDIUM
.
Implementations SHOULD map this value to a particular font size in pixels,
depending on device screen resolution and size.
public static final int SIZE_SMALL
Value 8
is assigned to SIZE_SMALL
.
Implementations SHOULD map this value to a particular font size in pixels,
depending on device screen resolution and size.
public static final int FACE_SYSTEM
Value 0
is assigned to FACE_SYSTEM
.
public static final int FACE_MONOSPACE
Value 32
is assigned to FACE_MONOSPACE
.
public static final int FACE_PROPORTIONAL
Value 64
is assigned to FACE_PROPORTIONAL
.
public static final int FONT_STATIC_TEXT
FONT_STATIC_TEXT
has the value 0
.
getFont(int fontSpecifier)
,
Constant Field Valuespublic static final int FONT_INPUT_TEXT
FONT_INPUT_TEXT
has the value 1
.
getFont(int fontSpecifier)
,
Constant Field Valuespublic static final int FONT_IDLE_TEXT
Font specifier for unfocused text on the idle screen.
FONT_IDLE_TEXT
can be is used with getFont
to retrieve the appropriate Font
for unfocused text on the
IdleItem
on the idle screen.
FONT_IDLE_TEXT
has the value 2
.
public static final int FONT_IDLE_HIGHLIGHTED_TEXT
Font specifier for focused text on the idle screen.
FONT_IDLE_HIGHLIGHTED_TEXT
can be is used with
getFont
to retrieve the appropriate Font
for
focused text on the IdleItem
on the idle screen.
FONT_IDLE_HIGHLIGHTED_TEXT
has the value 3
.
Method Detail |
---|
public static Font createFont(java.io.InputStream fontData) throws java.io.IOException
Font
using the specified font input data.
The new Font
is created with a default size
SIZE_MEDIUM
and style STYLE_PLAIN
. This
base font can then be used with the deriveFont
methods in
this class to derive new Font
objects with varying sizes
and styles. This method does not close the InputStream
.
Font data can be made persistent. When the createFont
method is called (using either downloaded font data, or the data from
the Record Store as an InputStream
), the input font data
shall be validated before the font is created. Implementations MUST
insure that the availability and use of fonts created using
createFont
method is limited to the execution environment
of a MIDlet suite that instantiated the font. The created fonts can be
discovered using getAvailableFonts
methods and can also be queried by getStyle
method. After createFont
is called, a new
Font
may also be instantiated using
getFont
or deriveFont
methods.
fontData
- an InputStream
object representing the input
data for the font.
Font
created from the specified font type
and input data.
FontFormatException
- if the fontData
contains invalid font
information, or if a font format is not supported.
java.io.IOException
- if the fontData
cannot be completely read.public static Font getFont(java.lang.String name, int style, int pixelSize)
Font
object from the font specified by name,
style and size in pixels.
The font name can be a font face name or a font family name. It is used
together with the style to find an appropriate font face. When a font
family name is specified, the style argument is used to select the most
appropriate face from the family. When a font face name is specified, the
face's style and the style argument are merged to locate the best
matching font from the same family. For example if face name "Arial
Bold" is specified with style Font.ITALIC
, the font
system looks for a face in the "Arial" family that is bold and
italic, and may associate the font instance with the physical font face
"Arial Bold Italic". The style argument is merged with the
specified face's style, not added or subtracted. This means, specifying a
bold face and a bold style does not double-embolden the font, and
specifying a bold face and a plain style does not lighten the font. If
the font face name specifies a particular style that is not the same as
style
argument, the font face name definition takes
priority. For example, if name = "Arial Italic"
,
and style = STYLE_PLAIN
, the Font object will reference
"Arial Italic".
Fonts that are packaged with a MIDlet and declared in its Manifest can be
instantiated using this method. Fonts that are downloaded at run-time or
stored in the Record Store may be referenced using this method, but
only after they are instantiated using
createFont
method.
If no face for the requested style can be found, the font system may
apply algorithmic styling to achieve the desired style. For example, if
ITALIC
is requested, but no italic face is available,
glyphs from the plain face may be algorithmically obliqued (slanted).
Font name lookup is case insensitive, using the case folding rules of the US locale.
name
- the font name. This can be a font face name or a font family
name, and may represent either a logical font or a physical
font. The family names for logical fonts are: Dialog,
DialogInput, Monospaced, Serif, or SansSerif. If name is
null
, the logical font name of the new Font as
returned by getName()
is set to the name
"Default".style
- the style constant for the Font
. The style
argument is an integer bitmask that may be
STYLE_PLAIN
, or a bitwise union of
STYLE_BOLD
and/or STYLE_ITALIC
(for example, STYLE_ITALIC
or
STYLE_BOLD | STYLE_ITALIC
). If the style
argument does not conform to one of the expected integer
bitmasks then the style is set to STYLE_PLAIN
.pixelSize
- a positive integer value representing the size of this
Font
in pixels. When value of this argument is
equal to zero, the Font
object will have the
default size SIZE_MEDIUM
.
java.lang.IllegalArgumentException
- if the font with the specified name
is not
found, or if style
or pixelSize
are not legal values.public static Font getFont(int fontSpecifier)
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.
fontSpecifier
- one of FONT_INPUT_TEXT
, FONT_STATIC_TEXT
,
FONT_IDLE_TEXT
or FONT_IDLE_HIGHLIGHTED_TEXT
java.lang.IllegalArgumentException
- if fontSpecifier
is not a valid fontSpecifierpublic static Font getFont(int face, int style, int size)
face
- one of FACE_SYSTEM
,
FACE_MONOSPACE
, or
FACE_PROPORTIONAL
style
- STYLE_PLAIN
, STYLE_BOLD
or
STYLE_ITALIC
, or a combination of
STYLE_BOLD
and STYLE_ITALIC
.size
- one of SIZE_SMALL
, SIZE_MEDIUM
,
or SIZE_LARGE
.
java.lang.IllegalArgumentException
- if face
, style
, or
size
are not legal valuespublic java.lang.String getFamily()
Font
.
The family name of a font is font specific. Two fonts such as Helvetica Italic and Helvetica Bold have the same family name, Helvetica, whereas their font face names are Helvetica Bold and Helvetica Italic.
Use getName()
to get the logical name of the font. Use
getFontName()
to get the font face name of the font.
Font
.getName()
,
getFontName()
public java.lang.String getName()
Font
.
Use getFamily()
to get the family name of the font. Use
getFontName()
to get the font face name of the font.
Font
.getFamily()
,
getFontName()
public java.lang.String getFontName()
Font
. For example,
Helvetica Bold could be returned as a font face name.
Use getFamily()
to get the family name of the font. Use
getName()
to get the logical name of the font.
Font
.getFamily()
,
getName()
public int getSize()
size
of this Font
. For a font
object that was created using custom size in pixels, the return value
indicates the range of a pixel size of a font.
SIZE_SMALL
is returned if the size of a font (in
pixels) is smaller or equal to the system-dependent
SIZE_SMALL
; SIZE_MEDIUM
is returned if the size of a font (in
pixels) is larger then system-dependent SIZE_SMALL
but
smaller then system-dependent SIZE_LARGE
; SIZE_LARGE
is returned if the size of a font (in
pixels) is equal or larger then system-dependent SIZE_LARGE
;
SIZE_SMALL
, SIZE_MEDIUM
or
SIZE_LARGE
.public int getPixelSize()
pixelSize
of this Font
. This
pixelSize
defines the height of the em box - a
distance (in pixels) between the baselines of two unadjusted, adjacent
lines of text in a single spaced text document.
Font
, in pixels.public static int getPixelSize(java.lang.String name)
pixelSize
supported by the font specified by
name
, in pixels.
If font is scalable, this method should return the value of 'zero'. If a
font is the bitmap font, this pixelSize
defines the height
of the em box - a distance (in pixels) between the baselines
of two unadjusted, adjacent lines of text in a single spaced text
document.
name
- the font name. This can be a font face name or a font family
name, and may represent either a logical font or a physical
font. The family names for logical fonts are: Dialog,
DialogInput, Monospaced, Serif, or SansSerif. If name is
null
, the return value will indicate the size
of the default system font.
java.lang.IllegalArgumentException
- if the font with the specified name
is not
found.public int getStyle()
Font
. The value can be
STYLE_PLAIN
, STYLE_BOLD
,
STYLE_ITALIC
, or STYLE_BOLD | STYLE_ITALIC
,
or a combination of them OR'ed
with
STYLE_UNDERLINED
.
Font
.isPlain()
,
isBold()
,
isItalic()
,
isUnderlined()
public static int getStyle(java.lang.String name)
name
. The return
value can be STYLE_PLAIN
, STYLE_BOLD
,
STYLE_ITALIC
, or STYLE_BOLD | STYLE_ITALIC
.
name
- the font name. This can be a font face name or a font family
name, and may represent either a logical font or a physical
font. The family names for logical fonts are: Dialog,
DialogInput, Monospaced, Serif, or SansSerif. If name is
null
, the return value will indicate the style
of the default system font.
java.lang.IllegalArgumentException
- if the font with the specified name
is not
found.public boolean isPlain()
true
if the font is plain.
Indicates whether or not this Font
object's style is
STYLE_PLAIN
.
true
if this Font
is plain,
false
otherwise.getStyle()
public boolean isBold()
true
if the font is bold.
Indicates whether or not this Font
object's style is
STYLE_BOLD
.
true
if this Font
is bold,
false
otherwise.getStyle()
public boolean isItalic()
true
if the font is italic.
Indicates whether or not this Font
object's style is
STYLE_ITALIC
.
true
if this Font
is italic,
false
otherwise.getStyle()
public boolean isUnderlined()
true
if the font is underlined.
Indicates whether or not this Font
object's style is
STYLE_UNDERLINED
.
true
if this Font
is underlined.getStyle()
public static Font getDefaultFont()
public int getFace()
When this method is called with a Font
object that was created
from font data packaged with a MIDlet or downloaded at run-time and
instantiated using
createFont
method,
the call may return either FACE_PROPORTIONAL
or
FACE_MONOSPACE
values, based on the information encoded
in a font data.
FACE_SYSTEM
,
FACE_PROPORTIONAL
, FACE_MONOSPACE
public static Font[] getAvailableFonts()
Font
where each Font object represents
a physical font available in the system. Font object will be created for
each font face, even if they belong to the same font family. For example,
if four different fonts representing faces "Arial", "Arial
Italic", "Arial Bold" and "Arial Bold Italic"
are available, the array returned by getAvailableFonts
will have four different Font objects.
Fonts that are packaged with a MIDlet and declared in its manifest will be
instantiated and included in the Font
array. Fonts that
are downloaded at run-time or stored in the Record Store will be included
only after they are instantiated using
createFont
method.
Font
representing all available
physical fonts. Font
objects are created with the
default size.getAvailableFonts(int style)
,
getAvailableFonts(int face, int style, int pixelSize)
public static Font[] getAvailableFonts(int style)
Font
objects where each object
represents a physical font having specified style
. For
example, if three different font families "Arial",
"Courier New" and "Times New Roman" are available,
and if style = STYLE_ITALIC
- the Font[]
will have three objects representing font faces "Arial Italic",
"Courier New Italic" and "Times New Roman Italic".
Fonts that are packaged with a MIDlet and declared in its manifest will be
instantiated and included in the Font
array. Fonts that
are downloaded at run-time or stored in the Record Store will be included
only after they are instantiated using
createFont
method.
style
- STYLE_PLAIN
, STYLE_BOLD
or
STYLE_ITALIC
, or a combination of
STYLE_BOLD
and STYLE_ITALIC
.
Font
representing available physical
fonts having specified style. Font
objects are
created with the default size.getAvailableFonts()
,
getAvailableFonts(int face, int style, int pixelSize)
public static Font[] getAvailableFonts(int face, int style, int pixelSize)
Font
objects where each object
represents a physical font having specified face
,
style
and pixelSize
. For example, if three
different font families "Arial", "Courier New" and
"Times New Roman" are available, and if
face = FACE_PROPORTIONAL
and
style = STYLE_PLAIN
- the Font[]
will have
two objects representing proportional font faces "Arial" and
"Times New Roman" in the specified pixelSize
.
Fonts that are packaged with a MIDlet and declared in its manifest will be
instantiated and included in the Font
array. Fonts that
are downloaded at run-time or stored in the Record Store will be included
only after they are instantiated using
createFont
method.
face
- one of FACE_SYSTEM
,
FACE_MONOSPACE
, or
FACE_PROPORTIONAL
style
- STYLE_PLAIN
, STYLE_BOLD
or
STYLE_ITALIC
, or a combination of
STYLE_BOLD
and STYLE_ITALIC
pixelSize
- a positive integer value representing the size of this
Font
in pixels. When value of this argument is
equal to zero, the Font
object will have the
default size SIZE_MEDIUM
.
Font
representing available fonts
having specified face, style and size.getAvailableFonts()
,
getAvailableFonts(int style)
public boolean equals(java.lang.Object obj)
Font
object to the specified
Object
.
The equality of two Font
objects is determined based on
the comparison of their parameters such as font face name, style, pixel
size, ascent and descent. However, since two Font
objects
may be instantiated from different font resources (either downloaded
or resident) they may still differ, e.g. in character set coverage.
equals
in class Object
equals
in class java.lang.Object
obj
- the Object
to compare.
true
if the argument is a Font
object having the same name
, style
,
pixelSize
, ascent
and
descent
as this object; false
otherwise.public Font deriveFont(int style, int pixelSize)
Font
object by replicating this
Font
object and applying a new style and size.
style
- STYLE_PLAIN
, STYLE_BOLD
or
STYLE_ITALIC
, or a combination of
STYLE_BOLD
and STYLE_ITALIC
, or
a combination of them and STYLE_UNDERLINED
pixelSize
- a positive integer value representing the size of this
Font
in pixels. When value of this argument is
equal to zero, the Font
object will have the
default size SIZE_MEDIUM
.
Font
object.
java.lang.IllegalArgumentException
- if style
or pixelSize
are not
legal values (e.g. when the current font object is a
non-scalable bitmap font)public Font deriveFont(int pixelSize)
Font
object by replicating this
Font
object and applying a new size to it.
pixelSize
- a positive integer value representing the size of this
Font
in pixels. When value of this argument is
equal to zero, the Font
object will have the
default size SIZE_MEDIUM
.
Font
object.
java.lang.IllegalArgumentException
- if pixelSize
is not a legal value (e.g. when
the current font object is a non-scalable bitmap font)public int getBaselinePosition()
getMaxAscent()
,
getMaxDescent()
public int stringWidth(java.lang.String str)
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. Note that the advance of a String
is not
necessarily the sum of the advance widths of its characters.
str
- the String
to be measured
java.lang.NullPointerException
- if str
is null
charsWidth(char[] ch, int offset, int length)
,
substringWidth(String str, int offset, int len)
public int substringWidth(java.lang.String str, int offset, int len)
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. Note that
the advance of a String
is not necessarily the sum of the
advance widths of its characters.
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()
.
str
- the String
to be measuredoffset
- zero-based index of first character in the substringlen
- length of the substring
java.lang.StringIndexOutOfBoundsException
- if offset
and length
specify an
invalid range
java.lang.NullPointerException
- if str
is null
charsWidth(char[] ch, int offset, int length)
public int charWidth(char ch)
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.
ch
- the character to be measured
public int charsWidth(char[] ch, int offset, int length)
ch
in this Font
; 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
.
ch
- the array of charactersoffset
- the index of the first character to measurelength
- the number of characters to be measured
java.lang.ArrayIndexOutOfBoundsException
- if offset
and length
specify an
invalid range
java.lang.NullPointerException
- if ch
is null
substringWidth(String str, int offset, int len)
public int getLeading()
Font
object. The standard leading, or interline spacing,
is the logical amount of space to be reserved between the descent of one
line of text and the ascent of the next line. The height metric is
calculated to include this extra space.
Font
in pixels.getHeight()
,
getAscent()
,
getDescent()
public int getAscent()
Font
object. The
font ascent is the distance from the font's baseline to the top of most
alphanumeric characters. Some characters in the Font
might
extend above the font ascent line.
Font
in pixels.getMaxAscent()
public int getDescent()
Font
object. The
font descent is the distance from the font's baseline to the bottom of
most alphanumeric characters. Some characters in the Font
might extend below the font descent line.
Font
in pixels.getMaxDescent()
public int getHeight()
leading + ascent + descent
. Due
to rounding this may not be the same as
getAscent() + getDescent() + getLeading()
. There is no
guarantee that lines of text spaced at this distance are disjoint; such
lines may overlap if some characters overshoot either the standard ascent
or the standard descent metric.
getLeading()
,
getAscent()
,
getDescent()
public int getMaxAscent()
Font
. No
character extends further above the font's maximum ascent line.
Font
in pixels.getAscent()
public int getMaxDescent()
Font
. No
character extends further below the font's maximum descent line.
Font
in pixels.getDescent()
|
MIDP3.0 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |