APIdia Launch Partner
Top Inners Fields Constructors Methods
sun.font

public final Class FontDesignMetrics

extends FontMetrics
Class Inheritance
Imports
java.awt.Font, .FontMetrics, .GraphicsEnvironment, java.awt.font.FontRenderContext, .TextLayout, java.awt.geom.AffineTransform, .Rectangle2D, java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .Serial, java.lang.ref.ReferenceQueue, .SoftReference, java.util.concurrent.ConcurrentHashMap, sun.java2d.Disposer, .DisposerRecord

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private transient float[]
private float
private int[]
private static final int
private static FontRenderContext
private float
private transient double[]
private Font
private transient FontStrike
private transient FontRenderContext
private AffineTransform
private transient int
private boolean
private float
private double[]
private float
private static final int
private static final ConcurrentHashMap<Object, FontDesignMetrics.KeyReference>
private static int
private static final FontDesignMetrics[]
private static float
private static final long
serialVersionUID

Hides java.awt.FontMetrics.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.
private int
private static final float
private boolean

Constructor Summary

AccessConstructor and Description
private
private

Method Summary

Modifier and TypeMethod and Description
public int
charsWidth(char[] data, int off, int len)

Overrides java.awt.FontMetrics.charsWidth.

Returns the total advance width for showing the specified array of characters in this Font.

public int
charWidth(char ch)

Overrides java.awt.FontMetrics.charWidth.

Returns the advance width of the specified character in this Font.

public int
charWidth(int ch)

Overrides java.awt.FontMetrics.charWidth.

Returns the advance width of the specified character in this Font.

public int
getAscent()

Overrides java.awt.FontMetrics.getAscent.

Determines the font ascent of the Font described by this FontMetrics object.

private static FontRenderContext
public int
getDescent()

Overrides java.awt.FontMetrics.getDescent.

Determines the font descent of the Font described by this FontMetrics object.

public FontRenderContext
getFontRenderContext()

Overrides java.awt.FontMetrics.getFontRenderContext.

Gets the FontRenderContext used by this FontMetrics object to measure text.

public int
getHeight()

Overrides java.awt.FontMetrics.getHeight.

Gets the standard height of a line of text in this font.

private float
public int
getLeading()

Overrides java.awt.FontMetrics.getLeading.

Determines the standard leading of the Font described by this FontMetrics object.

public int
getMaxAdvance()

Overrides java.awt.FontMetrics.getMaxAdvance.

Returns an estimate of the maximum advance width of any character in the Font described by this FontMetrics object, with important caveats, enumerated below.

public static FontDesignMetrics
public static FontDesignMetrics
public Rectangle2D
getSimpleBounds(char[] data, int off, int len)

This method is called from java.awt.Font only after verifying the arguments and that the text is simple and there are no layout attributes, font transform etc.

public int[]

Returns:

an array storing the advance widths of the characters in the Font described by this FontMetrics object.
getWidths
()

Overrides java.awt.FontMetrics.getWidths.

Gets the advance widths of the first 256 characters in the Font.

private float
private void
private void
private void
public int
stringWidth(String str)

Overrides java.awt.FontMetrics.stringWidth.

Returns the total advance width for showing the specified String in this Font.

private void
Inherited from java.awt.FontMetrics:
bytesWidthgetFontgetLineMetricsgetLineMetricsgetLineMetricsgetLineMetricsgetMaxAscentgetMaxCharBoundsgetMaxDecentgetMaxDescentgetStringBoundsgetStringBoundsgetStringBoundsgetStringBoundshasUniformLineMetricstoString

Field Detail

advCacheback to summary
private transient float[] advCache
ascentback to summary
private float ascent
cacheback to summary
private int[] cache
CURRENT_VERSIONback to summary
private static final int CURRENT_VERSION
DEFAULT_FRCback to summary
private static FontRenderContext DEFAULT_FRC

Hides java.awt.FontMetrics.DEFAULT_FRC.

descentback to summary
private float descent
devmatrixback to summary
private transient double[] devmatrix
fontback to summary
private Font font

Hides java.awt.FontMetrics.font.

fontStrikeback to summary
private transient FontStrike fontStrike
frcback to summary
private transient FontRenderContext frc
frcTxback to summary
private AffineTransform frcTx
heightback to summary
private transient int height
isAntiAliasedback to summary
private boolean isAntiAliased
leadingback to summary
private float leading
matrixback to summary
private double[] matrix
maxAdvanceback to summary
private float maxAdvance
MAXRECENTback to summary
private static final int MAXRECENT
metricsCacheback to summary
private static final ConcurrentHashMap<Object, FontDesignMetrics.KeyReference> metricsCache
recentIndexback to summary
private static int recentIndex
recentMetricsback to summary
private static final FontDesignMetrics[] recentMetrics
roundingUpValueback to summary
private static float roundingUpValue
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.FontMetrics.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Annotations
@Serial
serVersionback to summary
private int serVersion
UNKNOWN_WIDTHback to summary
private static final float UNKNOWN_WIDTH
usesFractionalMetricsback to summary
private boolean usesFractionalMetrics

Constructor Detail

FontDesignMetricsback to summary
private FontDesignMetrics(Font font)
FontDesignMetricsback to summary
private FontDesignMetrics(Font font, FontRenderContext frc)

Method Detail

charsWidthback to summary
public int charsWidth(char[] data, int off, int len)

Overrides java.awt.FontMetrics.charsWidth.

Doc from java.awt.FontMetrics.charsWidth.

Returns the total advance width for showing the specified array of characters in this Font. The advance is the distance from the leftmost point to the rightmost point on the string's baseline. The advance of a String is not necessarily the sum of the advances of its characters. This is equivalent to measuring a String of the characters in the specified range.

charWidthback to summary
public int charWidth(char ch)

Overrides java.awt.FontMetrics.charWidth.

Doc from java.awt.FontMetrics.charWidth.

Returns the advance width of the specified character in this Font. The advance is the distance from the leftmost point to the rightmost point on the character's baseline. Note that the advance of a String is not necessarily the sum of the advances of its characters.

Note

This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the charWidth(int) method.

charWidthback to summary
public int charWidth(int ch)

Overrides java.awt.FontMetrics.charWidth.

Doc from java.awt.FontMetrics.charWidth.

Returns the advance width of the specified character in this Font. The advance is the distance from the leftmost point to the rightmost point on the character's baseline. Note that the advance of a String is not necessarily the sum of the advances of its characters.

This method doesn't validate the specified character to be a valid Unicode code point. The caller must validate the character value using Character.isValidCodePoint if necessary.

getAscentback to summary
public int getAscent()

Overrides java.awt.FontMetrics.getAscent.

Doc from java.awt.FontMetrics.getAscent.

Determines the font ascent of the Font described by this FontMetrics object. The font ascent is the distance from the font's baseline to the top of most alphanumeric characters. Some characters in the Font might extend above the font ascent line.

getDefaultFrcback to summary
private static FontRenderContext getDefaultFrc()
getDescentback to summary
public int getDescent()

Overrides java.awt.FontMetrics.getDescent.

Doc from java.awt.FontMetrics.getDescent.

Determines the font descent of the Font described by this FontMetrics object. The font descent is the distance from the font's baseline to the bottom of most alphanumeric characters with descenders. Some characters in the Font might extend below the font descent line.

getFontRenderContextback to summary
public FontRenderContext getFontRenderContext()

Overrides java.awt.FontMetrics.getFontRenderContext.

Doc from java.awt.FontMetrics.getFontRenderContext.

Gets the FontRenderContext used by this FontMetrics object to measure text.

Note that methods in this class which take a Graphics parameter measure text using the FontRenderContext of that Graphics object, and not this FontRenderContext

getHeightback to summary
public int getHeight()

Overrides java.awt.FontMetrics.getHeight.

Doc from java.awt.FontMetrics.getHeight.

Gets the standard height of a line of text in this font. This is the distance between the baseline of adjacent lines of text. It is the sum of the leading + ascent + descent. Due to rounding this may not be the same as getAscent() + getDescent() + getLeading(). There is no guarantee that lines of text spaced at this distance are disjoint; such lines may overlap if some characters overshoot either the standard ascent or the standard descent metric.

getLatinCharWidthback to summary
private float getLatinCharWidth(char ch)
getLeadingback to summary
public int getLeading()

Overrides java.awt.FontMetrics.getLeading.

Doc from java.awt.FontMetrics.getLeading.

Determines the standard leading of the Font described by this FontMetrics object. The standard leading, or interline spacing, is the logical amount of space to be reserved between the descent of one line of text and the ascent of the next line. The height metric is calculated to include this extra space.

getMaxAdvanceback to summary
public int getMaxAdvance()

Overrides java.awt.FontMetrics.getMaxAdvance.

Doc from java.awt.FontMetrics.getMaxAdvance.

Returns an estimate of the maximum advance width of any character in the Font described by this FontMetrics object, with important caveats, enumerated below.

The advance is the distance from the leftmost point used to position the character to the rightmost point along the baseline. This is not the same thing as the visible width of the glyph image representing the character.

The advance of a String is not necessarily the sum of the advances of its characters. It may differ substantially if complex text layout is required for proper rendering.

Some of the caveats of the reported value include

  • The returned value is relying upon information from some underlying system font, and the correctness of that information is outside of AWT's control.
  • When specific characters are mapped into glyphs in some rendering context, instructions in the font itself together with the rasterization process may cause some glyph to have a wider advance than reported.
  • When a font is requested in some style, eg Font.BOLD, for which no exact match is available, then techniques to satisfy the requested rendering may similarly result in glyphs that are wider than the reported maximum.
  • Depending on the implementation, an AWT logical font or physical font may need to locate some characters from one or more "fall back" fonts, when the primary underlying physical font does not support the character. These fonts may not all be known or considered in the calculation of the reported maximum advance. It is common for the design center of such fall back fonts to be for a different script than the design center of the primary font, so their advances can be quite different. This can also lead to the unexpected result that a font such as Font.MONOSPACED can render glyphs that are not all the same width.
None of these caveats are exposed as they are all implementation details, and there is no practical way to determine when these are in effect. An application which needs a better estimate of the maximum advance, and knows the subset of characters it expects to display can query the advance of each such character to find the widest, however, as discussed above, since the displayed width of a String is not necessarily the sum of the advances the value still needs to be used with caution.

In summary, this method makes no absolute guarantee, nor can it even make a guarantee to be correct within some margin of error. So it should be used at most only for estimating the total space sufficient to display some number of as yet unknown characters from the font. And that might be either an overestimate, or an underestimate depending on the specific text and rendering context.

getMetricsback to summary
public static FontDesignMetrics getMetrics(Font font)
getMetricsback to summary
public static FontDesignMetrics getMetrics(Font font, FontRenderContext frc)
getSimpleBoundsback to summary
public Rectangle2D getSimpleBounds(char[] data, int off, int len)

This method is called from java.awt.Font only after verifying the arguments and that the text is simple and there are no layout attributes, font transform etc.

getWidthsback to summary
public int[] getWidths()

Overrides java.awt.FontMetrics.getWidths.

Gets the advance widths of the first 256 characters in the Font. The advance is the distance from the leftmost point to the rightmost point on the character's baseline. Note that the advance of a String is not necessarily the sum of the advances of its characters.

Returns:int[]

an array storing the advance widths of the characters in the Font described by this FontMetrics object.

handleCharWidthback to summary
private float handleCharWidth(int ch)
initAdvCacheback to summary
private void initAdvCache()
initMatrixAndMetricsback to summary
private void initMatrixAndMetrics()
readObjectback to summary
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
Annotations
@Serial
stringWidthback to summary
public int stringWidth(String str)

Overrides java.awt.FontMetrics.stringWidth.

Doc from java.awt.FontMetrics.stringWidth.

Returns the total advance width for showing the specified String in this Font. The advance is the distance from the leftmost point to the rightmost point on the string's baseline.

Note that the advance of a String is not necessarily the sum of the advances of its characters.

writeObjectback to summary
private void writeObject(ObjectOutputStream out) throws IOException
Annotations
@Serial
sun.font back to summary

private Class FontDesignMetrics.KeyReference

extends SoftReference<Object>
implements DisposerRecord, PollDisposable
Class Inheritance
All Implemented Interfaces
sun.java2d.Disposer.PollDisposable, sun.java2d.DisposerRecord

Field Summary

Modifier and TypeField and Description
pack-priv Object
pack-priv static ReferenceQueue<Object>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from java.lang.ref.SoftReference:
get

Field Detail

keyback to summary
pack-priv Object key
queueback to summary
pack-priv static ReferenceQueue<Object> queue

Hides java.lang.ref.Reference.queue.

Constructor Detail

KeyReferenceback to summary
pack-priv KeyReference(Object key, Object value)

Method Detail

disposeback to summary
public void dispose()

Implements sun.java2d.DisposerRecord.dispose.

sun.font back to summary

private Class FontDesignMetrics.MetricsKey

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv Font
pack-priv FontRenderContext
pack-priv int
pack-priv static final FontDesignMetrics.MetricsKey

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object key)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv void
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

fontback to summary
pack-priv Font font
frcback to summary
pack-priv FontRenderContext frc
hashback to summary
pack-priv int hash
keyback to summary
pack-priv static final FontDesignMetrics.MetricsKey key

Constructor Detail

MetricsKeyback to summary
pack-priv MetricsKey()
MetricsKeyback to summary
pack-priv MetricsKey(Font font, FontRenderContext frc)

Method Detail

equalsback to summary
public boolean equals(Object key)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
initback to summary
pack-priv void init(Font font, FontRenderContext frc)