org.apache.batik.gvt.renderer

Class StrokingTextPainter

public class StrokingTextPainter extends BasicTextPainter

More sophisticated implementation of TextPainter which renders the attributed character iterator of a TextNode. StrokingTextPainter includes support for stroke, fill, opacity, text-decoration, and other attributes.

See Also: TextPainter

Nested Class Summary
classStrokingTextPainter.TextRun
Inner convenience class for associating a TextLayout for sub-spans, and the ACI which iterates over that subspan.
Field Summary
static IntegerADJUST_ALL
static IntegerADJUST_SPACING
static GVTAttributedCharacterIterator.TextAttributeALT_GLYPH_HANDLER
static AttributeANCHOR_TYPE
static AttributeBIDI_LEVEL
static AttributeFLOW_PARAGRAPH
static AttributeFLOW_REGIONS
static AttributeGVT_FONT
static AttributeGVT_FONTS
static AttributePAINT_INFO
protected static TextPaintersingleton
A unique instance of this class.
static AttributeTEXTPATH
static AttributeTEXT_COMPOUND_ID
static AttributeWRITING_MODE
static IntegerWRITING_MODE_RTL
static IntegerWRITING_MODE_TTB
static AttributeXPOS
static AttributeYPOS
Method Summary
protected Point2DadjustChunkOffsets(Point2D location, List textRuns, StrokingTextPainter.TextChunk chunk)
Adjusts the position of the text runs within the specified text chunk to account for any text anchor properties.
ListcomputeTextRuns(TextNode node, AttributedCharacterIterator aci, AttributedCharacterIterator[] chunkACIs)
protected static AttributedCharacterIteratorcreateModifiedACIForFontMatching(AttributedCharacterIterator aci)
Returns a new AttributedCharacterIterator that contains resolved GVTFont attributes.
Rectangle2DgetBounds2D(TextNode node)
Get a Rectangle2D in userspace coords which encloses the textnode glyphs including stroke etc.
protected ShapegetDecorationOutline(List textRuns, int decorationType)
Returns the outline of the specified decoration type.
protected ShapegetDecorationStrokeOutline(List textRuns, int decorationType)
Returns the strokeed outline of the specified decoration type.
ShapegetHighlightShape(Mark beginMark, Mark endMark)
Return a Shape, in the coordinate system of the text layout, which encloses the text selection delineated by two Mark instances.
static TextPaintergetInstance()
Returns a unique instance of this class.
MarkgetMark(TextNode node, int index, boolean leadingEdge)
ShapegetOutline(TextNode node)
Get a Shape in userspace coords which defines the textnode glyph outlines.
int[]getSelected(Mark startMark, Mark finishMark)
Returns an array of ints representing begin/end index pairs into an AttributedCharacterIterator which represents the text selection delineated by two Mark instances.
protected StrokingTextPainter.TextChunkgetTextChunk(TextNode node, AttributedCharacterIterator aci, int[] charMap, List textRuns, StrokingTextPainter.TextChunk prevChunk)
protected AttributedCharacterIterator[]getTextChunkACIs(AttributedCharacterIterator aci)
Returns an array of ACIs, one for each text chunk within the given text node.
ListgetTextRuns(TextNode node, AttributedCharacterIterator aci)
protected MarkhitTest(double x, double y, TextNode node)
voidpaint(TextNode node, Graphics2D g2d)
Paints the specified text node using the specified Graphics2D.
protected voidpaintDecorations(List textRuns, Graphics2D g2d, int decorationType)
Paints decorations of the specified type.
protected voidpaintTextRuns(List textRuns, Graphics2D g2d)
Paints the text in each text run.
protected voidprintAttrs(AttributedCharacterIterator aci)
MarkselectFirst(TextNode node)
Selects the first glyph in the text node.
MarkselectLast(TextNode node)
Selects the last glyph in the text node.

Field Detail

ADJUST_ALL

public static final Integer ADJUST_ALL

ADJUST_SPACING

public static final Integer ADJUST_SPACING

ALT_GLYPH_HANDLER

public static final GVTAttributedCharacterIterator.TextAttribute ALT_GLYPH_HANDLER

ANCHOR_TYPE

public static final Attribute ANCHOR_TYPE

BIDI_LEVEL

public static final Attribute BIDI_LEVEL

FLOW_PARAGRAPH

public static final Attribute FLOW_PARAGRAPH

FLOW_REGIONS

public static final Attribute FLOW_REGIONS

GVT_FONT

public static final Attribute GVT_FONT

GVT_FONTS

public static final Attribute GVT_FONTS

PAINT_INFO

public static final Attribute PAINT_INFO

singleton

protected static TextPainter singleton
A unique instance of this class.

TEXTPATH

public static final Attribute TEXTPATH

TEXT_COMPOUND_ID

public static final Attribute TEXT_COMPOUND_ID

WRITING_MODE

public static final Attribute WRITING_MODE

WRITING_MODE_RTL

public static final Integer WRITING_MODE_RTL

WRITING_MODE_TTB

public static final Integer WRITING_MODE_TTB

XPOS

public static final Attribute XPOS

YPOS

public static final Attribute YPOS

Method Detail

adjustChunkOffsets

protected Point2D adjustChunkOffsets(Point2D location, List textRuns, StrokingTextPainter.TextChunk chunk)
Adjusts the position of the text runs within the specified text chunk to account for any text anchor properties.

computeTextRuns

public List computeTextRuns(TextNode node, AttributedCharacterIterator aci, AttributedCharacterIterator[] chunkACIs)

createModifiedACIForFontMatching

protected static AttributedCharacterIterator createModifiedACIForFontMatching(AttributedCharacterIterator aci)
Returns a new AttributedCharacterIterator that contains resolved GVTFont attributes. This is then used when creating the text runs so that the text can be split on changes of font as well as tspans and trefs.

Parameters: aci The aci to be modified should already be split into text chunks.

Returns: The new modified aci.

getBounds2D

public Rectangle2D getBounds2D(TextNode node)
Get a Rectangle2D in userspace coords which encloses the textnode glyphs including stroke etc.

getDecorationOutline

protected Shape getDecorationOutline(List textRuns, int decorationType)
Returns the outline of the specified decoration type.

Parameters: textRuns The list of text runs to get the decoration outline for. decorationType Indicates the type of decoration required. eg. underline, overline or strikethrough.

Returns: The decoration outline or null if the text is not decorated.

getDecorationStrokeOutline

protected Shape getDecorationStrokeOutline(List textRuns, int decorationType)
Returns the strokeed outline of the specified decoration type. If the decoration has no stroke it will return the fill outline

Parameters: textRuns The list of text runs to get the decoration outline for. decorationType Indicates the type of decoration required. eg. underline, overline or strikethrough.

Returns: The decoration outline or null if the text is not decorated.

getHighlightShape

public Shape getHighlightShape(Mark beginMark, Mark endMark)
Return a Shape, in the coordinate system of the text layout, which encloses the text selection delineated by two Mark instances. Note: The Mark instances passed must have been instantiated by an instance of this enclosing TextPainter implementation.

getInstance

public static TextPainter getInstance()
Returns a unique instance of this class.

getMark

public Mark getMark(TextNode node, int index, boolean leadingEdge)

getOutline

public Shape getOutline(TextNode node)
Get a Shape in userspace coords which defines the textnode glyph outlines.

Parameters: node the TextNode to measure

getSelected

public int[] getSelected(Mark startMark, Mark finishMark)
Returns an array of ints representing begin/end index pairs into an AttributedCharacterIterator which represents the text selection delineated by two Mark instances. Note: The Mark instances passed must have been instantiated by an instance of this enclosing TextPainter implementation.

getTextChunk

protected StrokingTextPainter.TextChunk getTextChunk(TextNode node, AttributedCharacterIterator aci, int[] charMap, List textRuns, StrokingTextPainter.TextChunk prevChunk)

getTextChunkACIs

protected AttributedCharacterIterator[] getTextChunkACIs(AttributedCharacterIterator aci)
Returns an array of ACIs, one for each text chunk within the given text node.

getTextRuns

public List getTextRuns(TextNode node, AttributedCharacterIterator aci)

hitTest

protected Mark hitTest(double x, double y, TextNode node)

paint

public void paint(TextNode node, Graphics2D g2d)
Paints the specified text node using the specified Graphics2D.

Parameters: node the text node to paint g2d the Graphics2D to use

paintDecorations

protected void paintDecorations(List textRuns, Graphics2D g2d, int decorationType)
Paints decorations of the specified type.

paintTextRuns

protected void paintTextRuns(List textRuns, Graphics2D g2d)
Paints the text in each text run. Decorations are not painted here.

printAttrs

protected void printAttrs(AttributedCharacterIterator aci)

selectFirst

public Mark selectFirst(TextNode node)
Selects the first glyph in the text node.

selectLast

public Mark selectLast(TextNode node)
Selects the last glyph in the text node.
Copyright B) 2008 Apache Software Foundation. All Rights Reserved.