JSR-62 (Final)

java.awt
Class Font

java.lang.Object
  |
  +--java.awt.Font
All Implemented Interfaces:
Serializable

public class Font
extends Object
implements Serializable

The Font class represents fonts.

See Also:
Serialized Form

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(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.
 String getFamily()
          Returns the family name of this Font.
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

PLAIN

public static final int PLAIN
The plain style constant.

See Also:
Constant Field Values

BOLD

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

See Also:
Constant Field Values

ITALIC

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

See Also:
Constant Field Values

name

protected String name
The logical name of this Font, as passed to the constructor.

Since:
JDK1.0
See Also:
getName()

style

protected int style
The style of this Font, as passed to the constructor. This style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.

Since:
JDK1.0
See Also:
getStyle()

size

protected int size
The point size of this Font, rounded to integer.

Since:
JDK1.0
See Also:
getSize()
Constructor Detail

Font

public Font(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 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 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.

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.

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(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.

decode

public static Font decode(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(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 Object
Returns:
a hashcode value for this Font.
Since:
JDK1.0
See Also:
Object.equals(java.lang.Object), Hashtable

equals

public boolean equals(Object obj)
Compares this Font object to the specified Object.

Overrides:
equals in class Object
Parameters:
obj - the Object to compare.
Returns:
true if the objects are the same; false otherwise.
Since:
JDK1.0
See Also:
Boolean.hashCode(), Hashtable

toString

public String toString()
Converts this Font object to a String representation.

Overrides:
toString in class Object
Returns:
a String representation of this Font object.
Since:
JDK1.0

JSR-62 (Final)

Java and Java 2D are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
Copyright 1993 - 2002 Sun Microsystems, Inc., 901 San Antonio Road, Palo Alto, California 94303, U.S.A. All Rights Reserved.
Use of this specification is subject to this license.