APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.font

public Class FontRenderContext

extends Object
Class Inheritance
Imports
java.awt.RenderingHints, java.awt.geom.AffineTransform

The FontRenderContext class is a container for the information needed to correctly measure text. The measurement of text can vary because of rules that map outlines to pixels, and rendering hints provided by an application.

One such piece of information is a transform that scales typographical points to pixels. (A point is defined to be exactly 1/72 of an inch, which is slightly different than the traditional mechanical measurement of a point.) A character that is rendered at 12pt on a 600dpi device might have a different size than the same character rendered at 12pt on a 72dpi device because of such factors as rounding to pixel boundaries and hints that the font designer may have specified.

Anti-aliasing and Fractional-metrics specified by an application can also affect the size of a character because of rounding to pixel boundaries.

Typically, instances of FontRenderContext are obtained from a Graphics2D object. A FontRenderContext which is directly constructed will most likely not represent any actual graphics device, and may lead to unexpected or incorrect results.

See Also
java.awt.RenderingHints#KEY_TEXT_ANTIALIASING, java.awt.RenderingHints#KEY_FRACTIONALMETRICS, java.awt.Graphics2D#getFontRenderContext(), java.awt.font.LineMetrics

Field Summary

Modifier and TypeField and Description
private final transient Object
private final transient boolean
private final transient Object
private final transient AffineTransform

Constructor Summary

AccessConstructor and Description
protected
FontRenderContext()

Constructs a new FontRenderContext object.

public
FontRenderContext(AffineTransform
the transform which is used to scale typographical points to pixels in this FontRenderContext. If null, an identity transform is used.
tx
,
boolean
determines if the newly constructed object has anti-aliasing.
isAntiAliased
,
boolean
determines if the newly constructed object has fractional metrics.
usesFractionalMetrics
)

Constructs a FontRenderContext object from an optional AffineTransform and two boolean values that determine if the newly constructed object has anti-aliasing or fractional metrics.

public
FontRenderContext(AffineTransform
the transform which is used to scale typographical points to pixels in this FontRenderContext. If null, an identity transform is used.
tx
,
Object
one of the text antialiasing rendering hint values defined in java.awt.RenderingHints. Any other value will throw IllegalArgumentException. VALUE_TEXT_ANTIALIAS_DEFAULT may be specified, in which case the mode used is implementation dependent.
aaHint
,
Object
one of the text fractional rendering hint values defined in java.awt.RenderingHints. VALUE_FRACTIONALMETRICS_DEFAULT may be specified, in which case the mode used is implementation dependent. Any other value will throw IllegalArgumentException
fmHint
)

Constructs a FontRenderContext object from an optional AffineTransform and two Object values that determine if the newly constructed object has anti-aliasing or fractional metrics.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the specified object is equal to this FontRenderContext; false otherwise.
equals
(Object
the object to test for equality
obj
)

Overrides java.lang.Object.equals.

Return true if obj is an instance of FontRenderContext and has the same transform, antialiasing, and fractional metrics values as this.

public boolean

Returns:

true if rhs is equal to this FontRenderContext; false otherwise.
equals
(FontRenderContext
the FontRenderContext to test for equality
rhs
)

Return true if rhs has the same transform, antialiasing, and fractional metrics values as this.

public Object

Returns:

text anti-aliasing rendering mode hint used in this FontRenderContext.
getAntiAliasingHint
()

Return the text anti-aliasing rendering mode hint used in this FontRenderContext.

public Object

Returns:

the text fractional metrics rendering mode hint used in this FontRenderContext.
getFractionalMetricsHint
()

Return the text fractional metrics rendering mode hint used in this FontRenderContext.

public AffineTransform

Returns:

the AffineTransform of this FontRenderContext.
getTransform
()

Gets the transform that is used to scale typographical points to pixels in this FontRenderContext.

public int

Returns:

the type of the transform.
getTransformType
()

Returns the integer type of the affine transform for this FontRenderContext as specified by java.awt.geom.AffineTransform#getType()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Return a hashcode for this FontRenderContext.

public boolean

Returns:

true, if text is anti-aliased in this FontRenderContext; false otherwise.
isAntiAliased
()

Returns a boolean which indicates whether or not some form of antialiasing is specified by this FontRenderContext.

public boolean

Returns:

true if this FontRenderContext object has a non-identity AffineTransform attribute. false otherwise.
isTransformed
()

Indicates whether or not this FontRenderContext object measures text in a transformed render context.

public boolean

Returns:

true, if layout should be performed with fractional metrics; false otherwise. in this FontRenderContext.
usesFractionalMetrics
()

Returns a boolean which whether text fractional metrics mode is used in this FontRenderContext.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

aaHintValueback to summary
private final transient Object aaHintValue
defaultingback to summary
private final transient boolean defaulting
fmHintValueback to summary
private final transient Object fmHintValue
txback to summary
private final transient AffineTransform tx

Constructor Detail

FontRenderContextback to summary
protected FontRenderContext()

Constructs a new FontRenderContext object.

FontRenderContextback to summary
public FontRenderContext(AffineTransform tx, boolean isAntiAliased, boolean usesFractionalMetrics)

Constructs a FontRenderContext object from an optional AffineTransform and two boolean values that determine if the newly constructed object has anti-aliasing or fractional metrics. In each case the boolean values true and false correspond to the rendering hint values ON and OFF respectively.

To specify other hint values, use the constructor which specifies the rendering hint values as parameters : FontRenderContext(AffineTransform, Object, Object).

Parameters
tx:AffineTransform

the transform which is used to scale typographical points to pixels in this FontRenderContext. If null, an identity transform is used.

isAntiAliased:boolean

determines if the newly constructed object has anti-aliasing.

usesFractionalMetrics:boolean

determines if the newly constructed object has fractional metrics.

FontRenderContextback to summary
public FontRenderContext(AffineTransform tx, Object aaHint, Object fmHint)

Constructs a FontRenderContext object from an optional AffineTransform and two Object values that determine if the newly constructed object has anti-aliasing or fractional metrics.

Parameters
tx:AffineTransform

the transform which is used to scale typographical points to pixels in this FontRenderContext. If null, an identity transform is used.

aaHint:Object

one of the text antialiasing rendering hint values defined in java.awt.RenderingHints. Any other value will throw IllegalArgumentException. VALUE_TEXT_ANTIALIAS_DEFAULT may be specified, in which case the mode used is implementation dependent.

fmHint:Object

one of the text fractional rendering hint values defined in java.awt.RenderingHints. VALUE_FRACTIONALMETRICS_DEFAULT may be specified, in which case the mode used is implementation dependent. Any other value will throw IllegalArgumentException

Exceptions
IllegalArgumentException:
if the hints are not one of the legal values.
Since
1.6

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Return true if obj is an instance of FontRenderContext and has the same transform, antialiasing, and fractional metrics values as this.

Parameters
obj:Object

the object to test for equality

Returns:boolean

true if the specified object is equal to this FontRenderContext; false otherwise.

equalsback to summary
public boolean equals(FontRenderContext rhs)

Return true if rhs has the same transform, antialiasing, and fractional metrics values as this.

Parameters
rhs:FontRenderContext

the FontRenderContext to test for equality

Returns:boolean

true if rhs is equal to this FontRenderContext; false otherwise.

Since
1.4
getAntiAliasingHintback to summary
public Object getAntiAliasingHint()

Return the text anti-aliasing rendering mode hint used in this FontRenderContext. This will be one of the text antialiasing rendering hint values defined in java.awt.RenderingHints.

Returns:Object

text anti-aliasing rendering mode hint used in this FontRenderContext.

Since
1.6
getFractionalMetricsHintback to summary
public Object getFractionalMetricsHint()

Return the text fractional metrics rendering mode hint used in this FontRenderContext. This will be one of the text fractional metrics rendering hint values defined in java.awt.RenderingHints.

Returns:Object

the text fractional metrics rendering mode hint used in this FontRenderContext.

Since
1.6
getTransformback to summary
public AffineTransform getTransform()

Gets the transform that is used to scale typographical points to pixels in this FontRenderContext.

Returns:AffineTransform

the AffineTransform of this FontRenderContext.

See Also
AffineTransform
getTransformTypeback to summary
public int getTransformType()

Returns the integer type of the affine transform for this FontRenderContext as specified by java.awt.geom.AffineTransform#getType()

Returns:int

the type of the transform.

Since
1.6
See Also
AffineTransform
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Return a hashcode for this FontRenderContext.

isAntiAliasedback to summary
public boolean isAntiAliased()

Returns a boolean which indicates whether or not some form of antialiasing is specified by this FontRenderContext. Call getAntiAliasingHint() for the specific rendering hint value.

Returns:boolean

true, if text is anti-aliased in this FontRenderContext; false otherwise.

See Also
java.awt.RenderingHints#KEY_TEXT_ANTIALIASING, FontRenderContext(AffineTransform, boolean, boolean), FontRenderContext(AffineTransform, Object, Object)
isTransformedback to summary
public boolean isTransformed()

Indicates whether or not this FontRenderContext object measures text in a transformed render context.

Returns:boolean

true if this FontRenderContext object has a non-identity AffineTransform attribute. false otherwise.

Since
1.6
See Also
java.awt.font.FontRenderContext#getTransform
usesFractionalMetricsback to summary
public boolean usesFractionalMetrics()

Returns a boolean which whether text fractional metrics mode is used in this FontRenderContext. Call getFractionalMetricsHint() to obtain the corresponding rendering hint value.

Returns:boolean

true, if layout should be performed with fractional metrics; false otherwise. in this FontRenderContext.

See Also
java.awt.RenderingHints#KEY_FRACTIONALMETRICS, FontRenderContext(AffineTransform, boolean, boolean), FontRenderContext(AffineTransform, Object, Object)