Class PageDrawer

    • Field Detail

      • LOG

        private static final org.apache.commons.logging.Log LOG
      • subsamplingAllowed

        private final boolean subsamplingAllowed
      • graphics

        private java.awt.Graphics2D graphics
      • xform

        private java.awt.geom.AffineTransform xform
      • xformScalingFactorX

        private float xformScalingFactorX
      • xformScalingFactorY

        private float xformScalingFactorY
      • flipTG

        private boolean flipTG
      • clipWindingRule

        private int clipWindingRule
      • linePath

        private java.awt.geom.GeneralPath linePath
      • lastClips

        private java.util.List<java.awt.geom.Path2D> lastClips
      • initialClip

        private java.awt.Shape initialClip
      • textClippings

        private java.util.List<java.awt.Shape> textClippings
      • fontGlyph2D

        private final java.util.Map<PDFont,​Glyph2D> fontGlyph2D
      • nestedHiddenOCGCount

        private int nestedHiddenOCGCount
      • renderingHints

        private final java.awt.RenderingHints renderingHints
      • imageDownscalingOptimizationThreshold

        private final float imageDownscalingOptimizationThreshold
      • JAVA_VERSION

        static final int JAVA_VERSION
      • annotationFilter

        private AnnotationFilter annotationFilter
        Default annotations filter, returns all annotations
    • Constructor Detail

      • PageDrawer

        public PageDrawer​(PageDrawerParameters parameters)
                   throws java.io.IOException
        Constructor.
        Parameters:
        parameters - Parameters for page drawing.
        Throws:
        java.io.IOException - If there is an error loading properties from the file.
    • Method Detail

      • getAnnotationFilter

        public AnnotationFilter getAnnotationFilter()
        Return the AnnotationFilter.
        Returns:
        the AnnotationFilter
      • setAnnotationFilter

        public void setAnnotationFilter​(AnnotationFilter annotationFilter)
        Set the AnnotationFilter.

        Allows to only render annotation accepted by the filter.

        Parameters:
        annotationFilter - the AnnotationFilter
      • getRenderer

        public final PDFRenderer getRenderer()
        Returns the parent renderer.
      • getGraphics

        protected final java.awt.Graphics2D getGraphics()
        Returns the underlying Graphics2D. May be null if drawPage has not yet been called.
      • getLinePath

        protected final java.awt.geom.GeneralPath getLinePath()
        Returns the current line path. This is reset to empty after each fill/stroke.
      • setRenderingHints

        private void setRenderingHints()
        Sets high-quality rendering hints on the current Graphics2D.
      • drawPage

        public void drawPage​(java.awt.Graphics g,
                             PDRectangle pageSize)
                      throws java.io.IOException
        Draws the page to the requested context.
        Parameters:
        g - The graphics context to draw onto.
        pageSize - The size of the page to draw.
        Throws:
        java.io.IOException - If there is an IO error while drawing the page.
      • drawTilingPattern

        void drawTilingPattern​(java.awt.Graphics2D g,
                               PDTilingPattern pattern,
                               PDColorSpace colorSpace,
                               PDColor color,
                               Matrix patternMatrix)
                        throws java.io.IOException
        Draws the pattern stream to the requested context.
        Parameters:
        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 matrix
        Throws:
        java.io.IOException - If there is an IO error while drawing the page.
      • clampColor

        private float clampColor​(float color)
      • getPaint

        protected java.awt.Paint getPaint​(PDColor color)
                                   throws java.io.IOException
        Returns an AWT paint for the given PDColor.
        Parameters:
        color - The color to get a paint for. This can be an actual color or a pattern.
        Throws:
        java.io.IOException
      • setClip

        protected final void setClip()
        Sets the clipping path using caching for performance. We track lastClip manually because Graphics.getClip() returns a new object instead of the same one passed to setClip(). You may need to call this if you override showGlyph(). See PDFBOX-5093 for more.
      • transferClip

        protected void transferClip​(java.awt.Graphics2D graphics)
        Transfer clip to the destination device. Override this if you want to avoid to do slow intersecting operations but want the destination device to do this (e.g. SVG). You can get the individual clippings via PDGraphicsState.getCurrentClippingPaths(). See PDFBOX-5258 for sample code.
        Parameters:
        graphics - graphics device
      • beginText

        public void beginText()
                       throws java.io.IOException
        Description copied from class: PDFStreamEngine
        Called when the BT operator is encountered. This method is for overriding in subclasses, the default implementation does nothing.
        Overrides:
        beginText in class PDFStreamEngine
        Throws:
        java.io.IOException - if there was an error processing the text
      • endText

        public void endText()
                     throws java.io.IOException
        Description copied from class: PDFStreamEngine
        Called when the ET operator is encountered. This method is for overriding in subclasses, the default implementation does nothing.
        Overrides:
        endText in class PDFStreamEngine
        Throws:
        java.io.IOException - if there was an error processing the text
      • beginTextClip

        private void beginTextClip()
        Begin buffering the text clipping path, if any.
      • endTextClip

        private void endTextClip()
        End buffering the text clipping path, if any.
      • showFontGlyph

        protected void showFontGlyph​(Matrix textRenderingMatrix,
                                     PDFont font,
                                     int code,
                                     Vector displacement)
                              throws java.io.IOException
        Description copied from class: PDFStreamEngine
        Called when a glyph is to be processed. This method is intended for overriding in subclasses, the default implementation does nothing.
        Overrides:
        showFontGlyph in class PDFStreamEngine
        Parameters:
        textRenderingMatrix - the current text rendering matrix, Trm
        font - the current font
        code - internal PDF character code for the glyph
        displacement - the displacement (i.e. advance) of the glyph in text space
        Throws:
        java.io.IOException - if the glyph cannot be processed
      • drawGlyph2D

        private void drawGlyph2D​(Glyph2D glyph2D,
                                 PDFont font,
                                 int code,
                                 Vector displacement,
                                 java.awt.geom.AffineTransform at)
                          throws java.io.IOException
        Render the font using the Glyph2D interface.
        Parameters:
        glyph2D - the Glyph2D implementation provided a GeneralPath for each glyph
        font - the font
        code - character code
        displacement - the glyph's displacement (advance)
        at - the transformation
        Throws:
        java.io.IOException - if something went wrong
      • showType3Glyph

        protected void showType3Glyph​(Matrix textRenderingMatrix,
                                      PDType3Font font,
                                      int code,
                                      Vector displacement)
                               throws java.io.IOException
        Description copied from class: PDFStreamEngine
        Called when a glyph is to be processed. This method is intended for overriding in subclasses, the default implementation does nothing.
        Overrides:
        showType3Glyph in class PDFStreamEngine
        Parameters:
        textRenderingMatrix - the current text rendering matrix, Trm
        font - the current font
        code - internal PDF character code for the glyph
        displacement - the displacement (i.e. advance) of the glyph in text space
        Throws:
        java.io.IOException - if the glyph cannot be processed
      • createGlyph2D

        private Glyph2D createGlyph2D​(PDFont font)
                               throws java.io.IOException
        Provide a Glyph2D for the given font.
        Parameters:
        font - the font
        Returns:
        the implementation of the Glyph2D interface for the given font
        Throws:
        java.io.IOException - if something went wrong
      • appendRectangle

        public void appendRectangle​(java.awt.geom.Point2D p0,
                                    java.awt.geom.Point2D p1,
                                    java.awt.geom.Point2D p2,
                                    java.awt.geom.Point2D p3)
        Description copied from class: PDFGraphicsStreamEngine
        Append a rectangle to the current path.
        Specified by:
        appendRectangle in class PDFGraphicsStreamEngine
        Parameters:
        p0 - point P0 of the rectangle.
        p1 - point P1 of the rectangle.
        p2 - point P2 of the rectangle.
        p3 - point P3 of the rectangle.
      • applySoftMaskToPaint

        private java.awt.Paint applySoftMaskToPaint​(java.awt.Paint parentPaint,
                                                    PDSoftMask softMask)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • adjustImage

        private java.awt.image.BufferedImage adjustImage​(java.awt.image.BufferedImage gray)
      • getStrokingPaint

        private java.awt.Paint getStrokingPaint()
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getNonStrokingPaint

        protected final java.awt.Paint getNonStrokingPaint()
                                                    throws java.io.IOException
        Returns the non-stroking AWT Paint. You may need to call this if you override showGlyph(). See PDFBOX-5093 for more.
        Returns:
        The non-stroking AWT Paint.
        Throws:
        java.io.IOException
      • getStroke

        private java.awt.Stroke getStroke()
      • isAllZeroDash

        private boolean isAllZeroDash​(float[] dashArray)
      • fillPath

        public void fillPath​(int windingRule)
                      throws java.io.IOException
        Description copied from class: PDFGraphicsStreamEngine
        Fill the path.
        Specified by:
        fillPath in class PDFGraphicsStreamEngine
        Parameters:
        windingRule - The winding rule this path will use.
        Throws:
        java.io.IOException - if something went wrong.
      • intersectShadingBBox

        private void intersectShadingBBox​(PDColor color,
                                          java.awt.geom.Area area)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • isRectangular

        private boolean isRectangular​(java.awt.geom.GeneralPath path)
        Returns true if the given path is rectangular.
      • fillAndStrokePath

        public void fillAndStrokePath​(int windingRule)
                               throws java.io.IOException
        Fills and then strokes the path.
        Specified by:
        fillAndStrokePath in class PDFGraphicsStreamEngine
        Parameters:
        windingRule - The winding rule this path will use.
        Throws:
        java.io.IOException - If there is an IO error while filling the path.
      • clip

        public void clip​(int windingRule)
        Description copied from class: PDFGraphicsStreamEngine
        Modify the current clipping path by intersecting it with the current path. The clipping path will not be updated until the succeeding painting operator is called.
        Specified by:
        clip in class PDFGraphicsStreamEngine
        Parameters:
        windingRule - The winding rule which will be used for clipping.
      • moveTo

        public void moveTo​(float x,
                           float y)
        Description copied from class: PDFGraphicsStreamEngine
        Starts a new path at (x,y).
        Specified by:
        moveTo in class PDFGraphicsStreamEngine
        Parameters:
        x - x-coordinate of the target point.
        y - y-coordinate of the target point.
      • lineTo

        public void lineTo​(float x,
                           float y)
        Description copied from class: PDFGraphicsStreamEngine
        Draws a line from the current point to (x,y).
        Specified by:
        lineTo in class PDFGraphicsStreamEngine
        Parameters:
        x - x-coordinate of the end point of the line.
        y - y-coordinate of the end point of the line.
      • curveTo

        public void curveTo​(float x1,
                            float y1,
                            float x2,
                            float y2,
                            float x3,
                            float y3)
        Description copied from class: PDFGraphicsStreamEngine
        Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.
        Specified by:
        curveTo in class PDFGraphicsStreamEngine
        Parameters:
        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.
      • drawImage

        public void drawImage​(PDImage pdImage)
                       throws java.io.IOException
        Description copied from class: PDFGraphicsStreamEngine
        Draw the image.
        Specified by:
        drawImage in class PDFGraphicsStreamEngine
        Parameters:
        pdImage - The image to draw.
        Throws:
        java.io.IOException - if something went wrong.
      • getSubsampling

        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
        Parameters:
        pdImage - PDImage to be drawn
        at - Transform that will be applied to the image when drawing
        Returns:
        The rounded-down ratio of image pixels to drawn pixels. Returned value will always be >=1.
      • drawBufferedImage

        private void drawBufferedImage​(java.awt.image.BufferedImage image,
                                       java.awt.geom.AffineTransform at)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • applyTransferFunction

        private java.awt.image.BufferedImage applyTransferFunction​(java.awt.image.BufferedImage image,
                                                                   COSBase transfer)
                                                            throws java.io.IOException
        Throws:
        java.io.IOException
      • shadingFill

        public void shadingFill​(COSName shadingName)
                         throws java.io.IOException
        Description copied from class: PDFGraphicsStreamEngine
        Fill with Shading.
        Specified by:
        shadingFill in class PDFGraphicsStreamEngine
        Parameters:
        shadingName - The name of the Shading Dictionary to use for this fill instruction.
        Throws:
        java.io.IOException - if something went wrong.
      • showAnnotation

        public void showAnnotation​(PDAnnotation annotation)
                            throws java.io.IOException
        Description copied from class: PDFStreamEngine
        Shows the given annotation.
        Overrides:
        showAnnotation in class PDFStreamEngine
        Parameters:
        annotation - An annotation on the current page.
        Throws:
        java.io.IOException - If an error occurred reading the annotation
      • showForm

        public void showForm​(PDFormXObject form)
                      throws java.io.IOException
        Shows a form from the content stream.
        Overrides:
        showForm in class PDFStreamEngine
        Parameters:
        form - form XObject
        Throws:
        java.io.IOException - if the form cannot be processed
      • showTransparencyGroup

        public void showTransparencyGroup​(PDTransparencyGroup form)
                                   throws java.io.IOException
        Description copied from class: PDFStreamEngine
        Shows a transparency group from the content stream.
        Overrides:
        showTransparencyGroup in class PDFStreamEngine
        Parameters:
        form - transparency group (form) XObject
        Throws:
        java.io.IOException - if the transparency group cannot be processed
      • showTransparencyGroupOnGraphics

        protected void showTransparencyGroupOnGraphics​(PDTransparencyGroup form,
                                                       java.awt.Graphics2D graphics)
                                                throws java.io.IOException
        For advanced users, to extract the transparency group into a separate graphics device.
        Parameters:
        form -
        graphics -
        Throws:
        java.io.IOException
      • beginMarkedContentSequence

        public void beginMarkedContentSequence​(COSName tag,
                                               COSDictionary properties)
        Called when a marked content group begins
        Overrides:
        beginMarkedContentSequence in class PDFStreamEngine
        Parameters:
        tag - indicates the role or significance of the sequence
        properties - optional properties
      • isContentRendered

        private boolean isContentRendered()
      • isHiddenOCG

        private boolean isHiddenOCG​(PDPropertyList propertyList)
      • getJavaVersion

        private static int getJavaVersion()