pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1790143 - in /pdfbox/trunk/preflight/src: main/java/org/apache/pdfbox/preflight/content/ test/java/org/apache/pdfbox/preflight/ test/resources/
Date Tue, 04 Apr 2017 16:10:56 GMT
Author: tilman
Date: Tue Apr  4 16:10:55 2017
New Revision: 1790143

URL: http://svn.apache.org/viewvc?rev=1790143&view=rev
Log:
PDFBOX-3741: check default colorspace + test case

Added:
    pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java 
 (with props)
    pdfbox/trunk/preflight/src/test/resources/PDFBOX-3743.pdf   (with props)
Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java?rev=1790143&r1=1790142&r2=1790143&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
Tue Apr  4 16:10:55 2017
@@ -154,6 +154,7 @@ public class PreflightContentStream exte
         validateRenderingIntent(operator, operands);
         checkSetColorSpaceOperators(operator, operands);
         validateNumberOfGraphicStates(operator);
+        validateDefaultColorSpace(operator);
     }
 
     @Override

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java?rev=1790143&r1=1790142&r2=1790143&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
Tue Apr  4 16:10:55 2017
@@ -91,6 +91,8 @@ import org.apache.pdfbox.contentstream.o
 import org.apache.pdfbox.contentstream.operator.text.SetTextRise;
 import org.apache.pdfbox.contentstream.operator.text.SetWordSpacing;
 import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceGray;
+import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
 
 /**
  * This class inherits from org.apache.pdfbox.util.PDFStreamEngine to allow the validation
of specific rules in
@@ -403,6 +405,58 @@ public abstract class PreflightStreamEng
                     ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING);
         }
     }
+
+    /**
+     * In some cases, the colorspace isn't checked because defaults (/DeviceGray) is used.
Thus we
+     * need to check all text output, stroke and fill for /DeviceGray.
+     *
+     * @param operator an operator.
+     * @throws ContentStreamException
+     */
+    void validateDefaultColorSpace(Operator operator) throws ContentStreamException
+    {
+        boolean v = false;
+        String op = operator.getName();
+        if ("Tj".equals(op) || "TJ".equals(op) || "'".equals(op) || "\"".equals(op))
+        {
+            RenderingMode rm = getGraphicsState().getTextState().getRenderingMode();
+            if (rm.isFill() && 
+                    getGraphicsState().getNonStrokingColor().getColorSpace() instanceof PDDeviceGray)
+            {
+                v = true;
+            }
+            if (rm.isStroke() && 
+                    getGraphicsState().getStrokingColor().getColorSpace() instanceof PDDeviceGray)
+            {
+                v = true;
+            }
+        }
+        // fills
+        if ("f".equals(op) || "F".equals(op) || "f*".equals(op) || 
+            "B".equals(op) || "B*".equals(op) || "b".equals(op) || "b*".equals(op))
+        {
+            if (getGraphicsState().getNonStrokingColor().getColorSpace() instanceof PDDeviceGray)
+            {
+                v = true;
+            }
+        }
+        // strokes
+        if ("B".equals(op) || "B*".equals(op) || "b".equals(op) || "b*".equals(op) || 
+            "s".equals(op) || "S".equals(op))
+        {
+            if (getGraphicsState().getStrokingColor().getColorSpace() instanceof PDDeviceGray)
+            {
+                v = true;
+            }
+        }
+        if (v)
+        {
+            if (!validColorSpaceDestOutputProfile(PreflightStreamEngine.ColorSpaceType.ALL))
+                        registerError("/DeviceGray default for operator \"" + op + 
+                                "\" can't be used without Color Profile",
+                    ERROR_GRAPHIC_INVALID_COLOR_SPACE_MISSING);
+        }
+    }
 
     private boolean validColorSpace(PDColorSpace colorSpace, ColorSpaceType expectedIccType)
             throws ContentStreamException

Added: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java?rev=1790143&view=auto
==============================================================================
--- pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java (added)
+++ pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java Tue
Apr  4 16:10:55 2017
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2017 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.preflight;
+
+import java.io.IOException;
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+
+import org.apache.pdfbox.preflight.parser.PreflightParser;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class TestPDFBox3743
+{
+    /**
+     * Test whether use of default colorspace without output intent for text output is detected.
+     *
+     * @throws IOException
+     */
+    @Test
+    public void testPDFBox3743() throws IOException
+    {
+        DataSource ds = new FileDataSource("src/test/resources/PDFBOX-3743.pdf");
+        PreflightParser parser = new PreflightParser(ds);
+        parser.parse();
+        PreflightDocument document = parser.getPreflightDocument();
+        document.validate();
+        ValidationResult result = document.getResult();
+        document.close();
+
+        // Error should be:
+        // 2.4.3: Invalid Color space, /DeviceGray default for operator "Tj" can't be used
without Color Profile
+        Assert.assertFalse("File PDFBOX-3743.pdf should be detected as not PDF/A-1b", result.isValid());
+        Assert.assertEquals("List should contain one result", 1, result.getErrorsList().size());
+        Assert.assertEquals("2.4.3", result.getErrorsList().get(0).getErrorCode());
+    }
+}

Propchange: pdfbox/trunk/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: pdfbox/trunk/preflight/src/test/resources/PDFBOX-3743.pdf
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/test/resources/PDFBOX-3743.pdf?rev=1790143&view=auto
==============================================================================
Binary file - no diff available.

Propchange: pdfbox/trunk/preflight/src/test/resources/PDFBOX-3743.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/pdf



Mime
View raw message