public class

StandardGlyphVector

extends GlyphVector
java.lang.Object
   ↳ java.awt.font.GlyphVector
     ↳ sun.font.StandardGlyphVector

Class Overview

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).

Summary

Nested Classes
class StandardGlyphVector.GlyphStrike  
Constants
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.
int FLAG_USES_VERTICAL_BASELINE A flag used with getLayoutFlags that indicates whether this GlyphVector uses a vertical baseline.
int FLAG_USES_VERTICAL_METRICS A flag used with getLayoutFlags that indicates whether this GlyphVector uses vertical glyph metrics.
[Expand]
Inherited Constants
From class java.awt.font.GlyphVector
Public Constructors
StandardGlyphVector(Font font, String str, FontRenderContext frc)
StandardGlyphVector(Font font, char[] text, FontRenderContext frc)
StandardGlyphVector(Font font, char[] text, int start, int count, FontRenderContext frc)
StandardGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions, int[] indices, int flags)
StandardGlyphVector(Font font, CharacterIterator iter, FontRenderContext frc)
StandardGlyphVector(Font font, int[] glyphs, FontRenderContext frc)
Public Methods
Object clone()
As a concrete subclass of GlyphVector, this must implement clone.
StandardGlyphVector copy()
Sometimes I wish java had covariant return types...
boolean equals(Object rhs)
Since we implement equality comparisons for GlyphVector, we implement the inherited Object.equals(Object) as well.
boolean equals(GlyphVector rhs)
Tests if the specified GlyphVector exactly equals this GlyphVector.
Font getFont()
Returns the Font associated with this GlyphVector.
FontRenderContext getFontRenderContext()
Returns the FontRenderContext associated with this GlyphVector.
int getGlyphCharIndex(int ix)
Returns the character index of the specified glyph.
int[] getGlyphCharIndices(int start, int count, int[] result)
Returns the character indices of the specified glyphs.
int getGlyphCode(int glyphIndex)
Returns the glyphcode of the specified glyph.
int[] getGlyphCodes(int start, int count, int[] result)
Returns an array of glyphcodes for the specified glyphs.
float[] getGlyphInfo()
For each glyph return posx, posy, advx, advy, visx, visy, visw, vish.
GlyphJustificationInfo getGlyphJustificationInfo(int ix)
Returns the justification information for the glyph at the specified index into this GlyphVector.
Shape getGlyphLogicalBounds(int ix)
Returns the logical bounds of the specified glyph within this GlyphVector.
GlyphMetrics getGlyphMetrics(int ix)
Returns the metrics of the glyph at the specified index into this GlyphVector.
Shape getGlyphOutline(int ix)
Returns a Shape whose interior corresponds to the visual representation of the specified glyph within this GlyphVector.
Shape getGlyphOutline(int ix, float x, float y)
Returns a Shape whose interior corresponds to the visual representation of the specified glyph within this GlyphVector, offset to x, y.
Rectangle getGlyphPixelBounds(int index, FontRenderContext renderFRC, float x, float y)
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.
Point2D getGlyphPosition(int ix)
Returns the position of the specified glyph relative to the origin of this GlyphVector.
float[] getGlyphPositions(int start, int count, float[] result)
Returns an array of glyph positions for the specified glyphs.
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.
AffineTransform getGlyphTransform(int ix)
Returns the transform of the specified glyph within this GlyphVector.
AffineTransform[] getGlyphTransforms(int start, int count, AffineTransform[] result)
Get transform information for the requested range of glyphs.
AffineTransform[] getGlyphTransforms()
Convenience overload for getGlyphTransforms(int, int, AffineTransform[], int);
Shape getGlyphVisualBounds(int ix)
Returns the visual bounds of the specified glyph within the GlyphVector.
int getLayoutFlags()
Returns flags describing the global state of the GlyphVector.
Rectangle2D getLogicalBounds()
Returns the logical bounds of this GlyphVector.
int getNumGlyphs()
Returns the number of glyphs in this GlyphVector.
Shape getOutline()
Returns a Shape whose interior corresponds to the visual representation of this GlyphVector.
Shape getOutline(float x, float y)
Returns a Shape whose interior corresponds to the visual representation of this GlyphVector when rendered at x, y.
Rectangle getPixelBounds(FontRenderContext renderFRC, float x, float y)
Returns the pixel bounds of this GlyphVector when rendered in a graphics with the given FontRenderContext at the given location.
static StandardGlyphVector getStandardGV(GlyphVector gv, FontInfo info)
Rectangle2D getVisualBounds()
Returns the visual bounds of this GlyphVector The visual bounds is the bounding box of the outline of this GlyphVector.
int hashCode()
As a concrete subclass of Object that implements equality, this must implement hashCode.
void initGlyphVector(Font font, FontRenderContext frc, int[] glyphs, float[] positions, int[] indices, int flags)
void performDefaultLayout()
Assigns default positions to each glyph in this GlyphVector.
void pixellate(FontRenderContext renderFRC, Point2D loc, Point pxResult)
!!! not used currently, but might be by getPixelbounds?
void setGlyphPosition(int ix, Point2D pos)
Sets the position of the specified glyph within this GlyphVector.
void setGlyphPositions(float[] srcPositions)
Set all the glyph positions, including the 'after last glyph' position.
void setGlyphPositions(float[] srcPositions, int srcStart, int start, int count)
void setGlyphTransform(int ix, AffineTransform newTX)
Sets the transform of the specified glyph within this GlyphVector.
void setGlyphTransforms(AffineTransform[] srcTransforms, int srcStart, int start, int count)
Set a number of glyph transforms.
void setGlyphTransforms(AffineTransform[] srcTransforms)
Convenience overload of setGlyphTransforms(AffineTransform[], int, int, int).
String toString()
Returns a string representation of the object.
[Expand]
Inherited Methods
From class java.awt.font.GlyphVector
From class java.lang.Object

Constants

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. For example, the letter 'A' can have four orientations, with the point at 12, 3, 6, or 9 'o clock. The following table shows where the point displays for different values of vertical baseline (vb), vertical metrics (vm) and alternate orientation (fo):

vb vm ao -- -- -- -- f f f 12 ^ horizontal metrics on horizontal lines f f t 6 v f t f 9 < vertical metrics on horizontal lines f t t 3 > t f f 3 > horizontal metrics on vertical lines t f t 9 < t t f 12 ^ vertical metrics on vertical lines t t t 6 v

Constant Value: 512 (0x00000200)

public static final int FLAG_USES_VERTICAL_BASELINE

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

Constant Value: 128 (0x00000080)

public static final int FLAG_USES_VERTICAL_METRICS

A flag used with getLayoutFlags that indicates whether this GlyphVector uses vertical glyph metrics. A GlyphVector can use vertical metrics on a horizontal line, or vice versa.

Constant Value: 256 (0x00000100)

Public Constructors

public StandardGlyphVector (Font font, String str, FontRenderContext frc)

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 StandardGlyphVector (Font font, CharacterIterator iter, FontRenderContext frc)

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

Public Methods

public Object clone ()

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

Returns
  • a clone of this instance.

public StandardGlyphVector copy ()

Sometimes I wish java had covariant return types...

public boolean equals (Object rhs)

Since we implement equality comparisons for GlyphVector, we implement the inherited Object.equals(Object) as well. GlyphVector should do this, and define two glyphvectors as not equal if the classes differ.

Parameters
rhs the reference object with which to compare.
Returns
  • true if this object is the same as the obj argument; false otherwise.

public boolean equals (GlyphVector rhs)

Tests if the specified GlyphVector exactly equals this GlyphVector.

Parameters
rhs the specified GlyphVector to test
Returns
  • true if the specified GlyphVector equals this GlyphVector; false otherwise.

public Font getFont ()

Returns the Font associated with this GlyphVector.

Returns
  • Font used to create this GlyphVector.

public FontRenderContext getFontRenderContext ()

Returns the FontRenderContext associated with this GlyphVector.

Returns
  • FontRenderContext used to create this GlyphVector.

public int getGlyphCharIndex (int ix)

Returns the character index of the specified glyph. The character index is the index of the first logical character represented by the glyph. The default implementation assumes a one-to-one, left-to-right mapping of glyphs to characters.

Parameters
ix the index of the glyph
Returns
  • the index of the first character represented by the glyph

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

Returns the character indices of the specified glyphs. The character index is the index of the first logical character represented by the glyph. Indices are returned in glyph order. The default implementation invokes getGlyphCharIndex for each glyph, and subclassers will probably want to override this implementation for performance reasons. Use this method for convenience and performance in processing of glyphcodes. If no array is passed in, a new array is created.

Parameters
start the index of the first glyph
count the number of glyph indices
result the array into which to return the character indices
Returns
  • an array of character indices, one per glyph.

public int getGlyphCode (int glyphIndex)

Returns the glyphcode of the specified glyph. This return value is meaningless to anything other than the Font object that created this GlyphVector.

Parameters
glyphIndex the index into this GlyphVector that corresponds to the glyph from which to retrieve the glyphcode.
Returns
  • the glyphcode of the glyph at the specified glyphIndex.

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

Returns an array of glyphcodes for the specified glyphs. The contents of this return value are meaningless to anything other than the Font used to create this GlyphVector. This method is used for convenience and performance when processing glyphcodes. If no array is passed in, a new array is created.

Parameters
start the index into this GlyphVector at which to start retrieving glyphcodes
count the number of glyphcodes to retrieve
result the array that receives the glyphcodes and is then returned
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)

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

Parameters
ix the index into this GlyphVector that corresponds to the glyph from which to retrieve its justification properties
Returns
  • a GlyphJustificationInfo object that represents the justification properties of the glyph at the specified glyphIndex into this GlyphVector.

public Shape getGlyphLogicalBounds (int ix)

Returns the logical bounds of the specified glyph within this GlyphVector. These logical bounds have a total of four edges, with two edges parallel to the baseline under the glyph's transform and the other two edges are shared with adjacent glyphs if they are present. This method is useful for hit-testing of the specified glyph, positioning of a caret at the leading or trailing edge of a glyph, and for drawing a highlight region around the specified glyph.

Parameters
ix the index into this GlyphVector that corresponds to the glyph from which to retrieve its logical bounds
Returns
  • a Shape that is the logical bounds of the glyph at the specified glyphIndex.

public GlyphMetrics getGlyphMetrics (int ix)

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

Parameters
ix the index into this GlyphVector that corresponds to the glyph from which to retrieve its metrics
Returns
  • a GlyphMetrics object that represents the metrics of the glyph at the specified glyphIndex into this GlyphVector.

public Shape getGlyphOutline (int ix)

Returns a Shape whose interior corresponds to the visual representation of the specified glyph within this GlyphVector. The outline returned by this method is positioned around the origin of each individual glyph.

Parameters
ix the index into this GlyphVector
Returns
  • a Shape that is the outline of the glyph at the specified glyphIndex of this GlyphVector.

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

Returns a Shape whose interior corresponds to the visual representation of the specified glyph within this GlyphVector, offset to x, y. The outline returned by this method is positioned around the origin of each individual glyph.

Parameters
ix the index into this GlyphVector
x the X coordinate of the location of this GlyphVector
y the Y coordinate of the location of this GlyphVector
Returns
  • a Shape that is the outline of the glyph at the specified glyphIndex of this GlyphVector when rendered at the specified coordinates.

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

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. The renderFRC need not be the same as the FontRenderContext of this GlyphVector, and can be null. If it is null, the FontRenderContext of this GlyphVector is used. The default implementation returns the visual bounds of the glyph, offset to x, y and rounded out to the next integer value, and ignores the FRC. Subclassers should override this method.

Parameters
index the index of the glyph.
renderFRC the FontRenderContext of the Graphics.
x the X position at which to render this GlyphVector.
y the Y position at which to render this GlyphVector.
Returns
  • a Rectangle bounding the pixels that would be affected.

public Point2D getGlyphPosition (int ix)

Returns the position of the specified glyph relative to the origin of this GlyphVector. If glyphIndex equals the number of of glyphs in this GlyphVector, this method returns the position after the last glyph. This position is used to define the advance of the entire GlyphVector.

Parameters
ix the index into this GlyphVector
Returns
  • a Point2D object that is the position of the glyph at the specified glyphIndex.

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

Returns an array of glyph positions for the specified glyphs. This method is used for convenience and performance when processing glyph positions. If no array is passed in, a new array is created. Even numbered array entries beginning with position zero are the X coordinates of the glyph numbered beginGlyphIndex + position/2. Odd numbered array entries beginning with position one are the Y coordinates of the glyph numbered beginGlyphIndex + (position-1)/2. If beginGlyphIndex equals the number of of glyphs in this GlyphVector, this method gets the position after the last glyph and this position is used to define the advance of the entire GlyphVector.

Parameters
start the index at which to begin retrieving glyph positions
count the number of glyphs to retrieve
result the array that receives the glyph positions and is then returned.
Returns
  • an array of glyph positions specified by beginGlyphIndex and numEntries.

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. !!! should I bother taking result parameter?

public AffineTransform getGlyphTransform (int ix)

Returns the transform of the specified glyph within this GlyphVector. The transform is relative to the glyph position. If no special transform has been applied, null can be returned. A null return indicates an identity transform.

Parameters
ix the index into this GlyphVector
Returns
  • an AffineTransform that is the transform of the glyph at the specified glyphIndex.

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

Get transform information for the requested range of glyphs. If no glyphs have a transform, return null. If a glyph has no transform (or is the identity transform) its entry in the result array will be null. If the passed-in result is null an array will be allocated for the caller. Each transform instance in the result array will unique, and independent of the GlyphVector's transform.

public AffineTransform[] getGlyphTransforms ()

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

public Shape getGlyphVisualBounds (int ix)

Returns the visual bounds of the specified glyph within the GlyphVector. The bounds returned by this method is positioned around the origin of each individual glyph.

Parameters
ix the index into this GlyphVector that corresponds to the glyph from which to retrieve its visual bounds
Returns
  • a Shape that is the visual bounds of the glyph at the specified glyphIndex.

public int getLayoutFlags ()

Returns flags describing the global state of the GlyphVector. Flags not described below are reserved. The default implementation returns 0 (meaning false) for the position adjustments, transforms, rtl, and complex flags. Subclassers should override this method, and make sure it correctly describes the GlyphVector and corresponds to the results of related calls.

Returns
  • an int containing the flags describing the state

public Rectangle2D getLogicalBounds ()

Returns the logical bounds of this GlyphVector. This method is used when positioning this GlyphVector in relation to visually adjacent GlyphVector objects.

Returns
  • a Rectangle2D that is the logical bounds of this GlyphVector.

public int getNumGlyphs ()

Returns the number of glyphs in this GlyphVector.

Returns
  • number of glyphs in this GlyphVector.

public Shape getOutline ()

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

Returns
  • a Shape that is the outline of this GlyphVector.

public Shape getOutline (float x, float y)

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

Parameters
x the X coordinate of this GlyphVector.
y the Y coordinate of this GlyphVector.
Returns
  • a Shape that is the outline of this GlyphVector when rendered at the specified coordinates.

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

Returns the pixel bounds of this GlyphVector when rendered in a graphics with the given FontRenderContext at the given location. The renderFRC need not be the same as the FontRenderContext of this GlyphVector, and can be null. If it is null, the FontRenderContext of this GlyphVector is used. The default implementation returns the visual bounds, offset to x, y and rounded out to the next integer value (i.e. returns an integer rectangle which encloses the visual bounds) and ignores the FRC. Subclassers should override this method.

Parameters
renderFRC the FontRenderContext of the Graphics.
x the x-coordinate at which to render this GlyphVector.
y the y-coordinate at which to render this GlyphVector.
Returns
  • a Rectangle bounding the pixels that would be affected.

public static StandardGlyphVector getStandardGV (GlyphVector gv, FontInfo info)

public Rectangle2D getVisualBounds ()

Returns the visual bounds of this GlyphVector The visual bounds is the bounding box of the outline of this GlyphVector. Because of rasterization and alignment of pixels, it is possible that this box does not enclose all pixels affected by rendering this GlyphVector.

Returns
  • a Rectangle2D that is the bounding box of this GlyphVector.

public int hashCode ()

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

Returns
  • a hash code value for this object.

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

public void performDefaultLayout ()

Assigns default positions to each glyph in this GlyphVector. This can destroy information generated during initial layout of this GlyphVector.

public void pixellate (FontRenderContext renderFRC, Point2D loc, Point pxResult)

!!! not used currently, but might be by getPixelbounds?

public void setGlyphPosition (int ix, Point2D pos)

Sets the position of the specified glyph within this GlyphVector. If glyphIndex equals the number of of glyphs in this GlyphVector, this method sets the position after the last glyph. This position is used to define the advance of the entire GlyphVector.

Parameters
ix the index into this GlyphVector
pos the Point2D at which to position the glyph at the specified glyphIndex

public void setGlyphPositions (float[] srcPositions)

Set all the glyph positions, including the 'after last glyph' position. The srcPositions array must be of length (numGlyphs + 1) * 2.

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

public void setGlyphTransform (int ix, AffineTransform newTX)

Sets the transform of the specified glyph within this GlyphVector. The transform is relative to the glyph position. A null argument for newTX indicates that no special transform is applied for the specified glyph. This method can be used to rotate, mirror, translate and scale the glyph. Adding a transform can result in signifant performance changes.

Parameters
ix the index into this GlyphVector
newTX the new transform of the glyph at glyphIndex

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

Set a number of glyph transforms. Original transforms are unchanged. The array may contain nulls, and also may contain multiple references to the same transform instance.

public void setGlyphTransforms (AffineTransform[] srcTransforms)

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

public String toString ()

Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a string representation of the object.