Package org.loboevolution.pdfview
Class PDFRenderer
java.lang.Object
org.loboevolution.pdfview.BaseWatchable
org.loboevolution.pdfview.PDFRenderer
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
Modifier and TypeFieldDescriptionstatic final int
ConstantNOCAP=-1000
static final float[]
ConstantNODASH
static final int
ConstantNOJOIN=-1000
static final float
ConstantNOLIMIT=-1000
static final float
ConstantNOPHASE=-1000
static final float
ConstantNOWIDTH=-1000
static final long
how long (in milliseconds) to wait between image updatesFields inherited from interface org.loboevolution.pdfview.Watchable
COMPLETED, ERROR, NEEDS_DATA, NOT_STARTED, PAUSED, RUNNING, STOPPED, UNKNOWN
-
Constructor Summary
ConstructorDescriptionPDFRenderer
(PDFPage page, Graphics2D g, Rectangle imgbounds, Rectangle2D clip, Color bgColor) create a new PDFGraphics state, given a Graphics2D.PDFRenderer
(PDFPage page, ImageInfo imageinfo, BufferedImage bi) create a new PDFGraphics state -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(ImageObserver observer) Add an image observervoid
cleanup()
Clean up after a set of iterations.void
clip
(GeneralPath s) add the path to the current clip.void
draw
(GeneralPath p, BasicStroke bs) draw an outline.draw an image.fill
(GeneralPath s) fill an outline using the current fill paintgetImage()
If exists, returns the image which is used by the renderer.get the initial transform from page space to Java spaceget the current stroke as a BasicStrokeget the current affinetransformint
iterate()
Perform a single iteration of this watchable.void
pop()
restore the state of this object to what it was when the previous push() was called.void
push()
push the current graphics state onto the stack.void
********************************************************************** Remember the current transformation **********************************************************************void
removeObserver
(ImageObserver observer) Remove an image observervoid
setFillAlpha
(float alpha) set the stroke alphavoid
setFillPaint
(PDFPaint paint) set the fill colorvoid
setStroke
(BasicStroke bs) set the current stroke as a BasicStrokevoid
setStrokeAlpha
(float alpha) set the stroke alphavoid
setStrokePaint
(PDFPaint paint) set the stroke colorvoid
setStrokeParts
(float wStroke, int capStroke, int joinStroke, float limitStroke, float[] aryStroke, float phaseStroke) Set some or all aspects of the current stroke.void
replace the current transform with the given one.void
setup()
Prepare for a set of iterations.stroke
(GeneralPath s, boolean autoAdjustStroke) draw an outline using the current stroke and draw paintvoid
concatenate the given transform with the current transformMethods inherited from class org.loboevolution.pdfview.BaseWatchable
execute, getErrorHandler, getStatus, go, go, go, go, isExecutable, isFinished, run, setError, setStatus, stop, waitForFinish
-
Field Details
-
UPDATE_DURATION
public static final long UPDATE_DURATIONhow long (in milliseconds) to wait between image updates- See Also:
-
NOPHASE
public static final float NOPHASEConstantNOPHASE=-1000
- See Also:
-
NOWIDTH
public static final float NOWIDTHConstantNOWIDTH=-1000
- See Also:
-
NOLIMIT
public static final float NOLIMITConstantNOLIMIT=-1000
- See Also:
-
NOCAP
public static final int NOCAPConstantNOCAP=-1000
- See Also:
-
NODASH
public static final float[] NODASHConstantNODASH
-
NOJOIN
public static final int NOJOINConstantNOJOIN=-1000
- See Also:
-
-
Constructor Details
-
PDFRenderer
create a new PDFGraphics state- Parameters:
page
- the current pageimageinfo
- the paramters of the image to renderbi
- aBufferedImage
object.
-
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 pageg
- the Graphics2D object to use for drawingimgbounds
- the bounds of the image into which to fit the pageclip
- the portion of the page to draw, in page space, or null if the whole page should be drawnbgColor
- the color to draw the background of the image, or null for no color (0 alpha value)
-
-
Method Details
-
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. -
pop
public void pop()restore the state of this object to what it was when the previous push() was called. -
stroke
draw an outline using the current stroke and draw paint- Parameters:
s
- the path to strokeautoAdjustStroke
- a boolean.- 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.
-
draw
draw an outline.- Parameters:
p
- the path to drawbs
- the stroke with which to draw the path
-
fill
fill an outline using the current fill paint- Parameters:
s
- the path to fill- Returns:
- a
Rectangle2D
object.
-
drawImage
draw an image.- Parameters:
image
- the image to draw- Returns:
- a
Rectangle2D
object.
-
clip
add the path to the current clip. The new clip will be the intersection of the old clip and given path.- Parameters:
s
- aGeneralPath
object.
-
getTransform
get the current affinetransform- Returns:
- a
AffineTransform
object.
-
setTransform
replace the current transform with the given one.- Parameters:
at
- aAffineTransform
object.
-
transform
concatenate the given transform with the current transform- Parameters:
at
- aAffineTransform
object.
-
getInitialTransform
get the initial transform from page space to Java space- Returns:
- a
AffineTransform
object.
-
setStrokeParts
public void setStrokeParts(float wStroke, int capStroke, int joinStroke, float limitStroke, float[] aryStroke, float phaseStroke) Set some or all aspects of the current stroke.- Parameters:
wStroke
- the width of the stroke, or NOWIDTH to leave it unchangedcapStroke
- the end cap style, or NOCAP to leave it unchangedjoinStroke
- the join style, or NOJOIN to leave it unchangedlimitStroke
- the miter limit, or NOLIMIT to leave it unchangedaryStroke
- 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.phaseStroke
- the phase of the dash array, or NOPHASE to leave it unchanged
-
getStroke
get the current stroke as a BasicStroke- Returns:
- a
BasicStroke
object.
-
setStroke
set the current stroke as a BasicStroke- Parameters:
bs
- aBasicStroke
object.
-
setStrokePaint
set the stroke color- Parameters:
paint
- aPDFPaint
object.
-
setFillPaint
set the fill color- Parameters:
paint
- aPDFPaint
object.
-
setStrokeAlpha
public void setStrokeAlpha(float alpha) set the stroke alpha- Parameters:
alpha
- a float.
-
setFillAlpha
public void setFillAlpha(float alpha) set the stroke alpha- Parameters:
alpha
- a float.
-
addObserver
Add an image observer- Parameters:
observer
- aImageObserver
object.
-
removeObserver
Remove an image observer- Parameters:
observer
- aImageObserver
object.
-
getImage
If exists, returns the image which is used by the renderer.- Returns:
- a BufferedImage or null
-
setup
public void setup()Prepare for a set of iterations. Called before the first iterate() call in a sequence. Subclasses should extend this method if they need to do anything to setup.Setup rendering. Called before iteration begins
- Overrides:
setup
in classBaseWatchable
-
iterate
Perform a single iteration of this watchable. This is the minimum granularity which the go() commands operate over.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.
- Specified by:
iterate
in classBaseWatchable
- Returns:
- one of three values:
- Watchable.RUNNING if there is still data to be processed
- Watchable.NEEDS_DATA if there is no data to be processed but the execution is not yet complete
- Watchable.COMPLETED if the execution is complete
- Throws:
Exception
- if any.
-
cleanup
public void cleanup()Clean up after a set of iterations. Called after iteration has stopped due to completion, manual stopping, or error.Called when iteration has stopped
- Overrides:
cleanup
in classBaseWatchable
-
rememberTransformation
public void rememberTransformation()********************************************************************** Remember the current transformation **********************************************************************
-