APIdia Launch Partner
Top Description Inners Fields Constructors Methods
sun.font

public Class StandardGlyphVector

extends GlyphVector
Class Inheritance
Imports
java.awt.Font, .Graphics2D, .Point, .Rectangle, .Shape, java.awt.font.FontRenderContext, .GlyphMetrics, .GlyphJustificationInfo, .GlyphVector, .LineMetrics, .TextAttribute, java.awt.geom.AffineTransform, .GeneralPath, .NoninvertibleTransformException, .PathIterator, .Point2D, .Rectangle2D, java.lang.ref.SoftReference, java.text.CharacterIterator, sun.awt.SunHints, sun.java2d.loops.FontInfo

Standard implementation of GlyphVector used by Font, GlyphList, and SunGraphics2D. The main issues involve the semantics of the various transforms (font, glyph, device) and their effect on rendering and metrics. Very, very unfortunately, the translation component of the font transform affects where the text gets rendered. It offsets the rendering origin. None of the other metrics of the glyphvector are affected, making them inconsistent with the rendering behavior. I think the translation component of the font would be better interpreted as the translation component of a per-glyph transform, but I don't know if this is possible to change. After the font transform is applied, the glyph transform is applied. This makes glyph transforms relative to font transforms, if the font transform changes, the glyph transform will have the same (relative) effect on the outline of the glyph. The outline and logical bounds are passed through the glyph transform before being returned. The glyph metrics ignore the glyph transform, but provide the outline bounds and the advance vector of the glyph (the latter will be rotated if the font is rotated). The default layout places each glyph at the end of the advance vector of the previous glyph, and since the glyph transform translates the advance vector, this means a glyph transform affects the positions of all subsequent glyphs if defaultLayout is called after setting a glyph transform. In the glyph info array, the bounds are the outline bounds including the glyph transform, and the positions are as computed, and the advances are the deltas between the positions. (There's a bug in the logical bounds of a rotated glyph for composite fonts, it's not to spec (in 1.4.0, 1.4.1, 1.4.2). The problem is that the rotated composite doesn't handle the multiple ascents and descents properly in both x and y. You end up with a rotated advance vector but an unrotated ascent and descent.) Finally, the whole thing is transformed by the device transform to position it on the page. Another bug: The glyph outline seems to ignore fractional point size information, but the images (and advances) don't ignore it. Small fonts drawn at large magnification have odd advances when fractional metrics is off-- that's because the advances depend on the frc. When the frc is scaled appropriately, the advances are fine. FM or a large frc (high numbers) make the advances right. The buffer aa flag doesn't affect rendering, the glyph vector renders as AA if aa is set in its frc, and as non-aa if aa is not set in its frc. font rotation, baseline, vertical etc. Font rotation and baseline Line metrics should be measured along a unit vector pi/4 cc from the baseline vector. For 'horizontal' fonts the baseline vector is the x vector passed through the font transform (ignoring translation), for 'vertical' it is the y vector. This definition makes ascent, descent, etc independent of shear, so shearing can be used to simulate italic. This means no fonts have 'negative ascents' or 'zero ascents' etc. Having a coordinate system with orthogonal axes where one is parallel to the baseline means we could use rectangles and interpret them in terms of this coordinate system. Unfortunately there is support for rotated fonts in the jdk already so maintaining the semantics of existing code (getlogical bounds, etc) might be difficult. A font transform transforms both the baseline and all the glyphs in the font, so it does not rotate the glyph w.r.t the baseline. If you do want to rotate individual glyphs, you need to apply a glyph transform. If performDefaultLayout is called after this, the transformed glyph advances will affect the glyph positions. useful additions - select vertical metrics - glyphs are rotated pi/4 cc and vertical metrics are used to align them to the baseline. - define baseline for font (glyph rotation not linked to baseline) - define extra space (delta between each glyph along baseline) - define offset (delta from 'true' baseline, impacts ascent and descent as these are still computed from true basline and pinned to zero, used in superscript).

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
public static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
private int[]
private AffineTransform
public static final int
FLAG_USES_ALTERNATE_ORIENTATION

A flag used with getLayoutFlags that indicates whether this GlyphVector uses the 'alternate orientation.' Glyphs have a default orientation given a particular baseline and metrics orientation, this is the orientation appropriate for left-to-right text.

public static final int
FLAG_USES_VERTICAL_BASELINE

A flag used with getLayoutFlags that indicates whether this GlyphVector uses a vertical baseline.

public static final int
FLAG_USES_VERTICAL_METRICS

A flag used with getLayoutFlags that indicates whether this GlyphVector uses vertical glyph metrics.

private int
private Font
private Font2D
private FontRenderContext
private AffineTransform
private SoftReference<StandardGlyphVector.GlyphStrike>
private AffineTransform
private int[]
private StandardGlyphVector.GlyphTransformInfo
private AffineTransform
private SoftReference<Shape[]>
private float[]
private static final int
private int[]
private SoftReference<Shape[]>
Inherited from java.awt.font.GlyphVector:
FLAG_COMPLEX_GLYPHSFLAG_HAS_POSITION_ADJUSTMENTSFLAG_HAS_TRANSFORMSFLAG_MASKFLAG_RUN_RTL

Constructor Summary

AccessConstructor and Description
public
public
StandardGlyphVector(Font font, char[] text, FontRenderContext frc)

public
StandardGlyphVector(Font font, char[] text, int start, int count, FontRenderContext frc)

public
StandardGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions, int[] indices, int flags)

public
public
StandardGlyphVector(Font font, int[] glyphs, FontRenderContext frc)

private
StandardGlyphVector(GlyphVector gv, FontRenderContext frc)

Utility used by getStandardGV.

Method Summary

Modifier and TypeMethod and Description
private void
addFlags(int newflags)

OR newFlags with existing flags.

pack-priv StringBuffer
private void
clearCaches(int ix)

private void
private void
clearFlags(int clearedFlags)

AND the complement of clearedFlags with existing flags.

public Object
clone()

Overrides java.lang.Object.clone.

As a concrete subclass of GlyphVector, this must implement clone.

public StandardGlyphVector
copy()

Sometimes I wish java had covariant return types...

private static boolean
public boolean
equals(GlyphVector rhs)

Implements abstract java.awt.font.GlyphVector.equals.

Tests if the specified GlyphVector exactly equals this GlyphVector.

public boolean
equals(Object rhs)

Overrides java.lang.Object.equals.

Since we implement equality comparisons for GlyphVector, we implement the inherited Object.equals(Object) as well.

private StandardGlyphVector.GlyphStrike
public Font
getFont()

Implements abstract java.awt.font.GlyphVector.getFont.

Returns the Font associated with this GlyphVector.

public FontRenderContext
getFontRenderContext()

Implements abstract java.awt.font.GlyphVector.getFontRenderContext.

Returns the FontRenderContext associated with this GlyphVector.

public int
getGlyphCharIndex(int ix)

Overrides java.awt.font.GlyphVector.getGlyphCharIndex.

Returns the character index of the specified glyph.

public int[]
getGlyphCharIndices(int start, int count, int[] result)

Overrides java.awt.font.GlyphVector.getGlyphCharIndices.

Returns the character indices of the specified glyphs.

public int
getGlyphCode(int glyphIndex)

Implements abstract java.awt.font.GlyphVector.getGlyphCode.

Returns the glyphcode of the specified glyph.

public int[]
getGlyphCodes(int start, int count, int[] result)

Implements abstract java.awt.font.GlyphVector.getGlyphCodes.

Returns an array of glyphcodes for the specified glyphs.

public float[]
getGlyphInfo()

For each glyph return posx, posy, advx, advy, visx, visy, visw, vish.

public GlyphJustificationInfo
getGlyphJustificationInfo(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphJustificationInfo.

Returns the justification information for the glyph at the specified index into this GlyphVector.

public Shape
getGlyphLogicalBounds(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphLogicalBounds.

Returns the logical bounds of the specified glyph within this GlyphVector.

public GlyphMetrics
getGlyphMetrics(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphMetrics.

Returns the metrics of the glyph at the specified index into this GlyphVector.

public Shape
getGlyphOutline(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphOutline.

Returns a Shape whose interior corresponds to the visual representation of the specified glyph within this GlyphVector.

public Shape
getGlyphOutline(int ix, float x, float y)

Overrides java.awt.font.GlyphVector.getGlyphOutline.

Returns a Shape whose interior corresponds to the visual representation of the specified glyph within this GlyphVector, offset to x, y.

private Rectangle2D
public Rectangle
getGlyphPixelBounds(int index, FontRenderContext renderFRC, float x, float y)

Overrides java.awt.font.GlyphVector.getGlyphPixelBounds.

Returns the pixel bounds of the glyph at index when this GlyphVector is rendered in a Graphics with the given FontRenderContext at the given location.

public Point2D
getGlyphPosition(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphPosition.

Returns the position of the specified glyph relative to the origin of this GlyphVector.

public float[]
getGlyphPositions(int start, int count, float[] result)

Implements abstract java.awt.font.GlyphVector.getGlyphPositions.

Returns an array of glyph positions for the specified glyphs.

public float[]
getGlyphPositions(float[] result)

This is a convenience overload that gets all the glyph positions, which is what you usually want to do if you're getting more than one.

private Shape
getGlyphsOutline(int start, int count, float x, float y)

Used by getOutline, getGlyphsOutline

private Rectangle
getGlyphsPixelBounds(FontRenderContext frc, float x, float y, int start, int count)

private StandardGlyphVector.GlyphStrike
public AffineTransform
getGlyphTransform(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphTransform.

Returns the transform of the specified glyph within this GlyphVector.

public AffineTransform[]
getGlyphTransforms(int start, int count, AffineTransform[] result)

Get transform information for the requested range of glyphs.

public AffineTransform[]
getGlyphTransforms()

Convenience overload for getGlyphTransforms(int, int, AffineTransform[], int);

public Shape
getGlyphVisualBounds(int ix)

Implements abstract java.awt.font.GlyphVector.getGlyphVisualBounds.

Returns the visual bounds of the specified glyph within the GlyphVector.

public int
getLayoutFlags()

Overrides java.awt.font.GlyphVector.getLayoutFlags.

Returns flags describing the global state of the GlyphVector.

public Rectangle2D
getLogicalBounds()

Implements abstract java.awt.font.GlyphVector.getLogicalBounds.

Returns the logical bounds of this GlyphVector.

private static AffineTransform
public int
getNumGlyphs()

Implements abstract java.awt.font.GlyphVector.getNumGlyphs.

Returns the number of glyphs in this GlyphVector.

public Shape
getOutline()

Implements abstract java.awt.font.GlyphVector.getOutline.

Returns a Shape whose interior corresponds to the visual representation of this GlyphVector.

public Shape
getOutline(float x, float y)

Implements abstract java.awt.font.GlyphVector.getOutline.

Returns a Shape whose interior corresponds to the visual representation of this GlyphVector when rendered at x, y.

public Rectangle
getPixelBounds(FontRenderContext renderFRC, float x, float y)

Overrides java.awt.font.GlyphVector.getPixelBounds.

Returns the pixel bounds of this GlyphVector when rendered in a graphics with the given FontRenderContext at the given location.

public static StandardGlyphVector
private float
pack-priv int[]
getValidatedGlyphs(int[] oglyphs)

public Rectangle2D
getVisualBounds()

Implements abstract java.awt.font.GlyphVector.getVisualBounds.

Returns the visual bounds of this GlyphVector The visual bounds is the bounding box of the outline of this GlyphVector.

public int
hashCode()

Overrides java.lang.Object.hashCode.

As a concrete subclass of Object that implements equality, this must implement hashCode.

private void
init(Font font, char[] text, int start, int count, FontRenderContext frc, int flags)

private void
public void
initGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions, int[] indices, int flags)

private void
initPositions()

Ensure that the positions array exists and holds position data.

private float[]

Returns:

the modified position array
internalGetGlyphPositions
(int
the index of the first glyph to get
start
,
int
the number of glyphs to get
count
,
int
the offset into result at which to put the data
offset
,
float[]
an array to hold the x,y positions
result
)

Copy glyph position data into a result array starting at the indicated offset in the array.

private static boolean
matchTX(double[] lhs, AffineTransform rhs)

pack-priv boolean
needsPositions(double[] devTX)

public void
performDefaultLayout()

Implements abstract java.awt.font.GlyphVector.performDefaultLayout.

Assigns default positions to each glyph in this GlyphVector.

private void
resetDTX(AffineTransform at)

Change the dtx for the strike refs we use.

private void
private void
public void
setGlyphPosition(int ix, Point2D pos)

Implements abstract java.awt.font.GlyphVector.setGlyphPosition.

Sets the position of the specified glyph within this GlyphVector.

public void
setGlyphPositions(float[] srcPositions, int srcStart, int start, int count)

public void
setGlyphPositions(float[] srcPositions)

Set all the glyph positions, including the 'after last glyph' position.

public void
setGlyphTransform(int ix, AffineTransform newTX)

Implements abstract java.awt.font.GlyphVector.setGlyphTransform.

Sets the transform of the specified glyph within this GlyphVector.

public void
setGlyphTransforms(AffineTransform[] srcTransforms, int srcStart, int start, int count)

Set a number of glyph transforms.

public void
setGlyphTransforms(AffineTransform[] srcTransforms)

Convenience overload of setGlyphTransforms(AffineTransform[], int, int, int).

private void
setRenderTransform(double[] devTX)

pack-priv Object
setupGlyphImages(long[] images, float[] positions, double[] devTX)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.