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.
'g'
,
LATIN SMALL LETTER G, is a character.
A glyph is a shape used to render a 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, an "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.
Physical fonts are the actual font libraries containing glyph data and tables to map from character sequences to glyph sequences, using a font technology such as TrueType or PostScript Type 1. All implementations of the Java 2 platform must support TrueType fonts; support for other font technologies is implementation dependent. Physical fonts may use names such as Helvetica, Palatino, HonMincho, or any number of other font names. Typically, each physical font supports only a limited set of writing systems, 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 createFont method.
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.
Peered AWT components, such as Label and TextField , can only use logical fonts.
For a discussion of the relative advantages and disadvantages of using physical or logical fonts, see the Internationalization FAQ document.
Font
can have many faces, such as heavy, medium, oblique, gothic and
regular. All of these faces have similar typographic design.
There are three different names that you 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 face, 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, transform
and font features.
The getAllFonts
method
of the GraphicsEnvironment
class returns an
array of all font faces available in the system. These font faces are
returned as Font
objects with a size of 1, identity
transform and default font features. These
base fonts can then be used to derive new Font
objects
with varying sizes, styles, transforms and font features via the
deriveFont
methods in this class.
Font
from the specified name, style and
point size.
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 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.
Font
with the specified attributes.
This Font
only recognizes keys defined in
TextAttribute
as attributes. If attributes
is null
, a new Font
is initialized
with default attributes.Font
has a glyph for the specified
character.
Note: This method cannot handle supplementary
characters. To support all Unicode characters, including
supplementary characters, use the
method or canDisplayUpTo
methods.
Font
has a glyph for the specified
character.Font
can display
the characters in the specified text
starting at start
and ending at
limit
. This method is a convenience overload.Font
can display the
text specified by the iter
starting at
start
and ending at limit
.Font
can display a
specified String
. For strings with Unicode encoding,
it is important to know if a particular font can display the
string. This method returns an offset into the String
str
which is the first character this
Font
cannot display without using the missing glyph
code. If the Font
can display all characters, -1 is
returned.Font
using the specified font type
and the specified font file. The new Font
is
created with a point size of 1 and style PLAIN
.
This base font can then be used with the deriveFont
methods in this class to derive new Font
objects with
varying sizes, styles, transforms and font features.Font
using the specified font type
and input data. The new Font
is
created with a point size of 1 and style PLAIN
.
This base font can then be used with the deriveFont
methods in this class to derive new Font
objects with
varying sizes, styles, transforms and font features. This
method does not close the InputStream
.Font
. This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.Font
. This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.Font
. This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.Font
. This method does no other
processing besides the mapping of glyphs to characters. This
means that this method is not useful for some scripts, such
as Arabic, Hebrew, Thai, and Indic, that require reordering,
shaping, or ligature substitution.Font
that the str
argument describes.
To ensure that this method returns the desired Font,
format the str
parameter in
one of these ways
"PLAIN"
, "BOLD"
, "BOLDITALIC"
, or
"ITALIC"
, and pointsize is a positive decimal integer
representation of the point size.
For example, if you want a font that is Arial, bold, with
a point size of 18, you would call this method with:
"Arial-BOLD-18".
This is equivalent to calling the Font constructor :
new Font("Arial", Font.BOLD, 18);
and the values are interpreted as specified by that constructor.
A valid trailing decimal field is always interpreted as the pointsize. Therefore a fontname containing a trailing decimal value should not be used in the fontname only form.
If a style name field is not one of the valid style strings, it is interpreted as part of the font name, and the default style is used.
Only one of ' ' or '-' may be used to separate fields in the input. The identified separator is the one closest to the end of the string which separates a valid pointsize, or a valid style name from the rest of the string. Null (empty) pointsize and style fields are treated as valid fields with the default value for that field.
Some font names may include the separator characters ' ' or '-'.
If str
is not formed with 3 components, e.g. such that
style
or pointsize
fields are not present in
str
, and fontname
also contains a
character determined to be the separator character
then these characters where they appear as intended to be part of
fontname
may instead be interpreted as separators
so the font name may not be properly recognised.
The default size is 12 and the default style is PLAIN.
If str
does not specify a valid size, the returned
Font
has a size of 12. If str
does not
specify a valid style, the returned Font has a style of PLAIN.
If you do not specify a valid font name in
the str
argument, this method will return
a font with the family name "Dialog".
To determine what font family names are available on
your system, use the
method.
If str
is null
, a new Font
is returned with the family name "Dialog", a size of 12 and a
PLAIN style.
Font
object by replicating the current
Font
object and applying a new transform to it.Font
object by replicating the current
Font
object and applying a new size to it.Font
object by replicating the current
Font
object and applying a new style to it.Font
object by replicating this
Font
object and applying a new style and transform.Font
object by replicating this
Font
object and applying a new style and size.Font
object by replicating the current
Font
object and applying a new set of font attributes
to it.Font
object to the specified
Object
.Font
. Attributes include things like ligatures and
glyph substitution.Font
. These attributes can be used to derive other
fonts.Large fonts can support different writing systems, and each system can use a different baseline. The character argument determines the writing system to use. Clients should not assume all characters use the same baseline.
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. The list of available family names may be obtained by using the method.
Use getName
to get the logical name of the font.
Use getFontName
to get the font face name of the font.
Font
, localized for
the specified locale.
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. The list of available family names may be obtained by using the method.
Use getFontName
to get the font face name of the font.
Font
appropriate to this attribute set.Font
object from the system properties list.
nm
is treated as the name of a system property to be
obtained. The String
value of this property is then
interpreted as a Font
object according to the
specification of Font.decode(String)
If the specified property is not found, null is returned instead.Font
from the system properties
list. As in the getProperty
method of
System
, the first
argument is treated as the name of a system property to be
obtained. The String
value of this property is then
interpreted as a Font
object.
The property value should be one of the forms accepted by
Font.decode(String)
If the specified property is not found, the font
argument is returned instead.
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
, localized
for the specified locale. For example, Helvetica Fett could be
returned as the font face name.
Use getFamily
to get the family name of the font.Font
. The italic angle
is the inverse slope of the caret which best matches the posture of this
Font
.LineMetrics
object created with the
specified arguments.LineMetrics
object created with the
specified arguments.LineMetrics
object created with the
specified arguments.FontRenderContext
.Font
does not have a glyph for a specified unicode.Font
.
Use getFamily
to get the family name of the font.
Use getFontName
to get the font face name of the font.Font
. Glyph codes
for this Font
range from 0 to
getNumGlyphs()
- 1.Font
.Font
.
Use getFamily
to get the family name of the font.
Use getFontName
to get the font face name of the font.Font
, rounded to
an integer.
Most users are familiar with the idea of using point size to
specify the size of glyphs in a font. This point size defines a
measurement between the baseline of one line to the baseline of the
following line in a single spaced text document. The point size is
based on typographic points, approximately 1/72 of an inch.
The Java(tm)2D API adopts the convention that one point is equivalent to one unit in user coordinates. When using a normalized transform for converting user space coordinates to device space coordinates 72 user space units equal 1 inch in device space. In this case one point is 1/72 of an inch.
Font
in
float
value.FontRenderContext
. The logical
bounds contains the origin, ascent, advance, and height, which
includes the leading. The logical bounds does not always enclose
all the text. For example, in some languages and in some fonts,
accent marks can be positioned above the ascent or below the
descent. To obtain a visual bounding box, which encloses all the
text, use the getBounds
method of
TextLayout
.FontRenderContext
. The logical bounds
contains the origin, ascent, advance, and height, which includes
the leading. The logical bounds does not always enclose all the
text. For example, in some languages and in some fonts, accent
marks can be positioned above the ascent or below the descent.
To obtain a visual bounding box, which encloses all the text,
use the getBounds
method of
TextLayout
.String
in
the specified FontRenderContext
. The logical bounds
contains the origin, ascent, advance, and height, which includes
the leading. The logical bounds does not always enclose all the
text. For example, in some languages and in some fonts, accent
marks can be positioned above the ascent or below the descent.
To obtain a visual bounding box, which encloses all the text,
use the getBounds
method of
TextLayout
.String
in
the specified FontRenderContext
. The logical bounds
contains the origin, ascent, advance, and height, which includes
the leading. The logical bounds does not always enclose all the
text. For example, in some languages and in some fonts, accent
marks can be positioned above the ascent or below the descent.
To obtain a visual bounding box, which encloses all the text,
use the getBounds
method of
TextLayout
.Font
. The style can be
PLAIN, BOLD, ITALIC, or BOLD+ITALIC.Font
.Font
.Font
has uniform
line metrics. A logical Font
might be a
composite font, which means that it is composed of different
physical fonts to cover different code ranges. Each of these
fonts might have different LineMetrics
. If the
logical Font
is a single
font then the metrics would be uniform.Font
object's style is
BOLD.Font
object's style is
ITALIC.Font
object's style is
PLAIN.Font
object has a
transform that affects its size in addition to the Size
attribute.GlyphVector
object, performing full
layout of the text if possible. Full layout is required for
complex text, such as Arabic or Hindi. Support for different
scripts depends on the font and implementation.
Bidi, and should only be performed on text that has a uniform direction. The direction is indicated in the flags parameter,by using LAYOUT_RIGHT_TO_LEFT to indicate a right-to-left (Arabic and Hebrew) run direction, or LAYOUT_LEFT_TO_RIGHT to indicate a left-to-right (English) run direction.
In addition, some operations, such as Arabic shaping, require context, so that the characters at the start and limit can have the proper shapes. Sometimes the data in the buffer outside the provided range does not have valid data. The values LAYOUT_NO_START_CONTEXT and LAYOUT_NO_LIMIT_CONTEXT can be added to the flags parameter to indicate that the text before start, or after limit, respectively, should not be examined for context.
All other values for the flags parameter are reserved.
wait
methods.
The awakened thread will not be able to proceed until the current thread relinquishes the lock on this object. The awakened thread will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened thread enjoys no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:
synchronized
statement
that synchronizes on the object.
Class,
by executing a
synchronized static method of that class.
Only one thread at a time can own an object's monitor.
wait
methods.
The awakened threads will not be able to proceed until the current thread relinquishes the lock on this object. The awakened threads will compete in the usual manner with any other threads that might be actively competing to synchronize on this object; for example, the awakened threads enjoy no reliable privilege or disadvantage in being the next thread to lock this object.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
Font
object to a String
representation.
The current thread must own this object's monitor. The thread
releases ownership of this monitor and waits until another thread
notifies threads waiting on this object's monitor to wake up
either through a call to the notify
method or the
notifyAll
method. The thread then waits until it can
re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.The current thread must own this object's monitor.
This method causes the current thread (call it T) to place itself in the wait set for this object and then to relinquish any and all synchronization claims on this object. Thread T becomes disabled for thread scheduling purposes and lies dormant until one of four things happens:
A thread can also wake up without being notified, interrupted, or timing out, a so-called spurious wakeup. While this will rarely occur in practice, applications must guard against it by testing for the condition that should have caused the thread to be awakened, and continuing to wait if the condition is not satisfied. In other words, waits should always occur in loops, like this one:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout); ... // Perform action appropriate to condition }(For more information on this topic, see Section 3.2.3 in Doug Lea's "Concurrent Programming in Java (Second Edition)" (Addison-Wesley, 2000), or Item 50 in Joshua Bloch's "Effective Java Programming Language Guide" (Addison-Wesley, 2001).
If the current thread is interrupted by another thread while it is waiting, then an InterruptedException is thrown. This exception is not thrown until the lock status of this object has been restored as described above.
Note that the wait method, as it places the current thread into the wait set for this object, unlocks only this object; any other objects on which the current thread may be synchronized remain locked while the thread waits.
This method should only be called by a thread that is the owner
of this object's monitor. See the notify
method for a
description of the ways in which a thread can become the owner of
a monitor.
This method is similar to the wait
method of one
argument, but it allows finer control over the amount of time to
wait for a notification before giving up. The amount of real time,
measured in nanoseconds, is given by:
1000000*timeout+nanos
In all other respects, this method does the same thing as the method of one argument. In particular, wait(0, 0) means the same thing as wait(0).
The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until either of the following two conditions has occurred:
notify
method
or the notifyAll
method.
timeout
milliseconds plus nanos
nanoseconds arguments, has
elapsed.
The thread then waits until it can re-obtain ownership of the monitor and resumes execution.
As in the one argument version, interrupts and spurious wakeups are possible, and this method should always be used in a loop:
synchronized (obj) { while (<condition does not hold>) obj.wait(timeout, nanos); ... // Perform action appropriate to condition }This method should only be called by a thread that is the owner of this object's monitor. See the
notify
method for a
description of the ways in which a thread can become the owner of
a monitor.