PDAP Public Review Draft

java.awt
Class Font

java.lang.Object
  |
  +--java.awt.Font

public class Font
extends java.lang.Object

The Font class represents fonts. The capabilities of this class have been extended over the java.awt.Font class in JDK(tm) 1.1 and earlier releases to provide for developers the ability to utilize more sophisticated typographic features.

It is important to present the concepts behind using the words character and glyph separately. A character is a symbol that represents items like letters and numbers in a particular writing system. For example, lowercase-g is a character. When a particular character has been rendered, a shape now represents this character. This shape is called a glyph.

Chararcter encoding is a conversion table that maps character codes to glyph codes in the font. The character encoding used in the Java 2D(tm) API is Unicode. For more information on Unicode you can visit the site http://www.unicode.org.

Characters and glyphs do not have one-to-one correspondence. For example, lowercase-a acute can be represented by two glyphs: lowercase-a and acute. Another example is ligatures such as ligature -fi which is a single glyph representing two characters, f and i.

A Font is a collection of glyphs. A 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 the same as that used by java.awt.Font in JDK 1.1 and earlier releases. 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 face name is the one that should be used to specify fonts. This name signifies actual fonts in the host system, and does not identify font names with the shape of font characters as the logical font name does.

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.


Field Summary
static int BOLD
          The bold style constant.
static int ITALIC
          The italicized style constant.
protected  java.lang.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(java.lang.String name, int style, int size)
          Creates a new Font from the specified name, style and point size.
 
Method Summary
static Font decode(java.lang.String str)
          Returns the Font that the str argument describes.
 boolean equals(java.lang.Object obj)
          Compares this Font object to the specified Object.
 java.lang.String getFamily()
          Returns the family name of this Font.
static Font getFont(java.lang.String nm)
          Returns a Font object from the system properties list.
static Font getFont(java.lang.String nm, Font font)
          Gets the specified Font from the system properties list.
 java.lang.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.
 java.lang.String toString()
          Converts this Font object to a String representation.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PLAIN

public static final int PLAIN
The plain style constant.

Value 0 is assigned to PLAIN.


BOLD

public static final int BOLD
The bold style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.

Value 1 is assigned to BOLD.


ITALIC

public static final int ITALIC
The italicized style constant. This can be combined with the other style constants (except PLAIN) for mixed styles.

Value 2 is assigned to ITALIC.


name

protected java.lang.String name
The logical name of this Font, as passed to the constructor.
See Also:
getName()
Since:
JDK1.0

style

protected int style
The style of this Font, as passed to the constructor. This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
See Also:
getStyle()
Since:
JDK1.0

size

protected int size
The point size of this Font, rounded to integer.
See Also:
getSize()
Since:
JDK1.0
Constructor Detail

Font

public Font(java.lang.String name,
            int style,
            int size)
Creates a new Font from the specified name, style and point size.
Parameters:
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, SansSerif, or Symbol. If name is null, the name of the new Font is set to 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). Any other bits set in the style parameter are ignored. 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 Font
Since:
JDK1.0
See Also:
GraphicsEnvironment.getAvailableFontFamilyNames()
Method Detail

getFamily

public java.lang.String getFamily()
Returns the family name of this Font. For example, Helvetica could be returned as a family name for the font face name of Helvetica Bold. Use getName to get the logical name of the font.
Returns:
a String that is the family name of this Font.
Since:
JDK1.1
See Also:
getName()

getName

public java.lang.String getName()
Returns the logical name of this Font. Use getFamily to get the family name of the font.
Returns:
a String representing the logical name of this Font.
Since:
JDK1.0
See Also:
getFamily()

getStyle

public int getStyle()
Returns the style of this Font. The style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.
Returns:
the style of this Font
Since:
JDK1.0
See Also:
isPlain(), isBold(), isItalic()

getSize

public int getSize()
Returns the point size of this 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.
Returns:
the point size of this Font in 1/72 of an inch units.
Since:
JDK1.0

isPlain

public boolean isPlain()
Indicates whether or not this Font object's style is PLAIN.
Returns:
true if this Font has a PLAIN sytle; false otherwise.
Since:
JDK1.0
See Also:
getStyle()

isBold

public boolean isBold()
Indicates whether or not this Font object's style is BOLD.
Returns:
true if this Font object's style is BOLD; false otherwise.
Since:
JDK1.0
See Also:
getStyle()

isItalic

public boolean isItalic()
Indicates whether or not this Font object's style is ITALIC.
Returns:
true if this Font object's style is ITALIC; false otherwise.
Since:
JDK1.0
See Also:
getStyle()

getFont

public static Font getFont(java.lang.String nm)
Returns a Font object from the system properties list.
Parameters:
nm - the property name
Returns:
a Font object that the property name describes.
Since:
1.2

decode

public static Font decode(java.lang.String str)
Returns the 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.

Parameters:
str - the name of the font, or null
Returns:
the Font object that str describes, or a new default Font if str is null.
Since:
JDK1.1
See Also:
getFamily()

getFont

public static Font getFont(java.lang.String nm,
                           Font font)
Gets the specified 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:

where style is one of the three case-insensitive strings "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.

Parameters:
nm - the case-insensitive property name
font - a default Font to return if property nm is not defined
Returns:
the Font value of the property.
See Also:
decode(String)

hashCode

public int hashCode()
Returns a hashcode for this Font.
Overrides:
hashCode in class java.lang.Object
Returns:
a hashcode value for this Font.
Since:
JDK1.0

equals

public boolean equals(java.lang.Object obj)
Compares this Font object to the specified Object.
Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object to compare.
Returns:
true if the objects are the same; false otherwise.
Since:
JDK1.0

toString

public java.lang.String toString()
Converts this Font object to a String representation.
Overrides:
toString in class java.lang.Object
Returns:
a String representation of this Font object.
Since:
JDK1.0

PDAP 1.0 Spec, Rev. 0.16