org.apache.fop.render.ps

Class PSTextPainter

Implemented Interfaces:
TextPainter

public class PSTextPainter
extends java.lang.Object
implements TextPainter

Renders the attributed character iterator of a TextNode. This class draws the text directly into the PSGraphics2D so that the text is not drawn using shapes which makes the PS files larger. If the text is simple enough to draw then it sets the font and calls drawString. If the text is complex or the cannot be translated into a simple drawString the StrokingTextPainter is used instead. (todo) handle underline, overline and strikethrough (todo) use drawString(AttributedCharacterIterator iterator...) for some
Version:
$Id: PSTextPainter.java 542237 2007-05-28 14:31:24Z jeremias $
Author:
Keiron Liddle

Field Summary

protected static TextPainter
PROXY_PAINTER
Use the stroking text painter to get the bounds and shape.
protected Log
log
the logger for this class

Constructor Summary

PSTextPainter(NativeTextHandler nativeTextHandler)
Create a new PS text painter with the given font information.

Method Summary

Rectangle2D
getBounds2D(TextNode node)
Get the bounds.
Rectangle2D
getGeometryBounds(TextNode node)
Get the geometry bounds.
Shape
getHighlightShape(Mark beginMark, Mark endMark)
Get the highlighted shape.
Mark
getMark(TextNode node, int pos, boolean all)
Get the mark.
Shape
getOutline(TextNode node)
Get the outline shape of the text characters.
int[]
getSelected(Mark start, Mark finish)
Get selected.
protected String
getText(AttributedCharacterIterator aci)
Extract the raw text from an ACI.
void
paint(TextNode node, Graphics2D g2d)
Paints the specified attributed character iterator using the specified Graphics2D and context and font context.
protected Point2D
paintACI(AttributedCharacterIterator aci, Graphics2D g2d, Point2D loc)
Paint an ACI on a Graphics2D at a given location.
protected Point2D
paintTextRun(StrokingTextPainter.TextRun run, Graphics2D g2d, Point2D loc)
Paint a single text run on the Graphics2D at a given location.
protected void
paintTextRuns(List textRuns, Graphics2D g2d, Point2D loc)
Paint a list of text runs on the Graphics2D at a given location.
Mark
selectAt(double x, double y, TextNode node)
Select at.
Mark
selectFirst(TextNode node)
Selec first.
Mark
selectLast(TextNode node)
Select last.
Mark
selectTo(double x, double y, Mark beginMark)
Select to.

Field Details

PROXY_PAINTER

protected static final TextPainter PROXY_PAINTER
Use the stroking text painter to get the bounds and shape. Also used as a fallback to draw the string with strokes.

log

protected Log log
the logger for this class

Constructor Details

PSTextPainter

public PSTextPainter(NativeTextHandler nativeTextHandler)
Create a new PS text painter with the given font information.
Parameters:
nativeTextHandler - the NativeTextHandler instance used for text painting

Method Details

getBounds2D

public Rectangle2D getBounds2D(TextNode node)
Get the bounds. This uses the StrokingTextPainter to get the bounds since in theory it should be the same.
Parameters:
node - the text node
Returns:
the bounds of the text

getGeometryBounds

public Rectangle2D getGeometryBounds(TextNode node)
Get the geometry bounds. This uses the StrokingTextPainter to get the bounds since in theory it should be the same.
Parameters:
node - the text node
Returns:
the bounds of the text

getHighlightShape

public Shape getHighlightShape(Mark beginMark,
                               Mark endMark)
Get the highlighted shape. This does nothing since the output is pdf and not interactive.
Parameters:
beginMark - the start mark
endMark - the end mark
Returns:
null

getMark

public Mark getMark(TextNode node,
                    int pos,
                    boolean all)
Get the mark. This does nothing since the output is pdf and not interactive.
Parameters:
node - the text node
pos - the position
all - select all
Returns:
null

getOutline

public Shape getOutline(TextNode node)
Get the outline shape of the text characters. This uses the StrokingTextPainter to get the outline shape since in theory it should be the same.
Parameters:
node - the text node
Returns:
the outline shape of the text characters

getSelected

public int[] getSelected(Mark start,
                         Mark finish)
Get selected. This does nothing since the output is pdf and not interactive.
Parameters:
start - the start mark
finish - the finish mark
Returns:
null

getText

protected String getText(AttributedCharacterIterator aci)
Extract the raw text from an ACI.
Parameters:
aci - ACI to inspect
Returns:
the extracted text

paint

public void paint(TextNode node,
                  Graphics2D g2d)
Paints the specified attributed character iterator using the specified Graphics2D and context and font context.
Parameters:
node - the TextNode to paint
g2d - the Graphics2D to use

paintACI

protected Point2D paintACI(AttributedCharacterIterator aci,
                           Graphics2D g2d,
                           Point2D loc)
Paint an ACI on a Graphics2D at a given location. The method has to update the location after painting.
Parameters:
aci - ACI to paint
g2d - Graphics2D to paint on
loc - start location
Returns:
new current location

paintTextRun

protected Point2D paintTextRun(StrokingTextPainter.TextRun run,
                               Graphics2D g2d,
                               Point2D loc)
Paint a single text run on the Graphics2D at a given location.
Parameters:
run - the text run to paint
g2d - the Graphics2D to paint to
loc - the current location of the "cursor"
Returns:
the new location of the "cursor" after painting the text run

paintTextRuns

protected void paintTextRuns(List textRuns,
                             Graphics2D g2d,
                             Point2D loc)
Paint a list of text runs on the Graphics2D at a given location.
Parameters:
textRuns - the list of text runs
g2d - the Graphics2D to paint to
loc - the current location of the "cursor"

selectAt

public Mark selectAt(double x,
                     double y,
                     TextNode node)
Select at. This does nothing since the output is pdf and not interactive.
Parameters:
x - the x position
y - the y position
node - the text node
Returns:
null

selectFirst

public Mark selectFirst(TextNode node)
Selec first. This does nothing since the output is pdf and not interactive.
Parameters:
node - the text node
Returns:
null

selectLast

public Mark selectLast(TextNode node)
Select last. This does nothing since the output is pdf and not interactive.
Parameters:
node - the text node
Returns:
null

selectTo

public Mark selectTo(double x,
                     double y,
                     Mark beginMark)
Select to. This does nothing since the output is pdf and not interactive.
Parameters:
x - the x position
y - the y position
beginMark - the start mark
Returns:
null

Copyright 1999-2007 The Apache Software Foundation. All Rights Reserved.