pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1696316 - /pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
Date Mon, 17 Aug 2015 16:23:21 GMT
Author: tilman
Date: Mon Aug 17 16:23:21 2015
New Revision: 1696316

URL: http://svn.apache.org/r1696316
Log:
PDFBOX-2804: check font array in ExtGState

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java?rev=1696316&r1=1696315&r2=1696316&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/process/reflect/ExtGStateValidationProcess.java
Mon Aug 17 16:23:21 2015
@@ -21,6 +21,11 @@
 
 package org.apache.pdfbox.preflight.process.reflect;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.pdfbox.preflight.PreflightConfiguration.FONT_PROCESS;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_KEY;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY;
 import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_TRANSPARENCY_EXT_GS_BLEND_MODE;
@@ -33,14 +38,21 @@ import static org.apache.pdfbox.prefligh
 import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_BM_COMPATIBLE;
 import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_BM_NORMAL;
 import static org.apache.pdfbox.preflight.PreflightConstants.TRANSPARENCY_DICTIONARY_VALUE_SOFT_MASK_NONE;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_COMMON;
+import static org.apache.pdfbox.preflight.PreflightConstants.ERROR_SYNTAX_NUMERIC_RANGE;
+import static org.apache.pdfbox.preflight.PreflightConstants.MAX_NEGATIVE_FLOAT;
+import static org.apache.pdfbox.preflight.PreflightConstants.MAX_POSITIVE_FLOAT;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSNumber;
+import org.apache.pdfbox.cos.COSObject;
+
+import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDFontFactory;
 import org.apache.pdfbox.preflight.PreflightConstants;
 import org.apache.pdfbox.preflight.PreflightContext;
 import org.apache.pdfbox.preflight.PreflightPath;
@@ -48,6 +60,7 @@ import org.apache.pdfbox.preflight.Valid
 import org.apache.pdfbox.preflight.exception.ValidationException;
 import org.apache.pdfbox.preflight.process.AbstractProcess;
 import org.apache.pdfbox.preflight.utils.COSUtils;
+import org.apache.pdfbox.preflight.utils.ContextHelper;
 
 public class ExtGStateValidationProcess extends AbstractProcess
 {
@@ -76,6 +89,7 @@ public class ExtGStateValidationProcess
             COSDictionary extGStatesDict = (COSDictionary) vPath.peek();
             List<COSDictionary> listOfExtGState = extractExtGStateDictionaries(context,
extGStatesDict);
             validateTransparencyRules(context, listOfExtGState);
+            validateFonts(context, listOfExtGState);
         }
     }
 
@@ -115,7 +129,7 @@ public class ExtGStateValidationProcess
     }
 
     /**
-     * Validate all ExtGState dictionaries of this container
+     * Validate transparency rules in all ExtGState dictionaries of this container.
      * 
      * @param context the preflight context.
      * @param listOfExtGState a list of ExtGState COSDictionaries.
@@ -135,6 +149,77 @@ public class ExtGStateValidationProcess
     }
 
     /**
+     * Validate fonts in all ExtGState dictionaries of this container.
+     * 
+     * @param context the preflight context.
+     * @param listOfExtGState a list of ExtGState COSDictionaries.
+     * @throws ValidationException
+     * 
+     */
+    protected void validateFonts(PreflightContext context, List<COSDictionary> listOfExtGState)
+            throws ValidationException
+    {
+        for (COSDictionary egs : listOfExtGState)
+        {
+            checkFont(context, egs);
+        }
+    }
+
+    /**
+     * This method checks a Font array in the ExtGState dictionary.
+     * 
+     * @param context the preflight context.
+     * @param egs the Graphic state to check
+     * @throws ValidationException
+     */
+    private void checkFont(PreflightContext context, COSDictionary egs) throws ValidationException
+    {
+        COSBase base = egs.getItem(COSName.FONT);
+        if (!(base instanceof COSArray) || ((COSArray) base).size() != 2)
+        {
+            context.addValidationError(new ValidationError(ERROR_SYNTAX_COMMON,
+                    "/Font entry in /ExtGState must be an array with 2 elements"));
+            return;
+        }
+        COSArray ar = (COSArray) base;
+        COSBase base0 = ar.get(0);
+        if (!(base0 instanceof COSObject))
+        {
+            context.addValidationError(new ValidationError(ERROR_SYNTAX_COMMON,
+                    "1st element in /Font entry in /ExtGState must be an indirect object"));
+            return;
+        }
+        COSBase base1 = ar.getObject(1);
+        if (!(base1 instanceof COSNumber))
+        {
+            context.addValidationError(new ValidationError(ERROR_SYNTAX_COMMON,
+                    "2nd element in /Font entry in /ExtGState must be a number"));
+            return;
+        }
+        COSNumber fontSize = (COSNumber) ar.getObject(1);
+        if (fontSize.floatValue() > MAX_POSITIVE_FLOAT || fontSize.floatValue() < MAX_NEGATIVE_FLOAT)
+        {
+            context.addValidationError(new ValidationError(ERROR_SYNTAX_NUMERIC_RANGE,
+                    "invalid float range in 2nd element in /Font entry in /ExtGState"));
+        }
+        if (ar.getObject(0) instanceof COSDictionary)
+        {
+            COSDictionary fontDict = (COSDictionary) ar.getObject(0);
+            try
+            {
+                PDFont newFont = PDFontFactory.createFont(fontDict);
+                ContextHelper.validateElement(context, newFont, FONT_PROCESS);
+            }
+            catch (IOException e)
+            {
+                //TODO find way to use addFontError from ResourcesValidationProcess
+                //addFontError((COSDictionary)fontDict, context);
+            }
+        }
+
+    }
+
+    /**
      * This method checks the SMask value of the ExtGState dictionary. The Soft Mask is optional
but must be "None" if
      * it is present.
      * 



Mime
View raw message