Font Class

Font Class

This Package | All Packages

public final class Font
implements IConstructable, IPersistable

Encapsulates a Win32 font. Fonts are used to draw text on video displays and other output devices.

Fields
Name Description
ANSI_FIXED Standard ANSI fixed-width font.
ANSI_VAR Standard ANSI variable-width font.
DEFAULT_GUI Default font for the current user interface.
DEVICE_DEFAULT Standard font for the current graphics device.
OEM_FIXED Standard original equipment manufacturer (OEM) fixed font.
SYSTEM Standard Windows variable-width system font.
SYSTEM_FIXED Standard Windows fixed-width system font.

Constructors
Name Description
Font(int handle) Creates a Font object based on an existing Win32 font handle.
Font(String name, int size) Creates a new font based on a specified font face name and size.
Font(String name, int size, int weight, boolean italic, boolean underline, boolean strikeOut) Creates a new font given a font face, size, and style.
Font(String name, int size, int weight, boolean italic, boolean underline, boolean strikeOut, int charSet, int orientation) Creates a new font.
Font(Font font, int size) Creates a new font from an existing one.
Font(Font font, int weight, boolean italic, boolean underline, boolean strikeOut) Creates a new font from an existing one.
Font(Font font, int size, int weight, boolean italic, boolean underline, boolean strikeOut) Creates a new font from an existing one.
Font(int family, int pitch, int size) Creates a new font based on a specified font family, pitch and size.
Font(int family, int pitch, int size, int weight, boolean italic, boolean underline, boolean strikeOut) Creates a new font based on a specified font face, size, and style.
Font(int family, int pitch, int size, int weight, boolean italic, boolean underline, boolean strikeOut, int charSet, int orientation) Creates a new font, based on the specified family, pitch, size, and weight.
Font(IDataStream stream) Creates a new font from a specified datastream.

Methods
Name Description
equals(Object obj) Determines if one object equates to another.
equalsBase(Font font) Determines if one font shares the same base font as another.
finalize() throws Throwable Releases all resources allocated by this object.
getBold() Retrieves a boolean value that indicates if the font is bold.
getCharacterSet() Retrieves the character set the font is using.
getConstructorArgs() Retrieves the ConstructorArgs needed to persist this object.
getExtension() Retrieves a file name extension with which to save this object's persistance data.
getFontMetrics() Retrieves a FontMetrics object for this font.
getFontMetrics(Graphics gr) Retrieves a FontMetrics object for this font.
getHandle() Retrieves the Win32 HFONT handle.
getItalic() Retrieves a boolean value that indicates whether the font is italicized.
getLogicalUnits(float points) Converts a font's Point value to a logical unit.
getLogicalUnits(float points, Graphics gr) Converts a font's Point value to a logical unit.
getName() Retrieves the face name of the font, and returns the name in a String object.
getOrientation() Rerieves the orientation of the font, in tenths of a degree, from the x-axis of the device.
getPoints(int units) Converts a font's logical unit to a point.
getPoints(int units, Graphics gr) Converts a font's logical unit to a point.
getSize() Retrieves the size of the font in logical units.
getStock(int index) Retrieves a stock font, based on a specified index.
getStrikeout() Retrieves a boolean value that indicates whether the current font is a strike-through font.
getUnderline() Retrieves a boolean value that indicates whether the font is underlined.
getWeight() Retrieves the weight associated with this font.
hashCode() Retrieves a hash code value for this font.
save(IDataStream stream) Persists this font to the given datastream.

Fields

Font.ANSI_FIXED

Syntax
public static final Font ANSI_FIXED;
Description
Standard ANSI fixed-width font.

Font.ANSI_VAR

Syntax
public static final Font ANSI_VAR;
Description
Standard ANSI variable-width font.

Font.DEFAULT_GUI

Syntax
public static final Font DEFAULT_GUI;
Description
Default font for the current user interface. This font automatically adapts its character set to the locale of the user.

Font.DEVICE_DEFAULT

Syntax
public static final Font DEVICE_DEFAULT;
Description
Standard font for the current graphics device.

Font.OEM_FIXED

Syntax
public static final Font OEM_FIXED;
Description
Standard original equipment manufacturer (OEM) fixed font.

Font.SYSTEM

Syntax
public static final Font SYSTEM;
Description
Standard Windows variable-width system font.

Font.SYSTEM_FIXED

Syntax
public static final Font SYSTEM_FIXED;
Description
Standard Windows fixed-width system font.

Constructors

Font.Font

Syntax 1
public Font( int handle );
Parameters
handle
The handle of the font.
Description

Creates a Font object based on an existing Win32 font handle. The handle is not owned by this object.



Syntax 2
public Font( String name, int size );
Parameters
name
The face name of the font to create.
size
The size of the font in logical units.
Description

Creates a new font based on a specified font face name and size.



Syntax 3
public Font( String name, int size, int weight, boolean italic, boolean underline, boolean strikeOut );
Parameters
name
The face name of the font to create.
size
The size of the font in logical units.
weight
The weight of the font. This must be one of the enumeration values defined in the FontWeight class.
italic
Set to true if the font is to be italicized; otherwise, set to false.
underline
Set to true if the font is to be underlined; therwise, false.
strikeOut
Set to true if the font is to be struck through; otherwise, set to false.
Description

Creates a new font given a font face, size, and style.



Syntax 4
public Font( String name, int size, int weight, boolean italic, boolean underline, boolean strikeOut, int charSet, int orientation );
Parameters
name
The face name of the font to create.
size
The size of the font in logical units.
weight
The weight of the font. This must be one of the enumeration values defined by the FontWeight class.
italic
Set to true if the font is to be italicized; otherwise, set to false.
underline
Set to true if the font is to be underlined; otherwise, set to false.
strikeOut
Set to true if the font is to be struck through; otherwise, det to false.
charSet
The character set of the font. This value must be one of the enumeration values defined in the wfc.app.CharacterSet class.
orientation
Orientation of the font. This is the angle, in tenths of a degree, between a character's baseline and the x-axis of a device.
Description

Creates a new font.



Syntax 5
public Font( Font font, int size );
Parameters
font
The existing font to use as a template.
size
The size of the new font in logical units.
Description

Creates a new font from an existing one.



Syntax 6
public Font( Font font, int weight, boolean italic, boolean underline, boolean strikeOut );
Parameters
font
The existing font to use as a template.
weight
The weight of the font. This must be one of the enumeration values defined in the FontWeight class.
italic
Set to true if the font is to be italicized; otherwise, set to false.
underline
Set to true if the font is to be underlined; otherwise, set to false.
strikeOut
Set to true if the font is to be struck through; otherwise, set to false.
Description

Creates a new font from an existing one.



Syntax 7
public Font( Font font, int size, int weight, boolean italic, boolean underline, boolean strikeOut );
Parameters
font
The existing font you want to use as a template.
size
The size of the new font in logical units.
weight
The weight of the font. This must be one of the enumeration values defined in the FontWeight class.
italic
Set to true if the font is to be underlined; otherwise, set to false.
underline
Set to true if the font is to be underlined; otherwise, set to false.
strikeOut
Set to true if the font is to be struck through; otherwise, set to false.
Description

Creates a new font from an existing one.



Syntax 8
public Font( int family, int pitch, int size );
Parameters
family
The family of the font you want to create. This value must be one of the enumeration values defined in the FontFamily class.
pitch
The pitch of the font you want to create. This value must be one of the enumeration values defined in the FontPitch class.
size
The size of the font in logical units.
Description

Creates a new font based on a specified font family, pitch and size. Usually, you use this method if you do not know the name of the font you want to create.



Syntax 9
public Font( int family, int pitch, int size, int weight, boolean italic, boolean underline, boolean strikeOut );
Parameters
family
The family of the font you want to create. This must be one of the enumeration values defined in the FontFamily class.
pitch
The pitch of the font you want to create. This must be one of the enumeration values defined in the FontPitch class.
size
The size of the font in logical units.
weight
The weight of the font. This must be one of the enumeration values defined in the FontWeight class.
italic
Set to true if the font is to be underlined; otherwise, set to false.
underline
Set to true if the font is to be underlined; otherwise, set to false.
strikeOut
Set to true if the font is to be struck through; otherwise, set to false.
Description

Creates a new font based on a specified font face, size, and style. Usually, you use this method if you do not know the name of the font you want to create.



Syntax 10
public Font( int family, int pitch, int size, int weight, boolean italic, boolean underline, boolean strikeOut, int charSet, int orientation );
Parameters
family
The family of the font you want to create.
pitch
The pitch of the font you want to create.
size
The size of the font in logical units.
weight
The weight of the font. This value must be one of the enumeration values defined in the FontWeight class.
italic
Set to true if the font is to be italicized; otherwise, set to false.
underline
Set to true if the font is to be underlined; otherwise, set to false.
strikeOut
Set to true if the font is to be struck through; otherwise, set to false.
charSet
The character set of the font. This must be one of the enumeration values defined in the wfc.app.CharacterSet class.
orientation
Orientation of the font. This is the angle, in tenths of a degree, between a character's baseline and the x-axis of a device.
Description

Creates a new font, based on the specified family, pitch, size, and weight. Usually, you use this method when you do not know the name of the font you want to create.



Syntax 11
public Font( IDataStream stream );
Parameters
stream
The IDataStream from which to read the font.
Description

Creates a new font from a specified datastream.

See Also
IDataStream, IPersistable

Methods

Font.equals

Syntax
public boolean equals( Object obj );
Parameters
obj
The object to test.
Return Value

Returns true if the given object equals this object; otherwise, returns false.

Description

Determines if one object equates to another.

Font.equalsBase

Syntax
public boolean equalsBase( Font font );
Parameters
font
The font to test.
Return Value

Returns true if the given font has the same base characteristics as this font; otherwise, returns false.

Description

Determines if one font shares the same base font as another.

Font.finalize

Syntax
protected void finalize() throws Throwable;
Description

Releases all resources allocated by this object.

Exceptions

Throwable Thrown if a problem occurs while freeing the object's resources.

Font.getBold

Syntax
public boolean getBold();
Return Value

Returns true if the font is bold; otherwise, returns false.

Description

Retrieves a boolean value that indicates if the font is bold.

Font.getCharacterSet

Syntax
public int getCharacterSet();
Return Value

Returns a wfc.app.CharacterSet enumeration value.

Description

Retrieves the character set the font is using.

Font.getConstructorArgs

Syntax
public ConstructorArg[] getConstructorArgs();
Return Value

Returns a ConstructorArg array.

Description

Retrieves the ConstructorArgs needed to persist this object.

See Also
ConstructorArg, IConstructable

Font.getExtension

Syntax
public String getExtension();
Return Value

Returns a file name extension to use during object persistence. Because Font objects do not use an extension, this method always returns null.

Description

Retrieves a file name extension with which to save this object's persistance data.

See Also
IPersistable

Font.getFontMetrics

Syntax 1
public FontMetrics getFontMetrics();
Return Value

Returns a FontMetrics object with the physical characteristics of the font.

Description

Retrieves a FontMetrics object for this font. While a Font object maintains the requested characteristics of a font, a FontMetrics contains information about the actual font as it will be rendered to a Graphics object. This information may or may not match the requested characteristics, depending on what font information is available. This function assumes a default Graphics object of the screen.



Syntax 2
public FontMetrics getFontMetrics( Graphics gr );
Parameters
gr
The Graphics object to which to map the font.
Return Value

Returns a FontMetrics object that describes the physical characteristics of the font.

Description

Retrieves a FontMetrics object for this font. While a Font object maintains the requested characteristics of a font, a FontMetrics object contains information about the font as it will be rendered to a Graphics object. This information may or may not match the requested Font object characteristics, depending on font information that is available.

Font.getHandle

Syntax
public int getHandle();
Return Value

Returns a Win32 handle to the font.

Description

Retrieves the Win32 HFONT handle.

Font.getItalic

Syntax
public boolean getItalic();
Return Value

Returns true if the font is italicized; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether the font is italicized.

Font.getLogicalUnits

Syntax 1
public static final int getLogicalUnits( float points );
Parameters
points
The point size to convert.
Return Value

Returns the number of logical units.

Description

Converts a font's Point value to a logical unit. A font's logical units are independent of a given Graphics object's resolution. Points, on the other hand, are dependent on the resolution of the target object.



Syntax 2
public static final int getLogicalUnits( float points, Graphics gr );
Parameters
points
The point size to convert.
gr
The Graphics object on which to base the conversion.
Return Value

Returns the number of logical units.

Description

Converts a font's Point value to a logical unit. A font's logical units are independent of a given Graphics object's resolution. Points, on the other hand, are dependent on the resolution of the target object.

Font.getName

Syntax
public String getName();
Return Value

Returns the font's face name.

Description

Retrieves the face name of the font, and returns the name in a String object.

Font.getOrientation

Syntax
public int getOrientation();
Return Value

Returns the orientation of the font.

Description

Rerieves the orientation of the font, in tenths of a degree, from the x-axis of the device.

Font.getPoints

Syntax 1
public static final float getPoints( int units );
Parameters
units
The logical unit number to convert to points.
Return Value

Returns the number of points in the logical unit.

Description

Converts a font's logical unit to a point. Logical units are independent of a Graphics object's resolution. Points, on the other hand, depend on the resolution of the target object.



Syntax 2
public static final float getPoints( int units, Graphics gr );
Parameters
units
The logical unit number to convert to points.
gr
The Graphics object on which to base the conversion.
Return Value

Returns the number of points in the logical unit.

Description

Converts a font's logical unit to a point. Logical units are independent of a Graphics object's resolution. Points, on the other hand, depend on the resolution of the target object.

Font.getSize

Syntax
public int getSize();
Return Value

Returns the font size in logical units.

Description

Retrieves the size of the font in logical units. Windows defines a positive font size as the cell height of the font, which is usually the distance from the bottom of a "g" to the top of an "M". Windows defines a negative font size as the character height of the font, which is typically the height of an "M".

Font.getStock

Syntax
public static Font getStock( int index );
Parameters
index
The stock font index as defined in wfc.win32.Windows.
Return Value

Returns the stock font that corresponds to the specified index.

Description

Retrieves a stock font, based on a specified index.

Font.getStrikeout

Syntax
public boolean getStrikeout();
Return Value

Returns true if the font is a strike-through font; otherwise, returns false.

Description

Retrieves a boolean value that indicates whether the current font is a strike-through font.

Font.getUnderline

Syntax
public boolean getUnderline();
Return Value

Returns true if the font is underlined; Otherwise, returns false.

Description

Retrieves a boolean value that indicates whether the font is underlined.

Font.getWeight

Syntax
public int getWeight();
Return Value

Returns one of the enumeration values defined in the FontWeight class.

Description

Retrieves the weight associated with this font.

See Also
FontWeight

Font.hashCode

Syntax
public int hashCode();
Return Value

Returns a hash code value for this font.

Description

Retrieves a hash code value for this font.

Font.save

Syntax
public void save( IDataStream stream );
Parameters
stream
The stream to which to persist the font information.
Description

Persists this font to the given datastream.

See Also
IPersistable