You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/10/09 14:23:43 UTC

svn commit: r1894073 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Author: tilman
Date: Sat Oct  9 14:23:42 2021
New Revision: 1894073

URL: http://svn.apache.org/viewvc?rev=1894073&view=rev
Log:
PDFBOX-4892: optimize usage of isContentRendered()

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1894073&r1=1894072&r2=1894073&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Sat Oct  9 14:23:42 2021
@@ -521,25 +521,22 @@ public class PageDrawer extends PDFGraph
             // render glyph
             Shape glyph = at.createTransformedShape(path);
 
-            if (renderingMode.isFill())
+            if (isContentRendered())
             {
-                graphics.setComposite(state.getNonStrokingJavaComposite());
-                graphics.setPaint(getNonStrokingPaint());
-                setClip();
-                if (isContentRendered())
+                if (renderingMode.isFill())
                 {
+                    graphics.setComposite(state.getNonStrokingJavaComposite());
+                    graphics.setPaint(getNonStrokingPaint());
+                    setClip();
                     graphics.fill(glyph);
                 }
-            }
 
-            if (renderingMode.isStroke())
-            {
-                graphics.setComposite(state.getStrokingJavaComposite());
-                graphics.setPaint(getStrokingPaint());
-                graphics.setStroke(getStroke());
-                setClip();
-                if (isContentRendered())
+                if (renderingMode.isStroke())
                 {
+                    graphics.setComposite(state.getStrokingJavaComposite());
+                    graphics.setPaint(getStrokingPaint());
+                    graphics.setStroke(getStroke());
+                    setClip();
                     graphics.draw(glyph);
                 }
             }
@@ -797,13 +794,13 @@ public class PageDrawer extends PDFGraph
     @Override
     public void strokePath() throws IOException
     {
-        graphics.setComposite(getGraphicsState().getStrokingJavaComposite());
-        graphics.setPaint(getStrokingPaint());
-        graphics.setStroke(getStroke());
-        setClip();
         //TODO bbox of shading pattern should be used here? (see fillPath)
         if (isContentRendered())
         {
+            graphics.setComposite(getGraphicsState().getStrokingJavaComposite());
+            graphics.setPaint(getStrokingPaint());
+            graphics.setStroke(getStroke());
+            setClip();
             graphics.draw(linePath);
         }
         linePath.reset();
@@ -1130,12 +1127,9 @@ public class PageDrawer extends PDFGraph
                 // draw the image
                 setClip();
                 graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
-                if (isContentRendered())
-                {
-                    graphics.drawImage(renderedPaint,
-                            AffineTransform.getTranslateInstance(bounds.getMinX(), bounds.getMinY()),
-                            null);
-                }
+                graphics.drawImage(renderedPaint,
+                        AffineTransform.getTranslateInstance(bounds.getMinX(), bounds.getMinY()),
+                        null);
             }
             else
             {
@@ -1367,6 +1361,10 @@ public class PageDrawer extends PDFGraph
     @Override
     public void shadingFill(COSName shadingName) throws IOException
     {
+        if (!isContentRendered())
+        {
+            return;
+        }
         PDShading shading = getResources().getShading(shadingName);
         if (shading == null)
         {
@@ -1408,10 +1406,7 @@ public class PageDrawer extends PDFGraph
                 area = getGraphicsState().getCurrentClippingPath();
             }
         }
-        if (isContentRendered())
-        {
-            graphics.fill(area);
-        }
+        graphics.fill(area);
     }
 
     @Override
@@ -1548,25 +1543,19 @@ public class PageDrawer extends PDFGraph
                     new Rectangle2D.Float(0, 0, image.getWidth(), image.getHeight()));
             awtPaint = applySoftMaskToPaint(awtPaint, softMask);
             graphics.setPaint(awtPaint);
-            if (isContentRendered())
-            {
-                graphics.fill(
-                        new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
-            }
+            graphics.fill(
+                    new Rectangle2D.Float(0, 0, bbox.getWidth() * xScale, bbox.getHeight() * yScale));
         }
         else
         {
-            if (isContentRendered())
+            try
             {
-                try
-                {
-                    graphics.drawImage(image, null, null);
-                }
-                catch (InternalError ie)
-                {
-                    LOG.error("Exception drawing image, see JDK-6689349, " +
-                              "try rendering into a BufferedImage instead", ie);
-                }
+                graphics.drawImage(image, null, null);
+            }
+            catch (InternalError ie)
+            {
+                LOG.error("Exception drawing image, see JDK-6689349, " +
+                          "try rendering into a BufferedImage instead", ie);
             }
         }