org.apache.batik.gvt.text
Class GlyphLayout

java.lang.Object
  |
  +--org.apache.batik.gvt.text.GlyphLayout
All Implemented Interfaces:
TextSpanLayout

public class GlyphLayout
extends java.lang.Object
implements TextSpanLayout

Implementation of TextSpanLayout which uses java.awt.font.GlyphVector.

See Also:
TextSpanLayout

Field Summary
static float eps
           
 
Fields inherited from interface org.apache.batik.gvt.text.TextSpanLayout
DECORATION_ALL, DECORATION_OVERLINE, DECORATION_STRIKETHROUGH, DECORATION_UNDERLINE
 
Constructor Summary
GlyphLayout(java.text.AttributedCharacterIterator aci, int[] charMap, java.awt.geom.Point2D offset, java.awt.font.FontRenderContext frc)
          Creates the specified text layout using the specified AttributedCharacterIterator and rendering context.
 
Method Summary
static void addPtsToPath(java.awt.geom.GeneralPath shape, java.awt.geom.Point2D.Float[] topPts, java.awt.geom.Point2D.Float[] botPts, int numPts)
           
protected  void adjustTextSpacing()
          Does any spacing adjustments that may have been specified.
protected  void applySpacingParams(java.lang.Float length, java.lang.Integer lengthAdjust, java.lang.Float kern, java.lang.Float letterSpacing, java.lang.Float wordSpacing)
          Adjusts the spacing according to the specified parameters.
protected  void applyStretchTransform(java.lang.Float length)
          Stretches the text so that it becomes the specified length.
protected  void doExplicitGlyphLayout(boolean applyOffset)
          Explicitly lays out each of the glyphs in the glyph vector.
protected  void doPathLayout(boolean offsetApplied)
          If this layout is on a text path, positions the characters along the path.
protected  java.awt.geom.Point2D doSpacing(java.lang.Float kern, java.lang.Float letterSpacing, java.lang.Float wordSpacing)
          Performs any spacing adjustments required and returns the new advance value.
 void draw(java.awt.Graphics2D g2d)
          Paints the text layout using the specified Graphics2D and rendering context.
 java.awt.geom.Point2D getAdvance2D()
          Returns the current text position at the completion of glyph layout.
 java.awt.geom.Rectangle2D getBounds()
          Returns the rectangular bounds of the completed glyph layout.
 int getCharacterCount(int startGlyphIndex, int endGlyphIndex)
          Returns the number of chars represented by the glyphs within the specified range.
 java.awt.geom.Rectangle2D getDecoratedBounds()
          Returns the rectangular bounds of the completed glyph layout, inclusive of "decoration" (underline, overline, etc.)
 java.awt.Shape getDecorationOutline(int decorationType)
          Returns the outline of the specified decorations on the glyphs,
protected  GVTFont getFont(java.text.AttributedCharacterIterator aci)
          Returns the GVTFont to use when rendering the specified character iterator.
 int getGlyphCount()
          Returns the number of glyphs in this layout.
 int getGlyphIndex(int charIndex)
          Returns the index of the glyph that has the specified char index.
protected  int getGlyphOrientationAngle()
          Returns the value of the vertical glyph orientation angle.
 java.awt.Shape getHighlightShape(int beginCharIndex, int endCharIndex)
          Returns a Shape which encloses the currently selected glyphs as specified by the character indices.
 java.awt.geom.Point2D getOffset()
          Returns the current text position at the beginning of glyph layout, before the application of explicit glyph positioning attributes.
 java.awt.Shape getOutline()
          Returns the outline of the completed glyph layout.
protected  java.awt.Shape getOverlineShape()
          Returns a shape describing the overline decoration for a given ACI.
protected  java.awt.Shape getStrikethroughShape()
          Returns a shape describing the strikethrough line for a given ACI.
 java.awt.geom.Point2D getTextPathAdvance()
          Returns the position to used when drawing a text run after this one.
protected  java.awt.Shape getUnderlineShape()
          Returns a shape describing the strikethrough line for a given ACI.
 TextHit hitTestChar(float x, float y)
          Perform hit testing for coordinate at x, y.
protected  boolean isGlyphOrientationAuto()
          Returns whether or not the vertical glyph orientation value is "auto".
protected  boolean isLatinChar(char c)
          Returns true if the specified character is within one of the Latin unicode character blocks.
 boolean isLeftToRight()
          Returns true if the text direction in this layout is from left to right.
 boolean isOnATextPath()
          Returns true if this layout in on a text path.
 boolean isVertical()
          Returns true if the advance direction of this text is vertical.
static int makeConvexHull(java.awt.geom.Point2D.Float[] pts, int numPts)
           
static void mergeAreas(java.awt.geom.GeneralPath shape, java.awt.geom.Area[] shapes, int nShapes)
           
protected  void rescaleSpacing(float xscale, float yscale)
          Rescales the spacing between each char by the specified scale factors.
 void setOffset(java.awt.geom.Point2D offset)
          Sets the text position used for the implicit origin of glyph layout.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eps

public static final float eps
Constructor Detail

GlyphLayout

public GlyphLayout(java.text.AttributedCharacterIterator aci,
                   int[] charMap,
                   java.awt.geom.Point2D offset,
                   java.awt.font.FontRenderContext frc)
Creates the specified text layout using the specified AttributedCharacterIterator and rendering context.
Parameters:
aci - the AttributedCharacterIterator whose text is to be laid out
charMap - Indicates how chars in aci map to original text char array.
offset - The offset position of this text layout
frc - the FontRenderContext to use for generating glyphs.
Method Detail

draw

public void draw(java.awt.Graphics2D g2d)
Paints the text layout using the specified Graphics2D and rendering context.
Specified by:
draw in interface TextSpanLayout
Parameters:
g2d - the Graphics2D to use
context - The current render context

getOutline

public java.awt.Shape getOutline()
Returns the outline of the completed glyph layout.
Specified by:
getOutline in interface TextSpanLayout

getOffset

public java.awt.geom.Point2D getOffset()
Returns the current text position at the beginning of glyph layout, before the application of explicit glyph positioning attributes.
Specified by:
getOffset in interface TextSpanLayout

setOffset

public void setOffset(java.awt.geom.Point2D offset)
Sets the text position used for the implicit origin of glyph layout. Ignored if multiple explicit glyph positioning attributes are present in ACI (e.g. if the aci has multiple X or Y values).
Specified by:
setOffset in interface TextSpanLayout

getDecorationOutline

public java.awt.Shape getDecorationOutline(int decorationType)
Returns the outline of the specified decorations on the glyphs,
Specified by:
getDecorationOutline in interface TextSpanLayout
Parameters:
decorationType - an integer indicating the type(s) of decorations included in this shape. May be the result of "OR-ing" several values together: e.g. DECORATION_UNDERLINE | DECORATION_STRIKETHROUGH

getBounds

public java.awt.geom.Rectangle2D getBounds()
Returns the rectangular bounds of the completed glyph layout.
Specified by:
getBounds in interface TextSpanLayout

getDecoratedBounds

public java.awt.geom.Rectangle2D getDecoratedBounds()
Returns the rectangular bounds of the completed glyph layout, inclusive of "decoration" (underline, overline, etc.)
Specified by:
getDecoratedBounds in interface TextSpanLayout

getAdvance2D

public java.awt.geom.Point2D getAdvance2D()
Returns the current text position at the completion of glyph layout.
Specified by:
getAdvance2D in interface TextSpanLayout

getTextPathAdvance

public java.awt.geom.Point2D getTextPathAdvance()
Returns the position to used when drawing a text run after this one. It takes into account the text path layout if there is one.
Specified by:
getTextPathAdvance in interface TextSpanLayout

getGlyphIndex

public int getGlyphIndex(int charIndex)
Returns the index of the glyph that has the specified char index.
Specified by:
getGlyphIndex in interface TextSpanLayout
Parameters:
charIndex - The original index of the character in the text node's text string.
Returns:
The index of the matching glyph in this layout's glyph vector, or -1 if a matching glyph could not be found.

getHighlightShape

public java.awt.Shape getHighlightShape(int beginCharIndex,
                                        int endCharIndex)
Returns a Shape which encloses the currently selected glyphs as specified by the character indices.
Specified by:
getHighlightShape in interface TextSpanLayout
Parameters:
beginCharIndex - the index of the first char in the contiguous selection.
endCharIndex - the index of the last char in the contiguous selection.
Returns:
The highlight shape or null if the spacified char range does not overlap with the chars in this layout.

makeConvexHull

public static int makeConvexHull(java.awt.geom.Point2D.Float[] pts,
                                 int numPts)

addPtsToPath

public static void addPtsToPath(java.awt.geom.GeneralPath shape,
                                java.awt.geom.Point2D.Float[] topPts,
                                java.awt.geom.Point2D.Float[] botPts,
                                int numPts)

mergeAreas

public static void mergeAreas(java.awt.geom.GeneralPath shape,
                              java.awt.geom.Area[] shapes,
                              int nShapes)

hitTestChar

public TextHit hitTestChar(float x,
                           float y)
Perform hit testing for coordinate at x, y.
Specified by:
hitTestChar in interface TextSpanLayout
Parameters:
x - the x coordinate of the point to be tested.
y - the y coordinate of the point to be tested.
Returns:
a TextHit object encapsulating the character index for successful hits and whether the hit is on the character leading edge.

isVertical

public boolean isVertical()
Returns true if the advance direction of this text is vertical.
Specified by:
isVertical in interface TextSpanLayout

isOnATextPath

public boolean isOnATextPath()
Returns true if this layout in on a text path.
Specified by:
isOnATextPath in interface TextSpanLayout

getGlyphCount

public int getGlyphCount()
Returns the number of glyphs in this layout.
Specified by:
getGlyphCount in interface TextSpanLayout

getCharacterCount

public int getCharacterCount(int startGlyphIndex,
                             int endGlyphIndex)
Returns the number of chars represented by the glyphs within the specified range.
Specified by:
getCharacterCount in interface TextSpanLayout
Parameters:
startGlyphIndex - The index of the first glyph in the range.
endGlyphIndex - The index of the last glyph in the range.
Returns:
The number of chars.

isLeftToRight

public boolean isLeftToRight()
Returns true if the text direction in this layout is from left to right.
Specified by:
isLeftToRight in interface TextSpanLayout

getOverlineShape

protected java.awt.Shape getOverlineShape()
Returns a shape describing the overline decoration for a given ACI.

getUnderlineShape

protected java.awt.Shape getUnderlineShape()
Returns a shape describing the strikethrough line for a given ACI.

getStrikethroughShape

protected java.awt.Shape getStrikethroughShape()
Returns a shape describing the strikethrough line for a given ACI.

getFont

protected GVTFont getFont(java.text.AttributedCharacterIterator aci)
Returns the GVTFont to use when rendering the specified character iterator. This should already be set as an attribute on the aci.
Parameters:
aci - The character iterator to get the font attribute from.
Returns:
The GVTFont to use.

doPathLayout

protected void doPathLayout(boolean offsetApplied)
If this layout is on a text path, positions the characters along the path.
Parameters:
offsetApplied - Indicates whether or not the text position offset has already been applied.

adjustTextSpacing

protected void adjustTextSpacing()
Does any spacing adjustments that may have been specified.

applyStretchTransform

protected void applyStretchTransform(java.lang.Float length)
Stretches the text so that it becomes the specified length.
Parameters:
length - The required length of the text.

applySpacingParams

protected void applySpacingParams(java.lang.Float length,
                                  java.lang.Integer lengthAdjust,
                                  java.lang.Float kern,
                                  java.lang.Float letterSpacing,
                                  java.lang.Float wordSpacing)
Adjusts the spacing according to the specified parameters.
Parameters:
length - The required text length.
lengthAdjust - Indicates the method to use when adjusting the text length.
kern - The kerning adjustment to apply to the space between each char.
letterSpacing - The amount of spacing required between each char.
wordSpacing - The amount of spacing required between each word.

doSpacing

protected java.awt.geom.Point2D doSpacing(java.lang.Float kern,
                                          java.lang.Float letterSpacing,
                                          java.lang.Float wordSpacing)
Performs any spacing adjustments required and returns the new advance value.
Parameters:
kern - The kerning adjustment to apply to the space between each char.
letterSpacing - The amount of spacing required between each char.
wordSpacing - The amount of spacing required between each word.

rescaleSpacing

protected void rescaleSpacing(float xscale,
                              float yscale)
Rescales the spacing between each char by the specified scale factors.
Parameters:
xscale - The amount to scale in the x direction.
yscale - The amount to scale in the y direction.

isLatinChar

protected boolean isLatinChar(char c)
Returns true if the specified character is within one of the Latin unicode character blocks.
Parameters:
c - The char to test.
Returns:
True if c is latin.

isGlyphOrientationAuto

protected boolean isGlyphOrientationAuto()
Returns whether or not the vertical glyph orientation value is "auto".

getGlyphOrientationAngle

protected int getGlyphOrientationAngle()
Returns the value of the vertical glyph orientation angle. This will be one of 0, 90, 180 or 270.

doExplicitGlyphLayout

protected void doExplicitGlyphLayout(boolean applyOffset)
Explicitly lays out each of the glyphs in the glyph vector. This will handle any glyph position adjustments such as dx, dy and baseline offsets. It will also handle vertical layouts.
Parameters:
applyOffset - Specifies whether or not to add the offset position to each of the glyph positions.


Copyright © 2001 Apache Software Foundation. All Rights Reserved.