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

public final Class GlyphMetrics

extends Object
Class Inheritance
Imports
java.awt.geom.Rectangle2D

The GlyphMetrics class represents information for a single glyph. A glyph is the visual representation of one or more characters. Many different glyphs can be used to represent a single character or combination of characters. GlyphMetrics instances are produced by Font and are applicable to a specific glyph in a particular Font.

Glyphs are either STANDARD, LIGATURE, COMBINING, or COMPONENT.

Other metrics available through GlyphMetrics are the components of the advance, the visual bounds, and the left and right side bearings.

Glyphs for a rotated font, or obtained from a GlyphVector which has applied a rotation to the glyph, can have advances that contain both X and Y components. Usually the advance only has one component.

The advance of a glyph is the distance from the glyph's origin to the origin of the next glyph along the baseline, which is either vertical or horizontal. Note that, in a GlyphVector, the distance from a glyph to its following glyph might not be the glyph's advance, because of kerning or other positioning adjustments.

The bounds is the smallest rectangle that completely contains the outline of the glyph. The bounds rectangle is relative to the glyph's origin. The left-side bearing is the distance from the glyph origin to the left of its bounds rectangle. If the left-side bearing is negative, part of the glyph is drawn to the left of its origin. The right-side bearing is the distance from the right side of the bounds rectangle to the next glyph origin (the origin plus the advance). If negative, part of the glyph is drawn to the right of the next glyph's origin. Note that the bounds does not necessarily enclose all the pixels affected when rendering the glyph, because of rasterization and pixel adjustment effects.

Although instances of GlyphMetrics can be directly constructed, they are almost always obtained from a GlyphVector. Once constructed, GlyphMetrics objects are immutable.

Example:

Querying a Font for glyph information

Font font = ...;
int glyphIndex = ...;
GlyphMetrics metrics = GlyphVector.getGlyphMetrics(glyphIndex);
int isStandard = metrics.isStandard();
float glyphAdvance = metrics.getAdvance();
See Also
java.awt.Font, GlyphVector

Field Summary

Modifier and TypeField and Description
private float
advanceX

The x-component of the advance.

private float
advanceY

The y-component of the advance.

private Rectangle2D.Float
bounds

The bounds of the associated glyph.

public static final byte
COMBINING

Indicates a glyph that represents a combining character, such as an umlaut.

public static final byte
COMPONENT

Indicates a glyph with no corresponding character in the backing store.

private byte
glyphType

Additional information about the glyph encoded as a byte.

private boolean
horizontal

Indicates whether the metrics are for a horizontal or vertical baseline.

public static final byte
LIGATURE

Indicates a glyph that represents multiple characters as a ligature, for example 'fi' or 'ffi'.

public static final byte
STANDARD

Indicates a glyph that represents a single standard character.

public static final byte
WHITESPACE

Indicates a glyph with no visual representation.

Constructor Summary

AccessConstructor and Description
public
GlyphMetrics(float
the advance width of the glyph
advance
,
Rectangle2D
the black box bounds of the glyph
bounds
,
byte
the type of the glyph
glyphType
)

Constructs a GlyphMetrics object.

public
GlyphMetrics(boolean
if true, metrics are for a horizontal baseline, otherwise they are for a vertical baseline
horizontal
,
float
the X-component of the glyph's advance
advanceX
,
float
the Y-component of the glyph's advance
advanceY
,
Rectangle2D
the visual bounds of the glyph
bounds
,
byte
the type of the glyph
glyphType
)

Constructs a GlyphMetrics object.

Method Summary

Modifier and TypeMethod and Description
public float

Returns:

the advance of the glyph
getAdvance
()

Returns the advance of the glyph along the baseline (either horizontal or vertical).

public float

Returns:

the x-component of the advance of the glyph
getAdvanceX
()

Returns the x-component of the advance of the glyph.

public float

Returns:

the y-component of the advance of the glyph
getAdvanceY
()

Returns the y-component of the advance of the glyph.

public Rectangle2D

Returns:

a Rectangle2D that is the bounds of the glyph.
getBounds2D
()

Returns the bounds of the glyph.

public float

Returns:

the left side bearing of the glyph.
getLSB
()

Returns the left (top) side bearing of the glyph.

public float

Returns:

the right side bearing of the glyph.
getRSB
()

Returns the right (bottom) side bearing of the glyph.

public int

Returns:

the raw glyph type code.
getType
()

Returns the raw glyph type code.

public boolean

Returns:

true if this is a combining glyph; false otherwise.
isCombining
()

Returns true if this is a combining glyph.

public boolean

Returns:

true if this is a component glyph; false otherwise.
isComponent
()

Returns true if this is a component glyph.

public boolean

Returns:

true if this is a ligature glyph; false otherwise.
isLigature
()

Returns true if this is a ligature glyph.

public boolean

Returns:

true if this is a standard glyph; false otherwise.
isStandard
()

Returns true if this is a standard glyph.

public boolean

Returns:

true if this is a whitespace glyph; false otherwise.
isWhitespace
()

Returns true if this is a whitespace glyph.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

advanceXback to summary
private float advanceX

The x-component of the advance.

advanceYback to summary
private float advanceY

The y-component of the advance.

boundsback to summary
private Rectangle2D.Float bounds

The bounds of the associated glyph.

COMBININGback to summary
public static final byte COMBINING

Indicates a glyph that represents a combining character, such as an umlaut. There is no caret position between this glyph and the preceding glyph.

COMPONENTback to summary
public static final byte COMPONENT

Indicates a glyph with no corresponding character in the backing store. The glyph is associated with the character represented by the logically preceding non-component glyph. This is used for kashida justification or other visual modifications to existing glyphs. There is no caret position between this glyph and the preceding glyph.

glyphTypeback to summary
private byte glyphType

Additional information about the glyph encoded as a byte.

horizontalback to summary
private boolean horizontal

Indicates whether the metrics are for a horizontal or vertical baseline.

LIGATUREback to summary
public static final byte LIGATURE

Indicates a glyph that represents multiple characters as a ligature, for example 'fi' or 'ffi'. It is followed by filler glyphs for the remaining characters. Filler and combining glyphs can be intermixed to control positioning of accent marks on the logically preceding ligature.

STANDARDback to summary
public static final byte STANDARD

Indicates a glyph that represents a single standard character.

WHITESPACEback to summary
public static final byte WHITESPACE

Indicates a glyph with no visual representation. It can be added to the other code values to indicate an invisible glyph.

Constructor Detail

GlyphMetricsback to summary
public GlyphMetrics(float advance, Rectangle2D bounds, byte glyphType)

Constructs a GlyphMetrics object.

Parameters
advance:float

the advance width of the glyph

bounds:Rectangle2D

the black box bounds of the glyph

glyphType:byte

the type of the glyph

GlyphMetricsback to summary
public GlyphMetrics(boolean horizontal, float advanceX, float advanceY, Rectangle2D bounds, byte glyphType)

Constructs a GlyphMetrics object.

Parameters
horizontal:boolean

if true, metrics are for a horizontal baseline, otherwise they are for a vertical baseline

advanceX:float

the X-component of the glyph's advance

advanceY:float

the Y-component of the glyph's advance

bounds:Rectangle2D

the visual bounds of the glyph

glyphType:byte

the type of the glyph

Since
1.4

Method Detail

getAdvanceback to summary
public float getAdvance()

Returns the advance of the glyph along the baseline (either horizontal or vertical).

Returns:float

the advance of the glyph

getAdvanceXback to summary
public float getAdvanceX()

Returns the x-component of the advance of the glyph.

Returns:float

the x-component of the advance of the glyph

Since
1.4
getAdvanceYback to summary
public float getAdvanceY()

Returns the y-component of the advance of the glyph.

Returns:float

the y-component of the advance of the glyph

Since
1.4
getBounds2Dback to summary
public Rectangle2D getBounds2D()

Returns the bounds of the glyph. This is the bounding box of the glyph outline. Because of rasterization and pixel alignment effects, it does not necessarily enclose the pixels that are affected when rendering the glyph.

Returns:Rectangle2D

a Rectangle2D that is the bounds of the glyph.

getLSBback to summary
public float getLSB()

Returns the left (top) side bearing of the glyph.

This is the distance from 0, 0 to the left (top) of the glyph bounds. If the bounds of the glyph is to the left of (above) the origin, the LSB is negative.

Returns:float

the left side bearing of the glyph.

getRSBback to summary
public float getRSB()

Returns the right (bottom) side bearing of the glyph.

This is the distance from the right (bottom) of the glyph bounds to the advance. If the bounds of the glyph is to the right of (below) the advance, the RSB is negative.

Returns:float

the right side bearing of the glyph.

getTypeback to summary
public int getType()

Returns the raw glyph type code.

Returns:int

the raw glyph type code.

isCombiningback to summary
public boolean isCombining()

Returns true if this is a combining glyph.

Returns:boolean

true if this is a combining glyph; false otherwise.

isComponentback to summary
public boolean isComponent()

Returns true if this is a component glyph.

Returns:boolean

true if this is a component glyph; false otherwise.

isLigatureback to summary
public boolean isLigature()

Returns true if this is a ligature glyph.

Returns:boolean

true if this is a ligature glyph; false otherwise.

isStandardback to summary
public boolean isStandard()

Returns true if this is a standard glyph.

Returns:boolean

true if this is a standard glyph; false otherwise.

isWhitespaceback to summary
public boolean isWhitespace()

Returns true if this is a whitespace glyph.

Returns:boolean

true if this is a whitespace glyph; false otherwise.