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 2017/04/04 16:10:47 UTC
svn commit: r1790142 - in /pdfbox/branches/2.0/preflight/src:
main/java/org/apache/pdfbox/preflight/content/
test/java/org/apache/pdfbox/preflight/ test/resources/
Author: tilman
Date: Tue Apr 4 16:10:47 2017
New Revision: 1790142
URL: http://svn.apache.org/viewvc?rev=1790142&view=rev
Log:
PDFBOX-3741: check default colorspace + test case
Added:
pdfbox/branches/2.0/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java (with props)
pdfbox/branches/2.0/preflight/src/test/resources/PDFBOX-3743.pdf (with props)
Modified:
pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
Modified: pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java?rev=1790142&r1=1790141&r2=1790142&view=diff
==============================================================================
--- pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java (original)
+++ pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java Tue Apr 4 16:10:47 2017
@@ -154,6 +154,7 @@ public class PreflightContentStream exte
validateRenderingIntent(operator, operands);
checkSetColorSpaceOperators(operator, operands);
validateNumberOfGraphicStates(operator);
+ validateDefaultColorSpace(operator);
}
@Override
Modified: pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java?rev=1790142&r1=1790141&r2=1790142&view=diff
==============================================================================
--- pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java (original)
+++ pdfbox/branches/2.0/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightStreamEngine.java Tue Apr 4 16:10:47 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/branches/2.0/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java?rev=1790142&view=auto
==============================================================================
--- pdfbox/branches/2.0/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java (added)
+++ pdfbox/branches/2.0/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java Tue Apr 4 16:10:47 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/branches/2.0/preflight/src/test/java/org/apache/pdfbox/preflight/TestPDFBox3743.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: pdfbox/branches/2.0/preflight/src/test/resources/PDFBOX-3743.pdf
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/preflight/src/test/resources/PDFBOX-3743.pdf?rev=1790142&view=auto
==============================================================================
Binary file - no diff available.
Propchange: pdfbox/branches/2.0/preflight/src/test/resources/PDFBOX-3743.pdf
------------------------------------------------------------------------------
svn:mime-type = application/pdf