- java.lang.Object
-
- java.awt.font.GlyphMetrics
-
public final class GlyphMetrics extends Object
TheGlyphMetricsclass 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.GlyphMetricsinstances are produced byFontand are applicable to a specific glyph in a particularFont.Glyphs are either STANDARD, LIGATURE, COMBINING, or COMPONENT.
- STANDARD glyphs are commonly used to represent single characters.
- LIGATURE glyphs are used to represent sequences of characters.
- COMPONENT glyphs in a
GlyphVectordo not correspond to a particular character in a text model. Instead, COMPONENT glyphs are added for typographical reasons, such as Arabic justification. - COMBINING glyphs embellish STANDARD or LIGATURE glyphs, such as accent marks. Carets do not appear before COMBINING glyphs.
Other metrics available through
GlyphMetricsare the components of the advance, the visual bounds, and the left and right side bearings.Glyphs for a rotated font, or obtained from a
GlyphVectorwhich 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
GlyphMetricscan be directly constructed, they are almost always obtained from aGlyphVector. Once constructed,GlyphMetricsobjects are immutable.Example:
Querying a
Fontfor glyph informationFont font = ...; int glyphIndex = ...; GlyphMetrics metrics = GlyphVector.getGlyphMetrics(glyphIndex); int isStandard = metrics.isStandard(); float glyphAdvance = metrics.getAdvance();
- See Also:
Font,GlyphVector
-
-
Field Summary
Fields Modifier and Type Field Description static byteCOMBININGIndicates a glyph that represents a combining character, such as an umlaut.static byteCOMPONENTIndicates a glyph with no corresponding character in the backing store.static byteLIGATUREIndicates a glyph that represents multiple characters as a ligature, for example 'fi' or 'ffi'.static byteSTANDARDIndicates a glyph that represents a single standard character.static byteWHITESPACEIndicates a glyph with no visual representation.
-
Constructor Summary
Constructors Constructor Description GlyphMetrics(boolean horizontal, float advanceX, float advanceY, Rectangle2D bounds, byte glyphType)Constructs aGlyphMetricsobject.GlyphMetrics(float advance, Rectangle2D bounds, byte glyphType)Constructs aGlyphMetricsobject.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description floatgetAdvance()Returns the advance of the glyph along the baseline (either horizontal or vertical).floatgetAdvanceX()Returns the x-component of the advance of the glyph.floatgetAdvanceY()Returns the y-component of the advance of the glyph.Rectangle2DgetBounds2D()Returns the bounds of the glyph.floatgetLSB()Returns the left (top) side bearing of the glyph.floatgetRSB()Returns the right (bottom) side bearing of the glyph.intgetType()Returns the raw glyph type code.booleanisCombining()Returnstrueif this is a combining glyph.booleanisComponent()Returnstrueif this is a component glyph.booleanisLigature()Returnstrueif this is a ligature glyph.booleanisStandard()Returnstrueif this is a standard glyph.booleanisWhitespace()Returnstrueif this is a whitespace glyph.
-
-
-
Field Detail
-
STANDARD
public static final byte STANDARD
Indicates a glyph that represents a single standard character.- See Also:
- Constant Field Values
-
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 preceding ligature.- See Also:
- Constant Field Values
-
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 preceding glyph.- See Also:
- Constant Field Values
-
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 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.- See Also:
- Constant Field Values
-
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
public GlyphMetrics(float advance, Rectangle2D bounds, byte glyphType)Constructs aGlyphMetricsobject.- Parameters:
advance- the advance width of the glyphbounds- the black box bounds of the glyphglyphType- the type of the glyph
-
GlyphMetrics
public GlyphMetrics(boolean horizontal, float advanceX, float advanceY, Rectangle2D bounds, byte glyphType)Constructs aGlyphMetricsobject.- Parameters:
horizontal- if true, metrics are for a horizontal baseline, otherwise they are for a vertical baselineadvanceX- the X-component of the glyph's advanceadvanceY- the Y-component of the glyph's advancebounds- the visual bounds of the glyphglyphType- the type of the glyph- Since:
- 1.4
-
-
Method Detail
-
getAdvance
public float getAdvance()
Returns the advance of the glyph along the baseline (either horizontal or vertical).- Returns:
- the advance of the glyph
-
getAdvanceX
public float getAdvanceX()
Returns the x-component of the advance of the glyph.- Returns:
- the x-component of the advance of the glyph
- Since:
- 1.4
-
getAdvanceY
public float getAdvanceY()
Returns the y-component of the advance of the glyph.- Returns:
- the y-component of the advance of the glyph
- Since:
- 1.4
-
getBounds2D
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:
- a
Rectangle2Dthat is the bounds of the glyph.
-
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
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
public int getType()
Returns the raw glyph type code.- Returns:
- the raw glyph type code.
-
isStandard
public boolean isStandard()
Returnstrueif this is a standard glyph.- Returns:
trueif this is a standard glyph;falseotherwise.
-
isLigature
public boolean isLigature()
Returnstrueif this is a ligature glyph.- Returns:
trueif this is a ligature glyph;falseotherwise.
-
isCombining
public boolean isCombining()
Returnstrueif this is a combining glyph.- Returns:
trueif this is a combining glyph;falseotherwise.
-
isComponent
public boolean isComponent()
Returnstrueif this is a component glyph.- Returns:
trueif this is a component glyph;falseotherwise.
-
isWhitespace
public boolean isWhitespace()
Returnstrueif this is a whitespace glyph.- Returns:
trueif this is a whitespace glyph;falseotherwise.
-
-