com.sun.pdfview

Class PDFRenderer

public class PDFRenderer extends BaseWatchable implements Runnable

This class turns a set of PDF Commands from a PDF page into an image. It encapsulates the state of drawing in terms of stroke, fill, transform, etc., as well as pushing and popping these states. When the run method is called, this class goes through all remaining commands in the PDF Page and draws them to its buffered image. It then updates any ImageConsumers with the drawn data.
Field Summary
static intNOCAP
static float[]NODASH
static intNOJOIN
static floatNOLIMIT
static floatNOPHASE
static floatNOWIDTH
static longUPDATE_DURATION
how long (in milliseconds) to wait between image updates
Constructor Summary
PDFRenderer(PDFPage page, ImageInfo imageinfo, BufferedImage bi)
create a new PDFGraphics state
PDFRenderer(PDFPage page, Graphics2D g, Rectangle imgbounds, Rectangle2D clip, Color bgColor)
create a new PDFGraphics state, given a Graphics2D.
Method Summary
voidaddObserver(ImageObserver observer)
Add an image observer
voidclip(GeneralPath s)
add the path to the current clip.
voiddraw(GeneralPath p, BasicStroke bs)
draw an outline.
Rectangle2DdrawImage(PDFImage image)
draw an image.
Rectangle2Dfill(GeneralPath s)
fill an outline using the current fill paint
AffineTransformgetInitialTransform()
get the initial transform from page space to Java space
GeneralPathgetLastShape()
Get the last shape drawn
BasicStrokegetStroke()
get the current stroke as a BasicStroke
AffineTransformgetTransform()
get the current affinetransform
intiterate()
Draws the next command in the PDFPage to the buffered image.
voidpop()
restore the state of this object to what it was when the previous push() was called.
voidpush()
push the current graphics state onto the stack.
voidremoveObserver(ImageObserver observer)
Remove an image observer
voidsetFillAlpha(float alpha)
set the stroke alpha
voidsetFillPaint(PDFPaint paint)
set the fill color
voidsetLastShape(GeneralPath shape)
Set the last shape drawn
voidsetStroke(BasicStroke bs)
set the current stroke as a BasicStroke
voidsetStrokeAlpha(float alpha)
set the stroke alpha
voidsetStrokePaint(PDFPaint paint)
set the stroke color
voidsetStrokeParts(float w, int cap, int join, float limit, float[] ary, float phase)
Set some or all aspects of the current stroke.
voidsetTransform(AffineTransform at)
replace the current transform with the given one.
Rectangle2Dstroke(GeneralPath s)
draw an outline using the current stroke and draw paint
voidtransform(AffineTransform at)
concatenate the given transform with the current transform

Field Detail

NOCAP

public static final int NOCAP

NODASH

public static final float[] NODASH

NOJOIN

public static final int NOJOIN

NOLIMIT

public static final float NOLIMIT

NOPHASE

public static final float NOPHASE

NOWIDTH

public static final float NOWIDTH

UPDATE_DURATION

public static final long UPDATE_DURATION
how long (in milliseconds) to wait between image updates

Constructor Detail

PDFRenderer

public PDFRenderer(PDFPage page, ImageInfo imageinfo, BufferedImage bi)
create a new PDFGraphics state

Parameters: page the current page imageinfo the paramters of the image to render

PDFRenderer

public PDFRenderer(PDFPage page, Graphics2D g, Rectangle imgbounds, Rectangle2D clip, Color bgColor)
create a new PDFGraphics state, given a Graphics2D. This version will not create an image, and you will get a NullPointerException if you attempt to call getImage().

Parameters: page the current page g the Graphics2D object to use for drawing imgbounds the bounds of the image into which to fit the page clip the portion of the page to draw, in page space, or null if the whole page should be drawn bgColor the color to draw the background of the image, or null for no color (0 alpha value)

Method Detail

addObserver

public void addObserver(ImageObserver observer)
Add an image observer

clip

public void clip(GeneralPath s)
add the path to the current clip. The new clip will be the intersection of the old clip and given path.

draw

public void draw(GeneralPath p, BasicStroke bs)
draw an outline.

Parameters: p the path to draw bs the stroke with which to draw the path

drawImage

public Rectangle2D drawImage(PDFImage image)
draw an image.

Parameters: image the image to draw

fill

public Rectangle2D fill(GeneralPath s)
fill an outline using the current fill paint

Parameters: s the path to fill

getInitialTransform

public AffineTransform getInitialTransform()
get the initial transform from page space to Java space

getLastShape

public GeneralPath getLastShape()
Get the last shape drawn

getStroke

public BasicStroke getStroke()
get the current stroke as a BasicStroke

getTransform

public AffineTransform getTransform()
get the current affinetransform

iterate

public int iterate()
Draws the next command in the PDFPage to the buffered image. The image will be notified about changes no less than every UPDATE_DURATION milliseconds.

Returns:

pop

public void pop()
restore the state of this object to what it was when the previous push() was called.

push

public void push()
push the current graphics state onto the stack. Continue working with the current object; calling pop() restores the state of this object to its state when push() was called.

removeObserver

public void removeObserver(ImageObserver observer)
Remove an image observer

setFillAlpha

public void setFillAlpha(float alpha)
set the stroke alpha

setFillPaint

public void setFillPaint(PDFPaint paint)
set the fill color

setLastShape

public void setLastShape(GeneralPath shape)
Set the last shape drawn

setStroke

public void setStroke(BasicStroke bs)
set the current stroke as a BasicStroke

setStrokeAlpha

public void setStrokeAlpha(float alpha)
set the stroke alpha

setStrokePaint

public void setStrokePaint(PDFPaint paint)
set the stroke color

setStrokeParts

public void setStrokeParts(float w, int cap, int join, float limit, float[] ary, float phase)
Set some or all aspects of the current stroke.

Parameters: w the width of the stroke, or NOWIDTH to leave it unchanged cap the end cap style, or NOCAP to leave it unchanged join the join style, or NOJOIN to leave it unchanged limit the miter limit, or NOLIMIT to leave it unchanged phase the phase of the dash array, or NOPHASE to leave it unchanged ary the dash array, or null to leave it unchanged. phase and ary must both be valid, or phase must be NOPHASE while ary is null.

setTransform

public void setTransform(AffineTransform at)
replace the current transform with the given one.

stroke

public Rectangle2D stroke(GeneralPath s)
draw an outline using the current stroke and draw paint

Parameters: s the path to stroke

Returns: a Rectangle2D to which the current region being drawn will be added. May also be null, in which case no dirty region will be recorded.

transform

public void transform(AffineTransform at)
concatenate the given transform with the current transform