org.apache.batik.gvt.text

Class GlyphLayout

public class GlyphLayout extends Object implements TextSpanLayout

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

See Also:

Field Summary
static doubleeps
static AttributeFLOW_EMPTY_PARAGRAPH
static AttributeFLOW_LINE_BREAK
static AttributeFLOW_PARAGRAPH
static AttributeGVT_FONT
static AttributeHORIZONTAL_ORIENTATION_ANGLE
static AttributeLINE_HEIGHT
protected static SetrunAtts
protected static SetszAtts
static AttributeVERTICAL_ORIENTATION
static AttributeVERTICAL_ORIENTATION_ANGLE
Constructor Summary
GlyphLayout(AttributedCharacterIterator aci, int[] charMap, Point2D offset, FontRenderContext frc)
Creates the specified text layout using the specified AttributedCharacterIterator and rendering context.
Method Summary
static voidaddPtsToPath(GeneralPath shape, Float[] topPts, Float[] botPts, int numPts)
protected voidadjustTextSpacing()
Does any spacing adjustments that may have been specified.
protected voidapplyStretchTransform(boolean stretchGlyphs)
Stretches the text so that it becomes the specified length.
protected voiddoExplicitGlyphLayout()
Explicitly lays out each of the glyphs in the glyph vector.
protected voiddoPathLayout()
If this layout is on a text path, positions the characters along the path.
protected Point2DdoSpacing(Float kern, Float letterSpacing, Float wordSpacing)
Performs any spacing adjustments required and returns the new advance value.
voiddraw(Graphics2D g2d)
Paints the text layout using the specified Graphics2D and rendering context.
static booleanepsEQ(double a, double b)
Point2DgetAdvance2D()
Returns the current text position at the completion of glyph layout.
Rectangle2DgetBounds2D()
Returns the rectangular bounds of the completed glyph layout.
intgetCharacterCount(int startGlyphIndex, int endGlyphIndex)
Returns the number of chars represented by the glyphs within the specified range.
doublegetComputedOrientationAngle(int index)
Return the angle value according to the orientation of the character.
ShapegetDecorationOutline(int decorationType)
Returns the outline of the specified decorations on the glyphs,
protected GVTFontgetFont()
Returns the GVTFont to use when rendering the specified character iterator.
Rectangle2DgetGeometricBounds()
Returns the rectangular bounds of the completed glyph layout, inclusive of "decoration" (underline, overline, etc.)
float[]getGlyphAdvances()
intgetGlyphCount()
Returns the number of glyphs in this layout.
intgetGlyphIndex(int charIndex)
Returns the index of the first glyph that has the specified char index.
GVTGlyphMetricsgetGlyphMetrics(int glyphIndex)
protected intgetGlyphOrientationAngle()
Returns the value of the vertical glyph orientation angle.
GVTGlyphVectorgetGlyphVector()
ShapegetHighlightShape(int beginCharIndex, int endCharIndex)
Returns a Shape which encloses the currently selected glyphs as specified by the character indices.
intgetLastGlyphIndex(int charIndex)
Returns the index of the last glyph that has the specified char index.
GVTLineMetricsgetLineMetrics()
Point2DgetOffset()
Returns the current text position at the beginning of glyph layout, before the application of explicit glyph positioning attributes.
ShapegetOutline()
Returns the outline of the completed glyph layout.
protected ShapegetOverlineShape()
Returns a shape describing the overline decoration for a given ACI.
protected ShapegetStrikethroughShape()
Returns a shape describing the strikethrough line for a given ACI.
Point2DgetTextPathAdvance()
Returns the position to used when drawing a text run after this one.
protected ShapegetUnderlineShape()
Returns a shape describing the undeline decoration for a given ACI.
booleanhasCharacterIndex(int index)
Return true is the character index is represented by glyphs in this layout.
TextHithitTestChar(float x, float y)
Perform hit testing for coordinate at x, y.
booleanisAltGlyph()
Return true if this text run represents an alt glyph.
protected booleanisGlyphOrientationAuto()
Returns whether or not the vertical glyph orientation value is "auto".
protected booleanisLatinChar(char c)
Returns true if the specified character is within one of the Latin unicode character blocks.
booleanisLeftToRight()
Returns true if the text direction in this layout is from left to right.
booleanisOnATextPath()
Returns true if this layout in on a text path.
booleanisVertical()
Returns true if the advance direction of this text is vertical.
static intmakeConvexHull(Float[] pts, int numPts)
static voidmergeAreas(GeneralPath shape, Area[] shapes, int nShapes)
voidsetOffset(Point2D offset)
Sets the text position used for the implicit origin of glyph layout.
voidsetScale(float xScale, float yScale, boolean adjSpacing)
Sets the scaling factor to use for string. if ajdSpacing is true then only the spacing between glyphs will be adjusted otherwise the glyphs and the spaces between them will be adjusted.

Field Detail

eps

public static final double eps

FLOW_EMPTY_PARAGRAPH

public static final Attribute FLOW_EMPTY_PARAGRAPH

FLOW_LINE_BREAK

public static final Attribute FLOW_LINE_BREAK

FLOW_PARAGRAPH

public static final Attribute FLOW_PARAGRAPH

GVT_FONT

public static final Attribute GVT_FONT

HORIZONTAL_ORIENTATION_ANGLE

public static final Attribute HORIZONTAL_ORIENTATION_ANGLE

LINE_HEIGHT

public static final Attribute LINE_HEIGHT

runAtts

protected static Set runAtts

szAtts

protected static Set szAtts

VERTICAL_ORIENTATION

public static final Attribute VERTICAL_ORIENTATION

VERTICAL_ORIENTATION_ANGLE

public static final Attribute VERTICAL_ORIENTATION_ANGLE

Constructor Detail

GlyphLayout

public GlyphLayout(AttributedCharacterIterator aci, int[] charMap, Point2D offset, 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

addPtsToPath

public static void addPtsToPath(GeneralPath shape, Float[] topPts, Float[] botPts, int numPts)

adjustTextSpacing

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

applyStretchTransform

protected void applyStretchTransform(boolean stretchGlyphs)
Stretches the text so that it becomes the specified length.

Parameters: stretchGlyphs if true xScale, yScale will be applied to each glyphs transform.

doExplicitGlyphLayout

protected void doExplicitGlyphLayout()
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.

doPathLayout

protected void doPathLayout()
If this layout is on a text path, positions the characters along the path.

doSpacing

protected Point2D doSpacing(Float kern, Float letterSpacing, 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.

draw

public void draw(Graphics2D g2d)
Paints the text layout using the specified Graphics2D and rendering context.

Parameters: g2d the Graphics2D to use

epsEQ

public static boolean epsEQ(double a, double b)

getAdvance2D

public Point2D getAdvance2D()
Returns the current text position at the completion of glyph layout.

getBounds2D

public Rectangle2D getBounds2D()
Returns the rectangular bounds of the completed glyph layout.

getCharacterCount

public int getCharacterCount(int startGlyphIndex, int endGlyphIndex)
Returns the number of chars represented by the glyphs within the specified range.

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.

getComputedOrientationAngle

public double getComputedOrientationAngle(int index)
Return the angle value according to the orientation of the character.

getDecorationOutline

public Shape getDecorationOutline(int decorationType)
Returns the outline of the specified decorations on the glyphs,

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

getFont

protected GVTFont getFont()
Returns the GVTFont to use when rendering the specified character iterator. This should already be set as an attribute on the aci.

Returns: The GVTFont to use.

getGeometricBounds

public Rectangle2D getGeometricBounds()
Returns the rectangular bounds of the completed glyph layout, inclusive of "decoration" (underline, overline, etc.)

getGlyphAdvances

public float[] getGlyphAdvances()

getGlyphCount

public int getGlyphCount()
Returns the number of glyphs in this layout.

getGlyphIndex

public int getGlyphIndex(int charIndex)
Returns the index of the first glyph that has the specified char index.

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.

getGlyphMetrics

public GVTGlyphMetrics getGlyphMetrics(int glyphIndex)

getGlyphOrientationAngle

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

getGlyphVector

public GVTGlyphVector getGlyphVector()

getHighlightShape

public Shape getHighlightShape(int beginCharIndex, int endCharIndex)
Returns a Shape which encloses the currently selected glyphs as specified by the character indices.

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.

getLastGlyphIndex

public int getLastGlyphIndex(int charIndex)
Returns the index of the last glyph that has the specified char index.

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.

getLineMetrics

public GVTLineMetrics getLineMetrics()

getOffset

public Point2D getOffset()
Returns the current text position at the beginning of glyph layout, before the application of explicit glyph positioning attributes.

getOutline

public Shape getOutline()
Returns the outline of the completed glyph layout.

getOverlineShape

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

getStrikethroughShape

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

getTextPathAdvance

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

getUnderlineShape

protected Shape getUnderlineShape()
Returns a shape describing the undeline decoration for a given ACI.

hasCharacterIndex

public boolean hasCharacterIndex(int index)
Return true is the character index is represented by glyphs in this layout.

Parameters: index index of the character in the ACI.

Returns: true if the layout represents that character.

hitTestChar

public TextHit hitTestChar(float x, float y)
Perform hit testing for coordinate at x, y.

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.

isAltGlyph

public boolean isAltGlyph()
Return true if this text run represents an alt glyph.

isGlyphOrientationAuto

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

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.

isLeftToRight

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

isOnATextPath

public boolean isOnATextPath()
Returns true if this layout in on a text path.

isVertical

public boolean isVertical()
Returns true if the advance direction of this text is vertical.

makeConvexHull

public static int makeConvexHull(Float[] pts, int numPts)

mergeAreas

public static void mergeAreas(GeneralPath shape, Area[] shapes, int nShapes)

setOffset

public void setOffset(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).

setScale

public void setScale(float xScale, float yScale, boolean adjSpacing)
Sets the scaling factor to use for string. if ajdSpacing is true then only the spacing between glyphs will be adjusted otherwise the glyphs and the spaces between them will be adjusted. Only the scale factor in the progression direction is used (x for horizontal text, y for vertical text ).

Parameters: xScale Scale factor to apply in X direction. yScale Scale factor to apply in Y direction. adjSpacing True if only spaces should be adjusted.

Copyright B) 2008 Apache Software Foundation. All Rights Reserved.