public class PageDrawer extends PDFGraphicsStreamEngine
If you want to do custom graphics processing rather than Graphics2D rendering, then you should
subclass PDFGraphicsStreamEngine
instead. Subclassing PageDrawer is only suitable for
cases where the goal is to render onto a Graphics2D
surface. In that case you'll also
have to subclass PDFRenderer
and modify
PDFRenderer.createPageDrawer(PageDrawerParameters)
.
Modifier and Type | Class and Description |
---|---|
private class |
PageDrawer.TransparencyGroup
Transparency group.
|
Modifier and Type | Field and Description |
---|---|
private AnnotationFilter |
annotationFilter
Default annotations filter, returns all annotations
|
private int |
clipWindingRule |
private RenderDestination |
destination |
private boolean |
flipTG |
private java.util.Map<PDFont,Glyph2D> |
fontGlyph2D |
private java.awt.Graphics2D |
graphics |
private java.awt.Shape |
initialClip |
(package private) static int |
JAVA_VERSION |
private java.awt.geom.Area |
lastClip |
private java.awt.geom.GeneralPath |
linePath |
private static org.apache.commons.logging.Log |
LOG |
private int |
nestedHiddenOCGCount |
private PDRectangle |
pageSize |
private PDFRenderer |
renderer |
private java.awt.RenderingHints |
renderingHints |
private boolean |
subsamplingAllowed |
private java.util.List<java.awt.Shape> |
textClippings |
private TilingPaintFactory |
tilingPaintFactory |
private java.util.Deque<PageDrawer.TransparencyGroup> |
transparencyGroupStack |
private java.awt.geom.AffineTransform |
xform |
Constructor and Description |
---|
PageDrawer(PageDrawerParameters parameters)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private java.awt.image.BufferedImage |
adjustImage(java.awt.image.BufferedImage gray) |
private void |
adjustRectangle(java.awt.geom.Rectangle2D r) |
void |
appendRectangle(java.awt.geom.Point2D p0,
java.awt.geom.Point2D p1,
java.awt.geom.Point2D p2,
java.awt.geom.Point2D p3)
Append a rectangle to the current path.
|
private java.awt.Paint |
applySoftMaskToPaint(java.awt.Paint parentPaint,
PDSoftMask softMask) |
private java.awt.image.BufferedImage |
applyTransferFunction(java.awt.image.BufferedImage image,
COSBase transfer) |
void |
beginMarkedContentSequence(COSName tag,
COSDictionary properties)
Called when a marked content group begins
|
void |
beginText()
Called when the BT operator is encountered.
|
private void |
beginTextClip()
Begin buffering the text clipping path, if any.
|
private float |
clampColor(float color) |
void |
clip(int windingRule)
Modify the current clipping path by intersecting it with the current path.
|
void |
closePath()
Closes the current path.
|
private Glyph2D |
createGlyph2D(PDFont font)
Provide a Glyph2D for the given font.
|
void |
curveTo(float x1,
float y1,
float x2,
float y2,
float x3,
float y3)
Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.
|
private void |
drawBufferedImage(java.awt.image.BufferedImage image,
java.awt.geom.AffineTransform at) |
private void |
drawGlyph2D(Glyph2D glyph2D,
PDFont font,
int code,
Vector displacement,
java.awt.geom.AffineTransform at)
Render the font using the Glyph2D interface.
|
void |
drawImage(PDImage pdImage)
Draw the image.
|
void |
drawPage(java.awt.Graphics g,
PDRectangle pageSize)
Draws the page to the requested context.
|
(package private) void |
drawTilingPattern(java.awt.Graphics2D g,
PDTilingPattern pattern,
PDColorSpace colorSpace,
PDColor color,
Matrix patternMatrix)
Draws the pattern stream to the requested context.
|
void |
endMarkedContentSequence()
Called when a a marked content group ends
|
void |
endPath()
Ends the current path without filling or stroking it.
|
void |
endText()
Called when the ET operator is encountered.
|
private void |
endTextClip()
End buffering the text clipping path, if any.
|
void |
fillAndStrokePath(int windingRule)
Fills and then strokes the path.
|
void |
fillPath(int windingRule)
Fill the path.
|
AnnotationFilter |
getAnnotationFilter()
Return the AnnotationFilter.
|
java.awt.geom.Point2D |
getCurrentPoint()
Returns the current point of the current path.
|
private float[] |
getDashArray(PDLineDashPattern dashPattern) |
protected java.awt.Graphics2D |
getGraphics()
Returns the underlying Graphics2D.
|
private static int |
getJavaVersion() |
protected java.awt.geom.GeneralPath |
getLinePath()
Returns the current line path.
|
private java.awt.Paint |
getNonStrokingPaint() |
protected java.awt.Paint |
getPaint(PDColor color)
Returns an AWT paint for the given PDColor.
|
PDFRenderer |
getRenderer()
Returns the parent renderer.
|
private java.awt.BasicStroke |
getStroke() |
private java.awt.Paint |
getStrokingPaint() |
private int |
getSubsampling(PDImage pdImage,
java.awt.geom.AffineTransform at)
Calculated the subsampling frequency for a given PDImage based on the current transformation
and its calculated transform
|
private boolean |
hasBlendMode(PDTransparencyGroup group,
java.util.Set<COSBase> groupsDone) |
private void |
intersectShadingBBox(PDColor color,
java.awt.geom.Area area) |
private boolean |
isContentRendered() |
private boolean |
isHiddenOCG(PDPropertyList propertyList) |
private boolean |
isHiddenOCMD(PDOptionalContentMembershipDictionary ocmd) |
private boolean |
isRectangular(java.awt.geom.GeneralPath path)
Returns true if the given path is rectangular.
|
void |
lineTo(float x,
float y)
Draws a line from the current point to (x,y).
|
void |
moveTo(float x,
float y)
Starts a new path at (x,y).
|
void |
setAnnotationFilter(AnnotationFilter annotationFilter)
Set the AnnotationFilter.
|
private void |
setClip() |
private void |
setRenderingHints()
Sets high-quality rendering hints on the current Graphics2D.
|
void |
shadingFill(COSName shadingName)
Fill with Shading.
|
void |
showAnnotation(PDAnnotation annotation)
Shows the given annotation.
|
protected void |
showFontGlyph(Matrix textRenderingMatrix,
PDFont font,
int code,
java.lang.String unicode,
Vector displacement)
Called when a glyph is to be processed.This method is intended for overriding in subclasses,
the default implementation does nothing.
|
void |
showForm(PDFormXObject form)
Shows a form from the content stream.
|
void |
showTransparencyGroup(PDTransparencyGroup form)
Shows a transparency group from the content stream.
|
protected void |
showType3Glyph(Matrix textRenderingMatrix,
PDType3Font font,
int code,
java.lang.String unicode,
Vector displacement)
Called when a glyph is to be processed.This method is intended for overriding in subclasses,
the default implementation does nothing.
|
void |
strokePath()
Stroke the path.
|
getPage
addOperator, applyTextAdjustment, decreaseLevel, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processPage, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, registerOperatorProcessor, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showGlyph, showText, showTextString, showTextStrings, transformedPoint, transformWidth, unsupportedOperator
private static final org.apache.commons.logging.Log LOG
private final PDFRenderer renderer
private final boolean subsamplingAllowed
private java.awt.Graphics2D graphics
private java.awt.geom.AffineTransform xform
private PDRectangle pageSize
private boolean flipTG
private int clipWindingRule
private java.awt.geom.GeneralPath linePath
private java.awt.geom.Area lastClip
private java.awt.Shape initialClip
private java.util.List<java.awt.Shape> textClippings
private final TilingPaintFactory tilingPaintFactory
private final java.util.Deque<PageDrawer.TransparencyGroup> transparencyGroupStack
private int nestedHiddenOCGCount
private final RenderDestination destination
private final java.awt.RenderingHints renderingHints
static final int JAVA_VERSION
private AnnotationFilter annotationFilter
public PageDrawer(PageDrawerParameters parameters) throws java.io.IOException
parameters
- Parameters for page drawing.java.io.IOException
- If there is an error loading properties from the file.public AnnotationFilter getAnnotationFilter()
public void setAnnotationFilter(AnnotationFilter annotationFilter)
Allows to only render annotation accepted by the filter.
annotationFilter
- the AnnotationFilterpublic final PDFRenderer getRenderer()
protected final java.awt.Graphics2D getGraphics()
protected final java.awt.geom.GeneralPath getLinePath()
private void setRenderingHints()
public void drawPage(java.awt.Graphics g, PDRectangle pageSize) throws java.io.IOException
g
- The graphics context to draw onto.pageSize
- The size of the page to draw.java.io.IOException
- If there is an IO error while drawing the page.void drawTilingPattern(java.awt.Graphics2D g, PDTilingPattern pattern, PDColorSpace colorSpace, PDColor color, Matrix patternMatrix) throws java.io.IOException
g
- The graphics context to draw onto.pattern
- The tiling pattern to be used.colorSpace
- color space for this tiling.color
- color for this tiling.patternMatrix
- the pattern matrixjava.io.IOException
- If there is an IO error while drawing the page.private float clampColor(float color)
protected java.awt.Paint getPaint(PDColor color) throws java.io.IOException
color
- The color to get a paint for. This can be an actual color or a pattern.java.io.IOException
private void setClip()
public void beginText() throws java.io.IOException
PDFStreamEngine
beginText
in class PDFStreamEngine
java.io.IOException
- if there was an error processing the textpublic void endText() throws java.io.IOException
PDFStreamEngine
endText
in class PDFStreamEngine
java.io.IOException
- if there was an error processing the textprivate void beginTextClip()
private void endTextClip()
protected void showFontGlyph(Matrix textRenderingMatrix, PDFont font, int code, java.lang.String unicode, Vector displacement) throws java.io.IOException
PDFStreamEngine
showFontGlyph
in class PDFStreamEngine
textRenderingMatrix
- the current text rendering matrix, Trmfont
- the current fontcode
- internal PDF character code for the glyphunicode
- the Unicode text for this glyph, or null if the PDF does provide itdisplacement
- the displacement (i.e. advance) of the glyph in text spacejava.io.IOException
- if the glyph cannot be processedprivate void drawGlyph2D(Glyph2D glyph2D, PDFont font, int code, Vector displacement, java.awt.geom.AffineTransform at) throws java.io.IOException
glyph2D
- the Glyph2D implementation provided a GeneralPath for each glyphfont
- the fontcode
- character codedisplacement
- the glyph's displacement (advance)at
- the transformationjava.io.IOException
- if something went wrongprotected void showType3Glyph(Matrix textRenderingMatrix, PDType3Font font, int code, java.lang.String unicode, Vector displacement) throws java.io.IOException
PDFStreamEngine
showType3Glyph
in class PDFStreamEngine
textRenderingMatrix
- the current text rendering matrix, Trmfont
- the current fontcode
- internal PDF character code for the glyphunicode
- the Unicode text for this glyph, or null if the PDF does provide itdisplacement
- the displacement (i.e. advance) of the glyph in text spacejava.io.IOException
- if the glyph cannot be processedprivate Glyph2D createGlyph2D(PDFont font) throws java.io.IOException
font
- the fontjava.io.IOException
- if something went wrongpublic void appendRectangle(java.awt.geom.Point2D p0, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)
PDFGraphicsStreamEngine
appendRectangle
in class PDFGraphicsStreamEngine
p0
- point P0 of the rectangle.p1
- point P1 of the rectangle.p2
- point P2 of the rectangle.p3
- point P3 of the rectangle.private java.awt.Paint applySoftMaskToPaint(java.awt.Paint parentPaint, PDSoftMask softMask) throws java.io.IOException
java.io.IOException
private void adjustRectangle(java.awt.geom.Rectangle2D r)
private java.awt.image.BufferedImage adjustImage(java.awt.image.BufferedImage gray)
private java.awt.Paint getStrokingPaint() throws java.io.IOException
java.io.IOException
private java.awt.Paint getNonStrokingPaint() throws java.io.IOException
java.io.IOException
private java.awt.BasicStroke getStroke()
private float[] getDashArray(PDLineDashPattern dashPattern)
public void strokePath() throws java.io.IOException
PDFGraphicsStreamEngine
strokePath
in class PDFGraphicsStreamEngine
java.io.IOException
- If there is an IO error while stroking the path.public void fillPath(int windingRule) throws java.io.IOException
PDFGraphicsStreamEngine
fillPath
in class PDFGraphicsStreamEngine
windingRule
- The winding rule this path will use.java.io.IOException
- if something went wrong.private void intersectShadingBBox(PDColor color, java.awt.geom.Area area) throws java.io.IOException
java.io.IOException
private boolean isRectangular(java.awt.geom.GeneralPath path)
public void fillAndStrokePath(int windingRule) throws java.io.IOException
fillAndStrokePath
in class PDFGraphicsStreamEngine
windingRule
- The winding rule this path will use.java.io.IOException
- If there is an IO error while filling the path.public void clip(int windingRule)
PDFGraphicsStreamEngine
clip
in class PDFGraphicsStreamEngine
windingRule
- The winding rule which will be used for clipping.public void moveTo(float x, float y)
PDFGraphicsStreamEngine
moveTo
in class PDFGraphicsStreamEngine
x
- x-coordinate of the target point.y
- y-coordinate of the target point.public void lineTo(float x, float y)
PDFGraphicsStreamEngine
lineTo
in class PDFGraphicsStreamEngine
x
- x-coordinate of the end point of the line.y
- y-coordinate of the end point of the line.public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3)
PDFGraphicsStreamEngine
curveTo
in class PDFGraphicsStreamEngine
x1
- x-coordinate of the first control point.y1
- y-coordinate of the first control point.x2
- x-coordinate of the second control point.y2
- y-coordinate of the second control point.x3
- x-coordinate of the end point of the curve.y3
- y-coordinate of the end point of the curve.public java.awt.geom.Point2D getCurrentPoint()
PDFGraphicsStreamEngine
getCurrentPoint
in class PDFGraphicsStreamEngine
public void closePath()
PDFGraphicsStreamEngine
closePath
in class PDFGraphicsStreamEngine
public void endPath()
PDFGraphicsStreamEngine
endPath
in class PDFGraphicsStreamEngine
public void drawImage(PDImage pdImage) throws java.io.IOException
PDFGraphicsStreamEngine
drawImage
in class PDFGraphicsStreamEngine
pdImage
- The image to draw.java.io.IOException
- if something went wrong.private int getSubsampling(PDImage pdImage, java.awt.geom.AffineTransform at)
pdImage
- PDImage to be drawnat
- Transform that will be applied to the image when drawingprivate void drawBufferedImage(java.awt.image.BufferedImage image, java.awt.geom.AffineTransform at) throws java.io.IOException
java.io.IOException
private java.awt.image.BufferedImage applyTransferFunction(java.awt.image.BufferedImage image, COSBase transfer) throws java.io.IOException
java.io.IOException
public void shadingFill(COSName shadingName) throws java.io.IOException
PDFGraphicsStreamEngine
shadingFill
in class PDFGraphicsStreamEngine
shadingName
- The name of the Shading Dictionary to use for this fill instruction.java.io.IOException
- if something went wrong.public void showAnnotation(PDAnnotation annotation) throws java.io.IOException
PDFStreamEngine
showAnnotation
in class PDFStreamEngine
annotation
- An annotation on the current page.java.io.IOException
- If an error occurred reading the annotationpublic void showForm(PDFormXObject form) throws java.io.IOException
showForm
in class PDFStreamEngine
form
- form XObjectjava.io.IOException
- if the form cannot be processedpublic void showTransparencyGroup(PDTransparencyGroup form) throws java.io.IOException
PDFStreamEngine
showTransparencyGroup
in class PDFStreamEngine
form
- transparency group (form) XObjectjava.io.IOException
- if the transparency group cannot be processedprivate boolean hasBlendMode(PDTransparencyGroup group, java.util.Set<COSBase> groupsDone)
public void beginMarkedContentSequence(COSName tag, COSDictionary properties)
beginMarkedContentSequence
in class PDFStreamEngine
tag
- indicates the role or significance of the sequenceproperties
- optional propertiespublic void endMarkedContentSequence()
endMarkedContentSequence
in class PDFStreamEngine
private boolean isContentRendered()
private boolean isHiddenOCG(PDPropertyList propertyList)
private boolean isHiddenOCMD(PDOptionalContentMembershipDictionary ocmd)
private static int getJavaVersion()