|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Font


public 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.
'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.
| Field Summary | |
|---|---|
static int |
BOLD
The bold style constant. |
static int |
CENTER_BASELINE
The baseline used in ideographic scripts like Chinese, Japanese, and Korean when laying out text. |
static int |
HANGING_BASELINE
The baseline used in Devanigiri and similar scripts when laying out text. |
static int |
ITALIC
The italicized style constant. |
static int |
LAYOUT_LEFT_TO_RIGHT
A flag to layoutGlyphVector indicating that text is left-to-right as determined by Bidi analysis. |
static int |
LAYOUT_NO_LIMIT_CONTEXT
A flag to layoutGlyphVector indicating that text in the char array after the indicated limit should not be examined. |
static int |
LAYOUT_NO_START_CONTEXT
A flag to layoutGlyphVector indicating that text in the char array before the indicated start should not be examined. |
static int |
LAYOUT_RIGHT_TO_LEFT
A flag to layoutGlyphVector indicating that text is right-to-left as determined by Bidi analysis. |
protected String |
name
The logical name of this Font, as passed to the
constructor. |
static int |
PLAIN
The plain style constant. |
protected float |
pointSize
The point size of this Font in float. |
static int |
ROMAN_BASELINE
The baseline used in most Roman scripts when laying out text. |
protected int |
size
The point size of this Font, rounded to integer. |
protected int |
style
The style of this Font, as passed to the constructor. |
static int |
TRUETYPE_FONT
Identify a font resource of type TRUETYPE. |
static int |
TYPE1_FONT
Identify a font resource of type TYPE1. |
| Constructor Summary | |
|---|---|
Font
Creates a new Font with the specified attributes. |
|
Font
Creates a new Font from the specified name, style and
point size. |
|
| Method Summary | |
|---|---|
boolean |
canDisplay
Checks if this Font has a glyph for the specified
character. |
boolean |
canDisplay
Checks if this Font has a glyph for the specified
character. |
int |
canDisplayUpTo
Indicates whether or not this Font can display
the characters in the specified text
starting at start and ending at
limit. |
int |
canDisplayUpTo
Indicates whether or not this Font can display the
text specified by the iter starting at
start and ending at limit. |
int |
canDisplayUpTo
Indicates whether or not this Font can display a
specified String. |
static Font |
createFont
Returns a new Font using the specified font type
and the specified font file. |
static Font |
createFont
Returns a new Font using the specified font type
and input data. |
GlyphVector |
createGlyphVector
Creates a GlyphVector by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font. |
GlyphVector |
createGlyphVector
Creates a GlyphVector by
mapping the specified characters to glyphs one-to-one based on the
Unicode cmap in this Font. |
GlyphVector |
createGlyphVector
Creates a GlyphVector by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font. |
GlyphVector |
createGlyphVector
Creates a GlyphVector by
mapping characters to glyphs one-to-one based on the
Unicode cmap in this Font. |
static Font |
decode
Returns the Font that the str
argument describes. |
Font |
deriveFont
Creates a new Font object by replicating the current
Font object and applying a new transform to it. |
Font |
deriveFont
Creates a new Font object by replicating the current
Font object and applying a new size to it. |
Font |
deriveFont
Creates a new Font object by replicating the current
Font object and applying a new style to it. |
Font |
deriveFont
Creates a new Font object by replicating this
Font object and applying a new style and transform. |
Font |
deriveFont
Creates a new Font object by replicating this
Font object and applying a new style and size. |
Font |
deriveFont
Creates a new Font object by replicating the current
Font object and applying a new set of font attributes
to it. |
boolean |
equals
Compares this Font object to the specified
Object. |
protected void |
finalize
Disposes the native Font object. |
Map |
getAttributes
Returns a map of font attributes available in this Font. |
AttributedCharacterIterator.Attribute |
getAvailableAttributes
Returns the keys of all the attributes supported by this Font. |
byte |
getBaselineFor
Returns the baseline appropriate for displaying this character. |
String |
getFamily
Returns the family name of this Font. |
String |
getFamily
Returns the family name of this Font, localized for
the specified locale. |
static Font |
getFont
Returns a Font appropriate to this attribute set. |
static Font |
getFont
Returns a Font object from the system properties list. |
static Font |
getFont
Gets the specified Font from the system properties
list. |
String |
getFontName
Returns the font face name of this Font. |
String |
getFontName
Returns the font face name of the Font, localized
for the specified locale. |
float |
getItalicAngle
Returns the italic angle of this Font. |
LineMetrics |
getLineMetrics
Returns a LineMetrics object created with the
specified arguments. |
LineMetrics |
getLineMetrics
Returns a LineMetrics object created with the
specified arguments. |
LineMetrics |
getLineMetrics
Returns a LineMetrics object created with the specified
String and FontRenderContext . |
LineMetrics |
getLineMetrics
Returns a LineMetrics object created with the
specified arguments. |
Rectangle2D |
getMaxCharBounds
Returns the bounds for the character with the maximum bounds as defined in the specified FontRenderContext. |
int |
getMissingGlyphCode
Returns the glyphCode which is used when this Font
does not have a glyph for a specified unicode. |
String |
getName
Returns the logical name of this Font. |
int |
getNumGlyphs
Returns the number of glyphs in this Font. |
FontPeer |
getPeer
Deprecated. Font rendering is now platform independent. |
String |
getPSName
Returns the postscript name of this Font. |
int |
getSize
Returns the point size of this Font, rounded to
an integer. |
float |
getSize2D
Returns the point size of this Font in
float value. |
Rectangle2D |
getStringBounds
Returns the logical bounds of the specified array of characters in the specified FontRenderContext. |
Rectangle2D |
getStringBounds
Returns the logical bounds of the characters indexed in the specified CharacterIterator in the
specified FontRenderContext. |
Rectangle2D |
getStringBounds
Returns the logical bounds of the specified String in
the specified FontRenderContext. |
Rectangle2D |
getStringBounds
Returns the logical bounds of the specified String in
the specified FontRenderContext. |