|
JSR 217 (Maintenance Release) | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.awt.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. 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.
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.
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
and font features.
| Field Summary | |
static int |
BOLD
The bold style constant. |
static int |
ITALIC
The italicized style constant. |
protected String |
name
The logical name of this Font, as passed to the
constructor. |
static int |
PLAIN
The plain style constant. |
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. |
| Constructor Summary | |
Font(Map attributes)
Creates a new Font with the specified attributes. |
|
Font(String name,
int style,
int size)
Creates a new Font from the specified name, style and
point size. |
|
| Method Summary | |
static Font |
decode(String str)
Returns the Font that the str
argument describes. |
boolean |
equals(Object obj)
Compares this Font object to the specified
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. |
String |
getFamily()
Returns the family name of this Font. |
static Font |
getFont(Map attributes)
Returns a Font appropriate to this attribute set. |
static Font |
getFont(String nm)
Returns a Font object from the system properties list. |
static Font |
getFont(String nm,
Font font)
Gets the specified Font from the system properties
list. |
String |
getName()
Returns the logical name of this Font. |
int |
getSize()
Returns the point size of this Font, rounded to
an integer. |
int |
getStyle()
Returns the style of this Font. |
int |
hashCode()
Returns a hashcode for this Font. |
boolean |
isBold()
Indicates whether or not this Font object's style is
BOLD. |
boolean |
isItalic()
Indicates whether or not this Font object's style is
ITALIC. |
boolean |
isPlain()
Indicates whether or not this Font object's style is
PLAIN. |
String |
toString()
Converts this Font object to a String
representation. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int PLAIN
public static final int BOLD
public static final int ITALIC
protected String name
Font, as passed to the
constructor.
getName()protected int style
Font, as passed to the constructor.
This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
getStyle()protected int size
Font, rounded to integer.
getSize()| Constructor Detail |
public Font(String name,
int style,
int size)
Font from the specified name, style and
point size.
name - the font name. This can be a logical font name or a
font face name. A logical name must be either: Dialog, DialogInput,
Monospaced, Serif, or SansSerif. If name is
null, the name of the new
Font is set to the name "Default".style - the style constant for the Font
The style argument is an integer bitmask that may
be PLAIN, or a bitwise union of BOLD and/or ITALIC
(for example, ITALIC or BOLD|ITALIC).
If the style argument does not conform to one of the expected
integer bitmasks then the style is set to PLAIN.size - the point size of the FontGraphicsEnvironment.getAvailableFontFamilyNames()public Font(Map attributes)
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.
attributes - the attributes to assign to the new
Font, or null| Method Detail |
public static Font getFont(Map attributes)
Font appropriate to this attribute set.
attributes - the attributes to assign to the new
Font
Font created with the specified
attributesTextAttributepublic 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. The list of
available family names may be obtained by using the
GraphicsEnvironment.getAvailableFontFamilyNames() method.
Use getName to get the logical name of the font.
String that is the family name of this
Font.getName()public String getName()
Font.
Use getFamily to get the family name of the font.
String representing the logical name of
this Font.getFamily()public int getStyle()
Font. The style can be
PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
FontisPlain(),
isBold(),
isItalic()public int getSize()
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. In this case one point is 1/72 of an inch.
Font in 1/72 of an
inch units.public boolean isPlain()
Font object's style is
PLAIN.
true if this Font has a
PLAIN sytle;
false otherwise.getStyle()public boolean isBold()
Font object's style is
BOLD.
true if this Font object's
style is BOLD;
false otherwise.getStyle()public boolean isItalic()
Font object's style is
ITALIC.
true if this Font object's
style is ITALIC;
false otherwise.getStyle()public static Font getFont(String nm)
Font object from the system properties list.
nm - the property name
Font object that the property name
describes.public static Font decode(String str)
Font that the str
argument describes.
To ensure that this method returns the desired Font,
format the str parameter in
one of two ways:
"fontfamilyname-style-pointsize" or
"fontfamilyname style pointsize"
in which style is one of the three
case-insensitive strings:
"BOLD", "BOLDITALIC", or
"ITALIC", and pointsize is a decimal
representation of the point size.
For example, if you want a font that is Arial, bold, and
a point size of 18, you would call this method with:
"Arial-BOLD-18".
The default size is 12 and the default style is PLAIN.
If you don't specify a valid size, the returned
Font has a size of 12. If you don't specify
a valid style, the returned Font has a style of PLAIN.
If you do not provide a valid font family name in
the str argument, this method still returns
a valid font with a family name of "dialog".
To determine what font family names are available on
your system, use the
GraphicsEnvironment.getAvailableFontFamilyNames() method.
If str is null, a new Font
is returned with the family name "dialog", a size of 12 and a
PLAIN style.
If str is null,
a new Font is returned with the name "dialog", a
size of 12 and a PLAIN style.
str - the name of the font, or null
Font object that str
describes, or a new default Font if
str is null.getFamily()
public static Font getFont(String nm,
Font font)
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 following forms:
"BOLD", "BOLDITALIC", or
"ITALIC", and point size is a decimal
representation of the point size.
The default style is PLAIN. The default point size
is 12.
If the specified property is not found, the font
argument is returned instead.
nm - the case-insensitive property namefont - a default Font to return if property
nm is not defined
Font value of the property.decode(String)public int hashCode()
Font.
hashCode in class ObjectFont.Object.equals(java.lang.Object),
Hashtablepublic boolean equals(Object obj)
Font object to the specified
Object.
equals in class Objectobj - the Object to compare
true if the objects are the same
or if the argument is a Font object
describing the same font as this object;
false otherwise.Object.hashCode(),
Hashtablepublic String toString()
Font object to a String
representation.
toString in class ObjectString representation of this
Font object.public Map getAttributes()
Font. Attributes include things like ligatures and
glyph substitution.
Font.public AttributedCharacterIterator.Attribute[] getAvailableAttributes()
Font.
Font.
|
JSR 217 (Maintenance Release) | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||