java::awt::Font Class Reference

Inheritance diagram for java::awt::Font:

Inheritance graph
java::lang::Object
[legend]
Collaboration diagram for java::awt::Font:

Collaboration graph
java::lang::Objectjava::lang::ObjectRefjava::lang::Interfacejava::lang::Comparable
[legend]

List of all members.


Detailed Description

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.

Characters and Glyphs

A character is a symbol that represents an item such as a letter, a digit, or punctuation in an abstract way. For example, 'g', <font size="-1>">LATIN SMALL LETTER G</font>, 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 'á' <font size="-1>">LATIN SMALL LETTER A WITH ACUTE</font>, 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 and Logical Fonts

The Java 2 platform distinguishes between two kinds of fonts: physical fonts and logical fonts.

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 Faces and Names

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

Version:
1.181, 01/23/03

Public Types

enum  FONT_STYLE { PLAIN, BOLD, ITALIC }
enum  FONT_BASELINE { ROMAN_BASELINE, CENTER_BASELINE, HANGING_BASELINE }
enum  FONT_TYPE { TRUETYPE_FONT }

Public Member Functions

 Font ()
 Default constructor.
 Font (const String &name, jint style, jint size)
 Creates a new Font from the specified name, style and point size.
 Font (const Map &attrs)
 Creates a new Font with the specified attributes.
virtual AffineTransformgetTransform () const
 Returns a copy of the transform associated with this Font.
virtual String getName () const
 Returns the logical name of this Font.
virtual jint getStyle () const
 Returns the style of this Font.
virtual jint getSize () const
 Returns the point size of this Font, rounded to an integer.
virtual jfloat getSize2D () const
 Returns the point size of this Font in float value.
virtual jboolean isPlain () const
 Indicates whether or not this Font object's style is PLAIN.
virtual jboolean isBold () const
 Indicates whether or not this Font object's style is BOLD.
virtual jboolean isItalic () const
 Indicates whether or not this Font object's style is ITALIC.
virtual jboolean isTransformed () const
 Indicates whether or not this Font object has a transform that affects its size in addition to the Size attribute.
virtual jint hashCode () const
 Returns a hashcode for this Font.
virtual jboolean equals (const Object &obj) const
 Compares this Font object to the specified Object.
virtual String toString () const
 Returns a string representation of the object.

Member Enumeration Documentation

enum java::awt::Font::FONT_STYLE

Enumerator:
PLAIN  The plain style constant.
BOLD  The bold style constant.

This can be combined with the other style constants (except PLAIN) for mixed styles.

ITALIC  The italicized style constant.

This can be combined with the other style constants (except PLAIN) for mixed styles.

enum java::awt::Font::FONT_BASELINE

Enumerator:
ROMAN_BASELINE  The baseline used in most Roman scripts when laying out text.
CENTER_BASELINE  The baseline used in ideographic scripts like Chinese, Japanese, and Korean when laying out text.
HANGING_BASELINE  The baseline used in Devanigiri and similar scripts when laying out text.

enum java::awt::Font::FONT_TYPE

Enumerator:
TRUETYPE_FONT  Create a Font of type TRUETYPE.

In future other types may be added to support other font types.


Constructor & Destructor Documentation

java::awt::Font::Font (  ) 

Default constructor.

java::awt::Font::Font ( const String name,
jint  style,
jint  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, 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 Font
See also:
GraphicsEnvironment::getAllFonts

GraphicsEnvironment::getAvailableFontFamilyNames

Since:
JDK1.0

java::awt::Font::Font ( const Map attrs  ) 

Creates a new 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.

Parameters:
attributes the attributes to assign to the new Font, or null


Member Function Documentation

virtual AffineTransform& java::awt::Font::getTransform (  )  const [virtual]

Returns a copy of the transform associated with this Font.

Returns:
an AffineTransform object representing the transform attribute of this Font object.

virtual String java::awt::Font::getName (  )  const [virtual]

Returns the logical name of this Font.

Use getFamily to get the family name of the font. Use getFontName to get the font face name of the font.

Returns:
a String representing the logical name of this Font.
See also:
getFamily

getFontName

Since:
JDK1.0

virtual jint java::awt::Font::getStyle (  )  const [virtual]

Returns the style of this Font.

The style can be PLAIN, BOLD, ITALIC, or BOLD+ITALIC.

Returns:
the style of this Font
See also:
isPlain

isBold

isItalic

Since:
JDK1.0

virtual jint java::awt::Font::getSize (  )  const [virtual]

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.
See also:
getSize2D

GraphicsConfiguration::getDefaultTransform

GraphicsConfiguration::getNormalizingTransform

Since:
JDK1.0

virtual jfloat java::awt::Font::getSize2D (  )  const [virtual]

Returns the point size of this Font in float value.

Returns:
the point size of this Font as a float value.
See also:
getSize
Since:
1.2

virtual jboolean java::awt::Font::isPlain (  )  const [virtual]

Indicates whether or not this Font object's style is PLAIN.

Returns:
true if this Font has a PLAIN sytle; false otherwise.
See also:
java.awt.Font::getStyle
Since:
JDK1.0

virtual jboolean java::awt::Font::isBold (  )  const [virtual]

Indicates whether or not this Font object's style is BOLD.

Returns:
true if this Font object's style is BOLD; false otherwise.
See also:
java.awt.Font::getStyle
Since:
JDK1.0

virtual jboolean java::awt::Font::isItalic (  )  const [virtual]

Indicates whether or not this Font object's style is ITALIC.

Returns:
true if this Font object's style is ITALIC; false otherwise.
See also:
java.awt.Font::getStyle
Since:
JDK1.0

virtual jboolean java::awt::Font::isTransformed (  )  const [virtual]

Indicates whether or not this Font object has a transform that affects its size in addition to the Size attribute.

Returns:
true if this Font object has a non-identity AffineTransform attribute. false otherwise.
See also:
java.awt.Font::getTransform
Since:
1.4

virtual jint java::awt::Font::hashCode (  )  const [virtual]

Returns a hashcode for this Font.

Returns:
a hashcode value for this Font.
Since:
JDK1.0

Reimplemented from java::lang::Object.

virtual jboolean java::awt::Font::equals ( const Object obj  )  const [virtual]

Compares this Font object to the specified Object.

Parameters:
obj the Object to compare
Returns:
true if the objects are the same or if the argument is a Font object describing the same font as this object; false otherwise.
Since:
JDK1.0

Reimplemented from java::lang::Object.

virtual String java::awt::Font::toString (  )  const [virtual]

Returns a string representation of the object.

In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `</code>', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: <blockquote>

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
</blockquote>

Returns:
a string representation of the object.

Reimplemented from java::lang::Object.


The documentation for this class was generated from the following file:
Generated on Fri May 16 11:55:59 2008 for CrossPlatformJavaLikeC++API by  doxygen 1.5.3