Class FontRenderContext
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:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConstructs a newFontRenderContextobject.FontRenderContext(AffineTransform tx, boolean isAntiAliased, boolean usesFractionalMetrics) Constructs aFontRenderContextobject from an optionalAffineTransformand twobooleanvalues that determine if the newly constructed object has anti-aliasing or fractional metrics.FontRenderContext(AffineTransform tx, Object aaHint, Object fmHint) Constructs aFontRenderContextobject from an optionalAffineTransformand twoObjectvalues that determine if the newly constructed object has anti-aliasing or fractional metrics. -
Method Summary
Modifier and TypeMethodDescriptionbooleanequals(FontRenderContext rhs) Return true if rhs has the same transform, antialiasing, and fractional metrics values as this.booleanReturn true if obj is an instance of FontRenderContext and has the same transform, antialiasing, and fractional metrics values as this.Return the text anti-aliasing rendering mode hint used in thisFontRenderContext.Return the text fractional metrics rendering mode hint used in thisFontRenderContext.Gets the transform that is used to scale typographical points to pixels in thisFontRenderContext.intReturns the integer type of the affine transform for thisFontRenderContextas specified byAffineTransform.getType()inthashCode()Return a hashcode for this FontRenderContext.booleanReturns a boolean which indicates whether or not some form of antialiasing is specified by thisFontRenderContext.booleanIndicates whether or not thisFontRenderContextobject measures text in a transformed render context.booleanReturns a boolean which whether text fractional metrics mode is used in thisFontRenderContext.
-
Constructor Details
-
FontRenderContext
protected FontRenderContext()Constructs a newFontRenderContextobject. -
FontRenderContext
Constructs aFontRenderContextobject from an optionalAffineTransformand twobooleanvalues that determine if the newly constructed object has anti-aliasing or fractional metrics. In each case the boolean valuestrueandfalsecorrespond to the rendering hint valuesONandOFFrespectively.To specify other hint values, use the constructor which specifies the rendering hint values as parameters :
FontRenderContext(AffineTransform, Object, Object).- Parameters:
tx- the transform which is used to scale typographical points to pixels in thisFontRenderContext. If null, an identity transform is used.isAntiAliased- determines if the newly constructed object has anti-aliasing.usesFractionalMetrics- determines if the newly constructed object has fractional metrics.
-
FontRenderContext
Constructs aFontRenderContextobject from an optionalAffineTransformand twoObjectvalues that determine if the newly constructed object has anti-aliasing or fractional metrics.- Parameters:
tx- the transform which is used to scale typographical points to pixels in thisFontRenderContext. If null, an identity transform is used.aaHint- one of the text antialiasing rendering hint values defined injava.awt.RenderingHints. Any other value will throwIllegalArgumentException.VALUE_TEXT_ANTIALIAS_DEFAULTmay be specified, in which case the mode used is implementation dependent.fmHint- one of the text fractional rendering hint values defined injava.awt.RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULTmay be specified, in which case the mode used is implementation dependent. Any other value will throwIllegalArgumentException- Throws:
IllegalArgumentException- if the hints are not one of the legal values.- Since:
- 1.6
-
-
Method Details
-
isTransformed
public boolean isTransformed()Indicates whether or not thisFontRenderContextobject measures text in a transformed render context.- Returns:
trueif thisFontRenderContextobject has a non-identity AffineTransform attribute.falseotherwise.- Since:
- 1.6
- See Also:
-
getTransformType
public int getTransformType()Returns the integer type of the affine transform for thisFontRenderContextas specified byAffineTransform.getType()- Returns:
- the type of the transform.
- Since:
- 1.6
- See Also:
-
getTransform
Gets the transform that is used to scale typographical points to pixels in thisFontRenderContext.- Returns:
- the
AffineTransformof thisFontRenderContext. - See Also:
-
isAntiAliased
public boolean isAntiAliased()Returns a boolean which indicates whether or not some form of antialiasing is specified by thisFontRenderContext. CallgetAntiAliasingHint()for the specific rendering hint value.- Returns:
true, if text is anti-aliased in thisFontRenderContext;falseotherwise.- See Also:
-
usesFractionalMetrics
public boolean usesFractionalMetrics()Returns a boolean which whether text fractional metrics mode is used in thisFontRenderContext. CallgetFractionalMetricsHint()to obtain the corresponding rendering hint value.- Returns:
true, if layout should be performed with fractional metrics;falseotherwise. in thisFontRenderContext.- See Also:
-
getAntiAliasingHint
Return the text anti-aliasing rendering mode hint used in thisFontRenderContext. This will be one of the text antialiasing rendering hint values defined injava.awt.RenderingHints.- Returns:
- text anti-aliasing rendering mode hint used in this
FontRenderContext. - Since:
- 1.6
-
getFractionalMetricsHint
Return the text fractional metrics rendering mode hint used in thisFontRenderContext. This will be one of the text fractional metrics rendering hint values defined injava.awt.RenderingHints.- Returns:
- the text fractional metrics rendering mode hint used in this
FontRenderContext. - Since:
- 1.6
-
equals
Return true if obj is an instance of FontRenderContext and has the same transform, antialiasing, and fractional metrics values as this. -
equals
Return true if rhs has the same transform, antialiasing, and fractional metrics values as this.- Parameters:
rhs- theFontRenderContextto test for equality- Returns:
trueifrhsis equal to thisFontRenderContext;falseotherwise.- Since:
- 1.4
-
hashCode
-