FileDocCategorySizeDatePackage
FontRenderContext.javaAPI DocJava SE 5 API5859Fri Aug 26 14:56:50 BST 2005java.awt.font

FontRenderContext

public class FontRenderContext extends Object
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 {@link java.awt.Graphics2D 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
java.awt.RenderingHints#KEY_TEXT_ANTIALIASING
see
java.awt.RenderingHints#KEY_FRACTIONALMETRICS
see
java.awt.Graphics2D#getFontRenderContext()
see
java.awt.font.LineMetrics

Fields Summary
private transient AffineTransform
tx
private transient boolean
bIsAntiAliased
private transient boolean
bUsesFractionalMetrics
Constructors Summary
protected FontRenderContext()
Constructs a new FontRenderContext object.

    
public FontRenderContext(AffineTransform tx, boolean isAntiAliased, boolean usesFractionalMetrics)
Constructs a FontRenderContext object from an optional {@link AffineTransform} and two boolean values that determine if the newly constructed object has anti-aliasing or fractional metrics.

param
tx the transform which is used to scale typographical points to pixels in this FontRenderContext. If null, an identity tranform is used.
param
isAntiAliased determines if the newly contructed object has anti-aliasing
param
usesFractionalMetrics determines if the newly constructed object uses fractional metrics

        if (tx != null && !tx.isIdentity()) {
            this.tx = new AffineTransform(tx);
        }
        this.bIsAntiAliased = isAntiAliased;
        this.bUsesFractionalMetrics = usesFractionalMetrics;
    
Methods Summary
public booleanequals(java.lang.Object obj)
Return true if obj is an instance of FontRenderContext and has the same transform, antialiasing, and fractional metrics values as this.

param
obj the object to test for equality
return
true if the specified object is equal to this FontRenderContext; false otherwise.

	try {
	    return equals((FontRenderContext)obj);
	}
	catch (ClassCastException e) {
	    return false;
	}
    
public booleanequals(java.awt.font.FontRenderContext rhs)
Return true if rhs has the same transform, antialiasing, and fractional metrics values as this.

param
rhs the FontRenderContext to test for equality
return
true if rhs is equal to this FontRenderContext; false otherwise.

	if (this == rhs) {
	    return true;
	}
	if (rhs != null &&
	    rhs.bIsAntiAliased == bIsAntiAliased &&
	    rhs.bUsesFractionalMetrics == bUsesFractionalMetrics) {
	    
	    return tx == null ? rhs.tx == null : tx.equals(rhs.tx);
	}
	return false;
    
public java.awt.geom.AffineTransformgetTransform()
Gets the transform that is used to scale typographical points to pixels in this FontRenderContext.

return
the AffineTransform of this FontRenderContext.
see
AffineTransform

        return (tx == null) ? new AffineTransform() : new AffineTransform(tx);
    
public inthashCode()
Return a hashcode for this FontRenderContext.

	int hash = tx == null ? 0 : tx.hashCode();
	if (bIsAntiAliased) {
	    hash ^= 0x1;
	}
	if (bUsesFractionalMetrics) {
	    hash ^= 0x2;
	}
	return hash;
    
public booleanisAntiAliased()
Gets the text anti-aliasing mode used in this FontRenderContext.

return
true, if text is anti-aliased in this FontRenderContext; false otherwise.
see
java.awt.RenderingHints#KEY_TEXT_ANTIALIASING

        return this.bIsAntiAliased;
    
public booleanusesFractionalMetrics()
Gets the text fractional metrics mode requested by the application for use in this FontRenderContext.

return
true, if layout should be performed with fractional metrics; false otherwise. in this FontRenderContext.
see
java.awt.RenderingHints#KEY_FRACTIONALMETRICS

        return this.bUsesFractionalMetrics;