pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1818783 - /pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java
Date Wed, 20 Dec 2017 12:02:15 GMT
Author: tilman
Date: Wed Dec 20 12:02:15 2017
New Revision: 1818783

URL: http://svn.apache.org/viewvc?rev=1818783&view=rev
Log:
PDFBOX-4043: detect and process possible tiling patterns in fill, stroke, showtext and show
stencil image

Modified:
    pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java

Modified: pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java?rev=1818783&r1=1818782&r2=1818783&view=diff
==============================================================================
--- pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java (original)
+++ pdfbox/branches/2.0/tools/src/main/java/org/apache/pdfbox/tools/ExtractImages.java Wed
Dec 20 12:02:15 2017
@@ -26,22 +26,30 @@ import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.io.IOUtils;
 
+import org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
-import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
-import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
 import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
-import org.apache.pdfbox.tools.imageio.ImageIOUtil;
-import org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine;
-import org.apache.pdfbox.pdmodel.PDResources;
+import org.apache.pdfbox.pdmodel.graphics.color.PDPattern;
 import org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
+import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
+import org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern;
+import org.apache.pdfbox.pdmodel.graphics.pattern.PDTilingPattern;
 import org.apache.pdfbox.pdmodel.graphics.state.PDSoftMask;
+import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
+import org.apache.pdfbox.tools.imageio.ImageIOUtil;
+import org.apache.pdfbox.util.Matrix;
+import org.apache.pdfbox.util.Vector;
 
 /**
  * Extracts the images from a PDF file.
@@ -217,6 +225,10 @@ public final class ExtractImages
         {
             if (pdImage instanceof PDImageXObject)
             {
+                if (pdImage.isStencil())
+                {
+                    processColor(getGraphicsState().getNonStrokingColor());
+                }
                 PDImageXObject xobject = (PDImageXObject)pdImage;
                 if (seen.contains(xobject.getCOSObject()))
                 {
@@ -285,21 +297,39 @@ public final class ExtractImages
         }
 
         @Override
-        public void strokePath() throws IOException
+        protected void showGlyph(Matrix textRenderingMatrix, 
+                                 PDFont font,
+                                 int code,
+                                 String unicode,
+                                 Vector displacement) throws IOException
         {
+            RenderingMode renderingMode = getGraphicsState().getTextState().getRenderingMode();
+            if (renderingMode.isFill())
+            {
+                processColor(getGraphicsState().getNonStrokingColor());
+            }
+            if (renderingMode.isStroke())
+            {
+                processColor(getGraphicsState().getStrokingColor());
+            }
+        }
 
+        @Override
+        public void strokePath() throws IOException
+        {
+            processColor(getGraphicsState().getStrokingColor());
         }
 
         @Override
         public void fillPath(int windingRule) throws IOException
         {
-
+            processColor(getGraphicsState().getNonStrokingColor());
         }
 
         @Override
         public void fillAndStrokePath(int windingRule) throws IOException
         {
-
+            processColor(getGraphicsState().getNonStrokingColor());
         }
 
         @Override
@@ -307,6 +337,20 @@ public final class ExtractImages
         {
 
         }
+
+        // find out if it is a tiling pattern, then process that one
+        private void processColor(PDColor color) throws IOException
+        {
+            if (color.getColorSpace() instanceof PDPattern)
+            {
+                PDPattern pattern = (PDPattern) color.getColorSpace();
+                PDAbstractPattern abstractPattern = pattern.getPattern(color);
+                if (abstractPattern instanceof PDTilingPattern)
+                {
+                    processTilingPattern((PDTilingPattern) abstractPattern, null, null);
+                }
+            }
+        }
     }
 
     private boolean hasMasks(PDImage pdImage) throws IOException



Mime
View raw message