< prev index next >
src/java.desktop/share/classes/java/awt/font/FontRenderContext.java
Print this page
*** 32,42 ****
import java.awt.RenderingHints;
import static java.awt.RenderingHints.*;
import java.awt.geom.AffineTransform;
/**
! * The <code>FontRenderContext</code> 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.
* <p>
* One such piece of information is a transform that scales
--- 32,42 ----
import java.awt.RenderingHints;
import static java.awt.RenderingHints.*;
import java.awt.geom.AffineTransform;
/**
! * The {@code 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.
* <p>
* One such piece of information is a transform that scales
*** 50,62 ****
* <p>
* Anti-aliasing and Fractional-metrics specified by an application can also
* affect the size of a character because of rounding to pixel
* boundaries.
* <p>
! * Typically, instances of <code>FontRenderContext</code> are
* obtained from a {@link java.awt.Graphics2D Graphics2D} object. A
! * <code>FontRenderContext</code> 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()
--- 50,62 ----
* <p>
* Anti-aliasing and Fractional-metrics specified by an application can also
* affect the size of a character because of rounding to pixel
* boundaries.
* <p>
! * Typically, instances of {@code FontRenderContext} are
* obtained from a {@link java.awt.Graphics2D Graphics2D} object. A
! * {@code 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()
*** 68,101 ****
private transient Object aaHintValue;
private transient Object fmHintValue;
private transient boolean defaulting;
/**
! * Constructs a new <code>FontRenderContext</code>
* object.
*
*/
protected FontRenderContext() {
aaHintValue = VALUE_TEXT_ANTIALIAS_DEFAULT;
fmHintValue = VALUE_FRACTIONALMETRICS_DEFAULT;
defaulting = true;
}
/**
! * Constructs a <code>FontRenderContext</code> object from an
! * optional {@link AffineTransform} and two <code>boolean</code>
* values that determine if the newly constructed object has
* anti-aliasing or fractional metrics.
! * In each case the boolean values <CODE>true</CODE> and <CODE>false</CODE>
! * correspond to the rendering hint values <CODE>ON</CODE> and
! * <CODE>OFF</CODE> respectively.
* <p>
* To specify other hint values, use the constructor which
* specifies the rendering hint values as parameters :
* {@link #FontRenderContext(AffineTransform, Object, Object)}.
* @param tx the transform which is used to scale typographical points
! * to pixels in this <code>FontRenderContext</code>. If null, an
* identity transform is used.
* @param isAntiAliased determines if the newly constructed object
* has anti-aliasing.
* @param usesFractionalMetrics determines if the newly constructed
* object has fractional metrics.
--- 68,101 ----
private transient Object aaHintValue;
private transient Object fmHintValue;
private transient boolean defaulting;
/**
! * Constructs a new {@code FontRenderContext}
* object.
*
*/
protected FontRenderContext() {
aaHintValue = VALUE_TEXT_ANTIALIAS_DEFAULT;
fmHintValue = VALUE_FRACTIONALMETRICS_DEFAULT;
defaulting = true;
}
/**
! * Constructs a {@code FontRenderContext} object from an
! * optional {@link AffineTransform} and two {@code boolean}
* values that determine if the newly constructed object has
* anti-aliasing or fractional metrics.
! * In each case the boolean values {@code true} and {@code false}
! * correspond to the rendering hint values {@code ON} and
! * {@code OFF} respectively.
* <p>
* To specify other hint values, use the constructor which
* specifies the rendering hint values as parameters :
* {@link #FontRenderContext(AffineTransform, Object, Object)}.
* @param tx the transform which is used to scale typographical points
! * to pixels in this {@code FontRenderContext}. If null, an
* identity transform is used.
* @param isAntiAliased determines if the newly constructed object
* has anti-aliasing.
* @param usesFractionalMetrics determines if the newly constructed
* object has fractional metrics.
*** 117,145 ****
fmHintValue = VALUE_FRACTIONALMETRICS_OFF;
}
}
/**
! * Constructs a <code>FontRenderContext</code> object from an
! * optional {@link AffineTransform} and two <code>Object</code>
* 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 <code>FontRenderContext</code>. If null, an
* identity transform is used.
* @param aaHint - one of the text antialiasing rendering hint values
* defined in {@link java.awt.RenderingHints java.awt.RenderingHints}.
! * Any other value will throw <code>IllegalArgumentException</code>.
* {@link java.awt.RenderingHints#VALUE_TEXT_ANTIALIAS_DEFAULT VALUE_TEXT_ANTIALIAS_DEFAULT}
* may be specified, in which case the mode used is implementation
* dependent.
* @param fmHint - one of the text fractional rendering hint values defined
* in {@link java.awt.RenderingHints java.awt.RenderingHints}.
* {@link java.awt.RenderingHints#VALUE_FRACTIONALMETRICS_DEFAULT VALUE_FRACTIONALMETRICS_DEFAULT}
* may be specified, in which case the mode used is implementation
* dependent.
! * Any other value will throw <code>IllegalArgumentException</code>
* @throws IllegalArgumentException if the hints are not one of the
* legal values.
* @since 1.6
*/
public FontRenderContext(AffineTransform tx, Object aaHint, Object fmHint){
--- 117,145 ----
fmHintValue = VALUE_FRACTIONALMETRICS_OFF;
}
}
/**
! * Constructs a {@code FontRenderContext} object from an
! * optional {@link AffineTransform} and two {@code Object}
* 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 {@code FontRenderContext}. If null, an
* identity transform is used.
* @param aaHint - one of the text antialiasing rendering hint values
* defined in {@link java.awt.RenderingHints java.awt.RenderingHints}.
! * Any other value will throw {@code IllegalArgumentException}.
* {@link java.awt.RenderingHints#VALUE_TEXT_ANTIALIAS_DEFAULT VALUE_TEXT_ANTIALIAS_DEFAULT}
* may be specified, in which case the mode used is implementation
* dependent.
* @param fmHint - one of the text fractional rendering hint values defined
* in {@link java.awt.RenderingHints java.awt.RenderingHints}.
* {@link java.awt.RenderingHints#VALUE_FRACTIONALMETRICS_DEFAULT VALUE_FRACTIONALMETRICS_DEFAULT}
* may be specified, in which case the mode used is implementation
* dependent.
! * Any other value will throw {@code IllegalArgumentException}
* @throws IllegalArgumentException if the hints are not one of the
* legal values.
* @since 1.6
*/
public FontRenderContext(AffineTransform tx, Object aaHint, Object fmHint){
*** 165,179 ****
throw new IllegalArgumentException("FM hint:" +fmHint);
}
}
/**
! * Indicates whether or not this <code>FontRenderContext</code> object
* measures text in a transformed render context.
! * @return <code>true</code> if this <code>FontRenderContext</code>
* object has a non-identity AffineTransform attribute.
! * <code>false</code> otherwise.
* @see java.awt.font.FontRenderContext#getTransform
* @since 1.6
*/
public boolean isTransformed() {
if (!defaulting) {
--- 165,179 ----
throw new IllegalArgumentException("FM hint:" +fmHint);
}
}
/**
! * Indicates whether or not this {@code FontRenderContext} object
* measures text in a transformed render context.
! * @return {@code true} if this {@code FontRenderContext}
* object has a non-identity AffineTransform attribute.
! * {@code false} otherwise.
* @see java.awt.font.FontRenderContext#getTransform
* @since 1.6
*/
public boolean isTransformed() {
if (!defaulting) {
*** 183,193 ****
}
}
/**
* Returns the integer type of the affine transform for this
! * <code>FontRenderContext</code> as specified by
* {@link java.awt.geom.AffineTransform#getType()}
* @return the type of the transform.
* @see AffineTransform
* @since 1.6
*/
--- 183,193 ----
}
}
/**
* Returns the integer type of the affine transform for this
! * {@code FontRenderContext} as specified by
* {@link java.awt.geom.AffineTransform#getType()}
* @return the type of the transform.
* @see AffineTransform
* @since 1.6
*/
*** 203,228 ****
}
}
/**
* Gets the transform that is used to scale typographical points
! * to pixels in this <code>FontRenderContext</code>.
! * @return the <code>AffineTransform</code> of this
! * <code>FontRenderContext</code>.
* @see AffineTransform
*/
public AffineTransform getTransform() {
return (tx == null) ? new AffineTransform() : new AffineTransform(tx);
}
/**
* Returns a boolean which indicates whether or not some form of
! * antialiasing is specified by this <code>FontRenderContext</code>.
* Call {@link #getAntiAliasingHint() getAntiAliasingHint()}
* for the specific rendering hint value.
! * @return <code>true</code>, if text is anti-aliased in this
! * <code>FontRenderContext</code>; <code>false</code> otherwise.
* @see java.awt.RenderingHints#KEY_TEXT_ANTIALIASING
* @see #FontRenderContext(AffineTransform,boolean,boolean)
* @see #FontRenderContext(AffineTransform,Object,Object)
*/
public boolean isAntiAliased() {
--- 203,228 ----
}
}
/**
* Gets the transform that is used to scale typographical points
! * to pixels in this {@code FontRenderContext}.
! * @return the {@code AffineTransform} of this
! * {@code FontRenderContext}.
* @see AffineTransform
*/
public AffineTransform getTransform() {
return (tx == null) ? new AffineTransform() : new AffineTransform(tx);
}
/**
* Returns a boolean which indicates whether or not some form of
! * antialiasing is specified by this {@code FontRenderContext}.
* Call {@link #getAntiAliasingHint() getAntiAliasingHint()}
* for the specific rendering hint value.
! * @return {@code true}, if text is anti-aliased in this
! * {@code FontRenderContext}; {@code false} otherwise.
* @see java.awt.RenderingHints#KEY_TEXT_ANTIALIASING
* @see #FontRenderContext(AffineTransform,boolean,boolean)
* @see #FontRenderContext(AffineTransform,Object,Object)
*/
public boolean isAntiAliased() {
*** 230,245 ****
aaHintValue == VALUE_TEXT_ANTIALIAS_DEFAULT);
}
/**
* Returns a boolean which whether text fractional metrics mode
! * is used in this <code>FontRenderContext</code>.
* Call {@link #getFractionalMetricsHint() getFractionalMetricsHint()}
* to obtain the corresponding rendering hint value.
! * @return <code>true</code>, if layout should be performed with
! * fractional metrics; <code>false</code> otherwise.
! * in this <code>FontRenderContext</code>.
* @see java.awt.RenderingHints#KEY_FRACTIONALMETRICS
* @see #FontRenderContext(AffineTransform,boolean,boolean)
* @see #FontRenderContext(AffineTransform,Object,Object)
*/
public boolean usesFractionalMetrics() {
--- 230,245 ----
aaHintValue == VALUE_TEXT_ANTIALIAS_DEFAULT);
}
/**
* Returns a boolean which whether text fractional metrics mode
! * is used in this {@code FontRenderContext}.
* Call {@link #getFractionalMetricsHint() getFractionalMetricsHint()}
* to obtain the corresponding rendering hint value.
! * @return {@code true}, if layout should be performed with
! * fractional metrics; {@code false} otherwise.
! * in this {@code FontRenderContext}.
* @see java.awt.RenderingHints#KEY_FRACTIONALMETRICS
* @see #FontRenderContext(AffineTransform,boolean,boolean)
* @see #FontRenderContext(AffineTransform,Object,Object)
*/
public boolean usesFractionalMetrics() {
*** 247,261 ****
fmHintValue == VALUE_FRACTIONALMETRICS_DEFAULT);
}
/**
* Return the text anti-aliasing rendering mode hint used in this
! * <code>FontRenderContext</code>.
* This will be one of the text antialiasing rendering hint values
* defined in {@link java.awt.RenderingHints java.awt.RenderingHints}.
* @return text anti-aliasing rendering mode hint used in this
! * <code>FontRenderContext</code>.
* @since 1.6
*/
public Object getAntiAliasingHint() {
if (defaulting) {
if (isAntiAliased()) {
--- 247,261 ----
fmHintValue == VALUE_FRACTIONALMETRICS_DEFAULT);
}
/**
* Return the text anti-aliasing rendering mode hint used in this
! * {@code FontRenderContext}.
* This will be one of the text antialiasing rendering hint values
* defined in {@link java.awt.RenderingHints java.awt.RenderingHints}.
* @return text anti-aliasing rendering mode hint used in this
! * {@code FontRenderContext}.
* @since 1.6
*/
public Object getAntiAliasingHint() {
if (defaulting) {
if (isAntiAliased()) {
*** 267,281 ****
return aaHintValue;
}
/**
* Return the text fractional metrics rendering mode hint used in this
! * <code>FontRenderContext</code>.
* This will be one of the text fractional metrics rendering hint values
* defined in {@link java.awt.RenderingHints java.awt.RenderingHints}.
* @return the text fractional metrics rendering mode hint used in this
! * <code>FontRenderContext</code>.
* @since 1.6
*/
public Object getFractionalMetricsHint() {
if (defaulting) {
if (usesFractionalMetrics()) {
--- 267,281 ----
return aaHintValue;
}
/**
* Return the text fractional metrics rendering mode hint used in this
! * {@code FontRenderContext}.
* This will be one of the text fractional metrics rendering hint values
* defined in {@link java.awt.RenderingHints java.awt.RenderingHints}.
* @return the text fractional metrics rendering mode hint used in this
! * {@code FontRenderContext}.
* @since 1.6
*/
public Object getFractionalMetricsHint() {
if (defaulting) {
if (usesFractionalMetrics()) {
*** 289,300 ****
/**
* 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 <code>true</code> if the specified object is equal to
! * this <code>FontRenderContext</code>; <code>false</code>
* otherwise.
*/
public boolean equals(Object obj) {
try {
return equals((FontRenderContext)obj);
--- 289,300 ----
/**
* 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 {@code true} if the specified object is equal to
! * this {@code FontRenderContext}; {@code false}
* otherwise.
*/
public boolean equals(Object obj) {
try {
return equals((FontRenderContext)obj);
*** 305,317 ****
}
/**
* Return true if rhs has the same transform, antialiasing,
* and fractional metrics values as this.
! * @param rhs the <code>FontRenderContext</code> to test for equality
! * @return <code>true</code> if <code>rhs</code> is equal to
! * this <code>FontRenderContext</code>; <code>false</code>
* otherwise.
* @since 1.4
*/
public boolean equals(FontRenderContext rhs) {
if (this == rhs) {
--- 305,317 ----
}
/**
* Return true if rhs has the same transform, antialiasing,
* and fractional metrics values as this.
! * @param rhs the {@code FontRenderContext} to test for equality
! * @return {@code true} if {@code rhs} is equal to
! * this {@code FontRenderContext}; {@code false}
* otherwise.
* @since 1.4
*/
public boolean equals(FontRenderContext rhs) {
if (this == rhs) {
< prev index next >