org.icepdf.core.pobjects.graphics
Class TextSprite

java.lang.Object
  extended by org.icepdf.core.pobjects.graphics.TextSprite

public class TextSprite
extends java.lang.Object

This class represents text which will be rendered to the a graphics context. This class was created to act as a wrapper for painting text using the Phelphs font library as well as painting using java.awt.Font.

Objects of this type are created by the content parser when "TJ" or "Tj" operands are encountered in a page's content stream. Each TextSprite object is comprised of a list of CharSprites which can be painted by the Shapes class at render time.

Since:
2.0

Constructor Summary
TextSprite(FontFile font, int size, java.awt.geom.AffineTransform graphicStateTransform)
          Creates a new TextSprit object.
 
Method Summary
 GlyphText addText(java.lang.String cid, java.lang.String unicode, float x, float y, float width)
          Adds a new text char to the TextSprite which will pe painted at x, y under the current CTM
 void dispose()
          Dispose this TextSprite Object.
 java.awt.geom.Rectangle2D.Float getBounds()
          Getst the bounds of the text that makes up this sprite.
 java.awt.geom.Area getGlyphOutline()
          Gets the glyph outline as an Area.
 java.util.ArrayList<GlyphText> getGlyphSprites()
          Gets the character bounds of each glyph found in the TextSprite.
 java.awt.geom.AffineTransform getGraphicStateTransform()
           
 boolean intersects(java.awt.Shape shape)
          Tests if the interior of the TextSprite bounds intersects the interior of a specified shape.
 void paint(java.awt.Graphics g)
          Paints all the character elements in this TextSprite to the graphics context
 void setGraphicStateTransform(java.awt.geom.AffineTransform graphicStateTransform)
          Set the graphic state transorm on all child sprites, This is used for xForm object parsing and text selection.
 void setRMode(int rmode)
          Set the rmode for all the characters being in this object.
 void setStrokeColor(java.awt.Color color)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextSprite

public TextSprite(FontFile font,
                  int size,
                  java.awt.geom.AffineTransform graphicStateTransform)

Creates a new TextSprit object.

Parameters:
font - font used when painting glyphs.
size - size of the font in user space
Method Detail

addText

public GlyphText addText(java.lang.String cid,
                         java.lang.String unicode,
                         float x,
                         float y,
                         float width)

Adds a new text char to the TextSprite which will pe painted at x, y under the current CTM

Parameters:
cid - cid to paint.
unicode - unicode represention of cid.
x - x-coordinate to paint.
y - y-coordinate to paint.
width - width of cid from font.

getGlyphSprites

public java.util.ArrayList<GlyphText> getGlyphSprites()
Gets the character bounds of each glyph found in the TextSprite.

Returns:
bounds in PDF coordinates of character bounds

getGraphicStateTransform

public java.awt.geom.AffineTransform getGraphicStateTransform()

setGraphicStateTransform

public void setGraphicStateTransform(java.awt.geom.AffineTransform graphicStateTransform)
Set the graphic state transorm on all child sprites, This is used for xForm object parsing and text selection. There is no need to do this outside of the context parser.

Parameters:
graphicStateTransform -

setRMode

public void setRMode(int rmode)

Set the rmode for all the characters being in this object. Rmode can have the following values:

Parameters:
rmode - valid rmode from 0-7

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setStrokeColor

public void setStrokeColor(java.awt.Color color)

getBounds

public java.awt.geom.Rectangle2D.Float getBounds()
Getst the bounds of the text that makes up this sprite. The bounds are defined PDF space and are relative to the current CTM.

Returns:

paint

public void paint(java.awt.Graphics g)

Paints all the character elements in this TextSprite to the graphics context

Parameters:
g - graphics context to which the characters will be painted to.

getGlyphOutline

public java.awt.geom.Area getGlyphOutline()
Gets the glyph outline as an Area. This method is primarily used for processing text rendering modes 4 - 7.

Returns:
area representing the glyph outline.

intersects

public boolean intersects(java.awt.Shape shape)
Tests if the interior of the TextSprite bounds intersects the interior of a specified shape.

Parameters:
shape - shape to calculate intersection against
Returns:
true, if TextSprite bounds intersects shape; otherwise; false.

dispose

public void dispose()
Dispose this TextSprite Object.