java.awt.font
Class GlyphMetrics

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.awt.font.GlyphMetrics

public final class GlyphMetrics
extends Object sample code for java.lang.Object definition code for java.lang.Object

The GlyphMetrics class represents infomation 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 sample code for java.awt.Font definition code for java.awt.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:
Font sample code for java.awt.Font definition code for java.awt.Font , GlyphVector sample code for java.awt.font.GlyphVector definition code for java.awt.font.GlyphVector

Field Summary
static byte COMBINING sample code for java.awt.font.GlyphMetrics.COMBINING definition code for java.awt.font.GlyphMetrics.COMBINING
          Indicates a glyph that represents a combining character, such as an umlaut.
static byte COMPONENT sample code for java.awt.font.GlyphMetrics.COMPONENT definition code for java.awt.font.GlyphMetrics.COMPONENT
          Indicates a glyph with no corresponding character in the backing store.
static byte LIGATURE sample code for java.awt.font.GlyphMetrics.LIGATURE definition code for java.awt.font.GlyphMetrics.LIGATURE
          Indicates a glyph that represents multiple characters as a ligature, for example 'fi' or 'ffi'.
static byte STANDARD sample code for java.awt.font.GlyphMetrics.STANDARD definition code for java.awt.font.GlyphMetrics.STANDARD
          Indicates a glyph that represents a single standard character.
static byte WHITESPACE sample code for java.awt.font.GlyphMetrics.WHITESPACE definition code for java.awt.font.GlyphMetrics.WHITESPACE
          Indicates a glyph with no visual representation.
 
Constructor Summary
GlyphMetrics sample code for java.awt.font.GlyphMetrics.GlyphMetrics(boolean, float, float, java.awt.geom.Rectangle2D, byte) definition code for java.awt.font.GlyphMetrics.GlyphMetrics(boolean, float, float, java.awt.geom.Rectangle2D, byte) (boolean horizontal, float advanceX, float advanceY, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds, byte glyphType)
          Constructs a GlyphMetrics object.
GlyphMetrics sample code for java.awt.font.GlyphMetrics.GlyphMetrics(float, java.awt.geom.Rectangle2D, byte) definition code for java.awt.font.GlyphMetrics.GlyphMetrics(float, java.awt.geom.Rectangle2D, byte) (float advance, Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds, byte glyphType)
          Constructs a GlyphMetrics object.
 
Method Summary
 float getAdvance sample code for java.awt.font.GlyphMetrics.getAdvance() definition code for java.awt.font.GlyphMetrics.getAdvance() ()
          Returns the advance of the glyph along the baseline (either horizontal or vertical).
 float getAdvanceX sample code for java.awt.font.GlyphMetrics.getAdvanceX() definition code for java.awt.font.GlyphMetrics.getAdvanceX() ()
          Returns the x-component of the advance of the glyph.
 float getAdvanceY sample code for java.awt.font.GlyphMetrics.getAdvanceY() definition code for java.awt.font.GlyphMetrics.getAdvanceY() ()
          Returns the y-component of the advance of the glyph.
 Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D getBounds2D sample code for java.awt.font.GlyphMetrics.getBounds2D() definition code for java.awt.font.GlyphMetrics.getBounds2D() ()
          Returns the bounds of the glyph.
 float getLSB sample code for java.awt.font.GlyphMetrics.getLSB() definition code for java.awt.font.GlyphMetrics.getLSB() ()
          Returns the left (top) side bearing of the glyph.
 float getRSB sample code for java.awt.font.GlyphMetrics.getRSB() definition code for java.awt.font.GlyphMetrics.getRSB() ()
          Returns the right (bottom) side bearing of the glyph.
 int getType sample code for java.awt.font.GlyphMetrics.getType() definition code for java.awt.font.GlyphMetrics.getType() ()
          Returns the raw glyph type code.
 boolean isCombining sample code for java.awt.font.GlyphMetrics.isCombining() definition code for java.awt.font.GlyphMetrics.isCombining() ()
          Returns true if this is a combining glyph.
 boolean isComponent sample code for java.awt.font.GlyphMetrics.isComponent() definition code for java.awt.font.GlyphMetrics.isComponent() ()
          Returns true if this is a component glyph.
 boolean isLigature sample code for java.awt.font.GlyphMetrics.isLigature() definition code for java.awt.font.GlyphMetrics.isLigature() ()
          Returns true if this is a ligature glyph.
 boolean isStandard sample code for java.awt.font.GlyphMetrics.isStandard() definition code for java.awt.font.GlyphMetrics.isStandard() ()
          Returns true if this is a standard glyph.
 boolean isWhitespace sample code for java.awt.font.GlyphMetrics.isWhitespace() definition code for java.awt.font.GlyphMetrics.isWhitespace() ()
          Returns true if this is a whitespace glyph.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Field Detail

STANDARD sample code for java.awt.font.GlyphMetrics.STANDARD

public static final byte STANDARD
Indicates a glyph that represents a single standard character.

See Also:
Constant Field Values

LIGATURE sample code for java.awt.font.GlyphMetrics.LIGATURE

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 preceeding ligature.

See Also:
Constant Field Values

COMBINING sample code for java.awt.font.GlyphMetrics.COMBINING

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 preceeding glyph.

See Also:
Constant Field Values

COMPONENT sample code for java.awt.font.GlyphMetrics.COMPONENT

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 logicaly preceeding 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 preceeding glyph.

See Also:
Constant Field Values

WHITESPACE sample code for java.awt.font.GlyphMetrics.WHITESPACE

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.

See Also:
Constant Field Values
Constructor Detail

GlyphMetrics sample code for java.awt.font.GlyphMetrics(float, java.awt.geom.Rectangle2D, byte) definition code for java.awt.font.GlyphMetrics(float, java.awt.geom.Rectangle2D, byte)

public GlyphMetrics(float advance,
                    Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds,
                    byte glyphType)
Constructs a GlyphMetrics object.

Parameters:
advance - the advance width of the glyph
bounds - the black box bounds of the glyph
glyphType - the type of the glyph

GlyphMetrics sample code for java.awt.font.GlyphMetrics(boolean, float, float, java.awt.geom.Rectangle2D, byte) definition code for java.awt.font.GlyphMetrics(boolean, float, float, java.awt.geom.Rectangle2D, byte)

public GlyphMetrics(boolean horizontal,
                    float advanceX,
                    float advanceY,
                    Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D  bounds,
                    byte glyphType)
Constructs a GlyphMetrics object.

Parameters:
horizontal - if true, metrics are for a horizontal baseline, otherwise they are for a vertical baseline
advanceX - the X-component of the glyph's advance
advanceY - the Y-component of the glyph's advance
bounds - the visual bounds of the glyph
glyphType - the type of the glyph
Method Detail

getAdvance sample code for java.awt.font.GlyphMetrics.getAdvance() definition code for java.awt.font.GlyphMetrics.getAdvance()

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

Returns:
the advance of the glyph

getAdvanceX sample code for java.awt.font.GlyphMetrics.getAdvanceX() definition code for java.awt.font.GlyphMetrics.getAdvanceX()

public float getAdvanceX()
Returns the x-component of the advance of the glyph.

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

getAdvanceY sample code for java.awt.font.GlyphMetrics.getAdvanceY() definition code for java.awt.font.GlyphMetrics.getAdvanceY()

public float getAdvanceY()
Returns the y-component of the advance of the glyph.

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

getBounds2D sample code for java.awt.font.GlyphMetrics.getBounds2D() definition code for java.awt.font.GlyphMetrics.getBounds2D()

public Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.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:
a Rectangle2D sample code for java.awt.geom.Rectangle2D definition code for java.awt.geom.Rectangle2D that is the bounds of the glyph.

getLSB sample code for java.awt.font.GlyphMetrics.getLSB() definition code for java.awt.font.GlyphMetrics.getLSB()

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:
the left side bearing of the glyph.

getRSB sample code for java.awt.font.GlyphMetrics.getRSB() definition code for java.awt.font.GlyphMetrics.getRSB()

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:
the right side bearing of the glyph.

getType sample code for java.awt.font.GlyphMetrics.getType() definition code for java.awt.font.GlyphMetrics.getType()

public int getType()
Returns the raw glyph type code.

Returns:
the raw glyph type code.

isStandard sample code for java.awt.font.GlyphMetrics.isStandard() definition code for java.awt.font.GlyphMetrics.isStandard()

public boolean isStandard()
Returns true if this is a standard glyph.

Returns:
true if this is a standard glyph; false otherwise.

isLigature sample code for java.awt.font.GlyphMetrics.isLigature() definition code for java.awt.font.GlyphMetrics.isLigature()

public boolean isLigature()
Returns true if this is a ligature glyph.

Returns:
true if this is a ligature glyph; false otherwise.

isCombining sample code for java.awt.font.GlyphMetrics.isCombining() definition code for java.awt.font.GlyphMetrics.isCombining()

public boolean isCombining()
Returns true if this is a combining glyph.

Returns:
true if this is a combining glyph; false otherwise.

isComponent sample code for java.awt.font.GlyphMetrics.isComponent() definition code for java.awt.font.GlyphMetrics.isComponent()

public boolean isComponent()
Returns true if this is a component glyph.

Returns:
true if this is a component glyph; false otherwise.

isWhitespace sample code for java.awt.font.GlyphMetrics.isWhitespace() definition code for java.awt.font.GlyphMetrics.isWhitespace()

public boolean isWhitespace()
Returns true if this is a whitespace glyph.

Returns:
true if this is a whitespace glyph; false otherwise.