fop 0.95

org.apache.fop.render.ps
Class PSTextPainter

java.lang.Object
  extended by org.apache.fop.render.ps.PSTextPainter
All Implemented Interfaces:
org.apache.batik.gvt.TextPainter

public class PSTextPainter
extends java.lang.Object
implements org.apache.batik.gvt.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 603590 2007-12-12 12:24:10Z acumiskey $
Author:
Keiron Liddle

Field Summary
protected  org.apache.commons.logging.Log log
          the logger for this class
protected static org.apache.batik.gvt.TextPainter PROXY_PAINTER
          Use the stroking text painter to get the bounds and shape.
 
Constructor Summary
PSTextPainter(NativeTextHandler nativeTextHandler)
          Create a new PS text painter with the given font information.
 
Method Summary
protected  void drawPrimitiveString(java.awt.Graphics2D g2d, java.awt.geom.Point2D loc, Font font, java.lang.String txt, float tx)
           
 java.awt.geom.Rectangle2D getBounds2D(org.apache.batik.gvt.TextNode node)
          Get the bounds.
 java.awt.geom.Rectangle2D getGeometryBounds(org.apache.batik.gvt.TextNode node)
          Get the geometry bounds.
 java.awt.Shape getHighlightShape(org.apache.batik.gvt.text.Mark beginMark, org.apache.batik.gvt.text.Mark endMark)
          Get the highlighted shape.
 org.apache.batik.gvt.text.Mark getMark(org.apache.batik.gvt.TextNode node, int pos, boolean all)
          Get the mark.
 java.awt.Shape getOutline(org.apache.batik.gvt.TextNode node)
          Get the outline shape of the text characters.
 int[] getSelected(org.apache.batik.gvt.text.Mark start, org.apache.batik.gvt.text.Mark finish)
          Get selected.
protected  java.lang.String getText(java.text.AttributedCharacterIterator aci)
          Extract the raw text from an ACI.
 void paint(org.apache.batik.gvt.TextNode node, java.awt.Graphics2D g2d)
          Paints the specified attributed character iterator using the specified Graphics2D and context and font context.
protected  java.awt.geom.Point2D paintACI(java.text.AttributedCharacterIterator aci, java.awt.Graphics2D g2d, java.awt.geom.Point2D loc)
          Paint an ACI on a Graphics2D at a given location.
protected  java.awt.geom.Point2D paintTextRun(org.apache.batik.gvt.renderer.StrokingTextPainter.TextRun run, java.awt.Graphics2D g2d, java.awt.geom.Point2D loc)
          Paint a single text run on the Graphics2D at a given location.
protected  void paintTextRuns(java.util.List textRuns, java.awt.Graphics2D g2d, java.awt.geom.Point2D loc)
          Paint a list of text runs on the Graphics2D at a given location.
 org.apache.batik.gvt.text.Mark selectAt(double x, double y, org.apache.batik.gvt.TextNode node)
          Select at.
 org.apache.batik.gvt.text.Mark selectFirst(org.apache.batik.gvt.TextNode node)
          Selec first.
 org.apache.batik.gvt.text.Mark selectLast(org.apache.batik.gvt.TextNode node)
          Select last.
 org.apache.batik.gvt.text.Mark selectTo(double x, double y, org.apache.batik.gvt.text.Mark beginMark)
          Select to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected org.apache.commons.logging.Log log
the logger for this class


PROXY_PAINTER

protected static final org.apache.batik.gvt.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.

Constructor Detail

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 Detail

paint

public void paint(org.apache.batik.gvt.TextNode node,
                  java.awt.Graphics2D g2d)
Paints the specified attributed character iterator using the specified Graphics2D and context and font context.

Specified by:
paint in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the TextNode to paint
g2d - the Graphics2D to use

paintTextRuns

protected void paintTextRuns(java.util.List textRuns,
                             java.awt.Graphics2D g2d,
                             java.awt.geom.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"

paintTextRun

protected java.awt.geom.Point2D paintTextRun(org.apache.batik.gvt.renderer.StrokingTextPainter.TextRun run,
                                             java.awt.Graphics2D g2d,
                                             java.awt.geom.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

getText

protected java.lang.String getText(java.text.AttributedCharacterIterator aci)
Extract the raw text from an ACI.

Parameters:
aci - ACI to inspect
Returns:
the extracted text

paintACI

protected java.awt.geom.Point2D paintACI(java.text.AttributedCharacterIterator aci,
                                         java.awt.Graphics2D g2d,
                                         java.awt.geom.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

drawPrimitiveString

protected void drawPrimitiveString(java.awt.Graphics2D g2d,
                                   java.awt.geom.Point2D loc,
                                   Font font,
                                   java.lang.String txt,
                                   float tx)

getOutline

public java.awt.Shape getOutline(org.apache.batik.gvt.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.

Specified by:
getOutline in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the text node
Returns:
the outline shape of the text characters

getBounds2D

public java.awt.geom.Rectangle2D getBounds2D(org.apache.batik.gvt.TextNode node)
Get the bounds. This uses the StrokingTextPainter to get the bounds since in theory it should be the same.

Specified by:
getBounds2D in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the text node
Returns:
the bounds of the text

getGeometryBounds

public java.awt.geom.Rectangle2D getGeometryBounds(org.apache.batik.gvt.TextNode node)
Get the geometry bounds. This uses the StrokingTextPainter to get the bounds since in theory it should be the same.

Specified by:
getGeometryBounds in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the text node
Returns:
the bounds of the text

getMark

public org.apache.batik.gvt.text.Mark getMark(org.apache.batik.gvt.TextNode node,
                                              int pos,
                                              boolean all)
Get the mark. This does nothing since the output is pdf and not interactive.

Specified by:
getMark in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the text node
pos - the position
all - select all
Returns:
null

selectAt

public org.apache.batik.gvt.text.Mark selectAt(double x,
                                               double y,
                                               org.apache.batik.gvt.TextNode node)
Select at. This does nothing since the output is pdf and not interactive.

Specified by:
selectAt in interface org.apache.batik.gvt.TextPainter
Parameters:
x - the x position
y - the y position
node - the text node
Returns:
null

selectTo

public org.apache.batik.gvt.text.Mark selectTo(double x,
                                               double y,
                                               org.apache.batik.gvt.text.Mark beginMark)
Select to. This does nothing since the output is pdf and not interactive.

Specified by:
selectTo in interface org.apache.batik.gvt.TextPainter
Parameters:
x - the x position
y - the y position
beginMark - the start mark
Returns:
null

selectFirst

public org.apache.batik.gvt.text.Mark selectFirst(org.apache.batik.gvt.TextNode node)
Selec first. This does nothing since the output is pdf and not interactive.

Specified by:
selectFirst in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the text node
Returns:
null

selectLast

public org.apache.batik.gvt.text.Mark selectLast(org.apache.batik.gvt.TextNode node)
Select last. This does nothing since the output is pdf and not interactive.

Specified by:
selectLast in interface org.apache.batik.gvt.TextPainter
Parameters:
node - the text node
Returns:
null

getSelected

public int[] getSelected(org.apache.batik.gvt.text.Mark start,
                         org.apache.batik.gvt.text.Mark finish)
Get selected. This does nothing since the output is pdf and not interactive.

Specified by:
getSelected in interface org.apache.batik.gvt.TextPainter
Parameters:
start - the start mark
finish - the finish mark
Returns:
null

getHighlightShape

public java.awt.Shape getHighlightShape(org.apache.batik.gvt.text.Mark beginMark,
                                        org.apache.batik.gvt.text.Mark endMark)
Get the highlighted shape. This does nothing since the output is pdf and not interactive.

Specified by:
getHighlightShape in interface org.apache.batik.gvt.TextPainter
Parameters:
beginMark - the start mark
endMark - the end mark
Returns:
null

fop 0.95

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