You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/12/14 01:26:02 UTC

svn commit: r1645372 - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/util/ pdfbox/src/main/java/org/apache/pdfbox/contentstream/ pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/ pdfbox/src/main/java/org/apache/pdfbox...

Author: jahewson
Date: Sun Dec 14 00:26:01 2014
New Revision: 1645372

URL: http://svn.apache.org/r1645372
Log:
PDFBOX-2566: Move logging from Operator classes to PDFStreamEngine

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/MissingOperandException.java   (with props)
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/EmptyGraphicsStackException.java   (with props)
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/MissingResourceException.java   (with props)
Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingColorSpace.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingColorSpace.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/Restore.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineDashPattern.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineWidth.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/content/PreflightContentStream.java
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PreflightType3Stream.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java (original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/util/PrintImageLocations.java Sun Dec 14 00:26:01 2014
@@ -105,16 +105,16 @@ public class PrintImageLocations extends
      * This is used to handle an operation.
      *
      * @param operator The operation to perform.
-     * @param arguments The list of arguments.
+     * @param operands The list of arguments.
      *
      * @throws IOException If there is an error processing the operation.
      */
-    protected void processOperator( Operator operator, List<COSBase> arguments ) throws IOException
+    protected void processOperator( Operator operator, List<COSBase> operands) throws IOException
     {
         String operation = operator.getName();
         if( "Do".equals(operation) )
         {
-            COSName objectName = (COSName)arguments.get( 0 );
+            COSName objectName = (COSName) operands.get( 0 );
             PDXObject xobject = getResources().getXObject( objectName );
             if( xobject instanceof PDImageXObject)
             {
@@ -169,7 +169,7 @@ public class PrintImageLocations extends
         }
         else
         {
-            super.processOperator( operator, arguments );
+            super.processOperator( operator, operands);
         }
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java Sun Dec 14 00:26:01 2014
@@ -31,12 +31,16 @@ import java.util.Stack;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.pdfbox.contentstream.operator.MissingOperandException;
+import org.apache.pdfbox.contentstream.operator.state.EmptyGraphicsStackException;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSObject;
 import org.apache.pdfbox.cos.COSString;
+import org.apache.pdfbox.filter.MissingImageReaderException;
 import org.apache.pdfbox.pdfparser.PDFStreamParser;
+import org.apache.pdfbox.pdmodel.MissingResourceException;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
@@ -44,6 +48,7 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.font.PDFontFactory;
 import org.apache.pdfbox.pdmodel.font.PDType3CharProc;
 import org.apache.pdfbox.pdmodel.font.PDType3Font;
+import org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColorSpace;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
@@ -789,21 +794,28 @@ public class PDFStreamEngine
      * This is used to handle an operation.
      * 
      * @param operator The operation to perform.
-     * @param arguments The list of arguments.
+     * @param operands The list of arguments.
      * @throws IOException If there is an error processing the operation.
      */
-    protected void processOperator(Operator operator, List<COSBase> arguments) throws IOException
+    protected void processOperator(Operator operator, List<COSBase> operands) throws IOException
     {
         String name = operator.getName();
         OperatorProcessor processor = operators.get(name);
         if (processor != null)
         {
             processor.setContext(this);
-            processor.process(operator, arguments);
+            try
+            {
+                processor.process(operator, operands);
+            }
+            catch (IOException e)
+            {
+                operatorException(operator, operands, e);
+            }
         }
         else
         {
-            unsupportedOperator(operator, arguments);
+            unsupportedOperator(operator, operands);
         }
     }
 
@@ -811,14 +823,45 @@ public class PDFStreamEngine
      * Called when an unsupported operator is encountered.
      *
      * @param operator The unknown operator.
-     * @param arguments The list of arguments.
+     * @param operands The list of operands.
      */
-    protected void unsupportedOperator(Operator operator, List<COSBase> arguments) throws IOException
+    protected void unsupportedOperator(Operator operator, List<COSBase> operands) throws IOException
     {
         // overridden in subclasses
     }
 
     /**
+     * Called when an exception is thrown by an operator.
+     *
+     * @param operator The unknown operator.
+     * @param operands The list of operands.
+     */
+    protected void operatorException(Operator operator, List<COSBase> operands, IOException e)
+            throws IOException
+    {
+        if (e instanceof MissingOperandException ||
+            e instanceof MissingResourceException ||
+            e instanceof MissingImageReaderException)
+        {
+            LOG.error(e.getMessage());
+        }
+        else if (e instanceof EmptyGraphicsStackException)
+        {
+            LOG.warn(e.getMessage());
+        }
+        else if (operator.getName().equals("Do"))
+        {
+            // todo: this too forgiving, but PDFBox has always worked this way for DrawObject
+            //       some careful refactoring is needed
+            LOG.warn(e.getMessage());
+        }
+        else
+        {
+            throw e;
+        }
+    }
+
+    /**
      * Pushes the current graphics state to the stack.
      */
     public void saveGraphicsState()
@@ -881,7 +924,22 @@ public class PDFStreamEngine
     {
         textMatrix = value;
     }
-    
+
+    /**
+     * @param array dash array
+     * @param phase dash phase
+     */
+    public void setLineDashPattern(COSArray array, int phase)
+    {
+        if (phase < 0)
+        {
+            LOG.warn("Dash phase has negative value " + phase + ", set to 0");
+            phase = 0;
+        }
+        PDLineDashPattern lineDash = new PDLineDashPattern(array, phase);
+        getGraphicsState().setLineDashPattern(lineDash);
+    }
+
     /**
      * Returns the stream' resources.
      */

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/MissingOperandException.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/MissingOperandException.java?rev=1645372&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/MissingOperandException.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/MissingOperandException.java Sun Dec 14 00:26:01 2014
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.contentstream.operator;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.pdfbox.cos.COSBase;
+
+/**
+ * Throw when a PDF operator is missing required operands.
+ */
+public final class MissingOperandException extends IOException
+{
+    public MissingOperandException(Operator operator, List<COSBase> operands)
+    {
+        super("Operator " + operator.getName() + " has too few operands: " + operands);
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/MissingOperandException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/OperatorProcessor.java Sun Dec 14 00:26:01 2014
@@ -20,8 +20,6 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.contentstream.PDFStreamEngine;
 import java.util.List;
 import java.io.IOException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * Processes a PDF operator.
@@ -30,11 +28,6 @@ import org.apache.commons.logging.LogFac
  */
 public abstract class OperatorProcessor
 {
-    /**
-     * Log instance.
-     */
-    private static final Log LOG = LogFactory.getLog(OperatorProcessor.class);
-
     /** The processing context. */
     protected PDFStreamEngine context;
 
@@ -49,7 +42,7 @@ public abstract class OperatorProcessor
      * Returns the processing context.
      * @return the processing context
      */
-    protected PDFStreamEngine getContext()
+    protected final PDFStreamEngine getContext()
     {
         return context;
     }
@@ -75,22 +68,4 @@ public abstract class OperatorProcessor
      * Returns the name of this operator, e.g. "BI".
      */
     public abstract String getName();
-
-    /**
-     * Check the size of the arguments and puts out a warning if the size doesn't match.
-     *
-     * @param arguments Arguments for this operator.
-     * @param expectedSize Expected arguments size.
-     * @return true if size is correct, false if not.
-     */
-    protected boolean checkArgumentSize(List<COSBase> arguments, int expectedSize)
-    {
-        if (arguments.size() < expectedSize)
-        {
-            LOG.warn("'" + getName() + "' operator must have " + expectedSize
-                    + " parameters, but has " + arguments.size());
-            return false;
-}
-        return true;
-    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetColor.java Sun Dec 14 00:26:01 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.contentstream.operator.color;
 
+import org.apache.pdfbox.contentstream.operator.MissingOperandException;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
@@ -38,10 +39,10 @@ public abstract class SetColor extends O
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
         PDColorSpace colorSpace = getColorSpace();
-        if (colorSpace instanceof PDDeviceColorSpace
-                && !checkArgumentSize(arguments, colorSpace.getNumberOfComponents()))
+        if (colorSpace instanceof PDDeviceColorSpace &&
+            arguments.size() < colorSpace.getNumberOfComponents())
         {
-            return;
+            throw new MissingOperandException(operator, arguments);
         }
         COSArray array = new COSArray();
         array.addAll(arguments);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingColorSpace.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingColorSpace.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetNonStrokingColorSpace.java Sun Dec 14 00:26:01 2014
@@ -35,23 +35,14 @@ import org.apache.pdfbox.contentstream.o
  */
 public class SetNonStrokingColorSpace extends OperatorProcessor
 {
-    private static final Log LOG = LogFactory.getLog(SetNonStrokingColorSpace.class);
-
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
         COSName name = (COSName)arguments.get(0);
 
-        try
-        {
-            PDColorSpace cs = context.getResources().getColorSpace(name);
-            context.getGraphicsState().setNonStrokingColorSpace(cs);
-            context.getGraphicsState().setNonStrokingColor(cs.getInitialColor());
-        }
-        catch (PDColorSpace.MissingException e)
-        {
-            LOG.error("Missing color space: " + name.getName());
-        }
+        PDColorSpace cs = context.getResources().getColorSpace(name);
+        context.getGraphicsState().setNonStrokingColorSpace(cs);
+        context.getGraphicsState().setNonStrokingColor(cs.getInitialColor());
     }
 
     @Override
@@ -59,4 +50,4 @@ public class SetNonStrokingColorSpace ex
     {
         return "cs";
     }
-}
\ No newline at end of file
+}

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingColorSpace.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingColorSpace.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/color/SetStrokingColorSpace.java Sun Dec 14 00:26:01 2014
@@ -35,23 +35,14 @@ import org.apache.pdfbox.contentstream.o
  */
 public class SetStrokingColorSpace extends OperatorProcessor
 {
-    private static final Log LOG = LogFactory.getLog(SetStrokingColorSpace.class);
-
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
         COSName name = (COSName)arguments.get(0);
 
-        try
-        {
-            PDColorSpace cs = context.getResources().getColorSpace(name);
-            context.getGraphicsState().setStrokingColorSpace(cs);
-            context.getGraphicsState().setStrokingColor(cs.getInitialColor());
-        }
-        catch (PDColorSpace.MissingException e)
-        {
-            LOG.error("Missing color space: " + name.getName());
-        }
+        PDColorSpace cs = context.getResources().getColorSpace(name);
+        context.getGraphicsState().setStrokingColorSpace(cs);
+        context.getGraphicsState().setStrokingColor(cs.getInitialColor());
     }
 
     @Override

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/DrawObject.java Sun Dec 14 00:26:01 2014
@@ -19,11 +19,9 @@ package org.apache.pdfbox.contentstream.
 import java.io.IOException;
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.filter.MissingImageReaderException;
+import org.apache.pdfbox.pdmodel.MissingResourceException;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.pdmodel.graphics.PDXObject;
@@ -37,8 +35,6 @@ import org.apache.pdfbox.contentstream.o
  */
 public final class DrawObject extends GraphicsOperatorProcessor
 {
-    private static final Log LOG = LogFactory.getLog(DrawObject.class);
-
     @Override
     public void process(Operator operator, List<COSBase> operands) throws IOException
     {
@@ -47,30 +43,18 @@ public final class DrawObject extends Gr
 
         if (xobject == null)
         {
-            LOG.warn("Can't find the XObject named '" + objectName.getName() + "'");
+            throw new MissingResourceException("Missing XObject: " + objectName.getName());
         }
         else if (xobject instanceof PDImageXObject)
         {
             PDImageXObject image = (PDImageXObject)xobject;
-            try
-            {
-                context.drawImage(image);
-            }
-            catch (MissingImageReaderException e)
-            {
-                // missing ImageIO plug-in  TODO how far should we escalate this? (after all the user can fix the problem)
-                LOG.error(e.getMessage());
-            }
-            catch (Exception e)
-            {
-                // TODO we probably shouldn't catch Exception, what errors are expected here?
-                LOG.error(e, e);
-            }
+            context.drawImage(image);
         }
         else if (xobject instanceof PDFormXObject)
         {
             PDFormXObject form = (PDFormXObject) xobject;
-            if (form.getGroup() != null && COSName.TRANSPARENCY.equals(form.getGroup().getSubType())) {
+            if (form.getGroup() != null &&
+                COSName.TRANSPARENCY.equals(form.getGroup().getSubType())) {
                 getContext().showTransparencyGroup(form);
             }
             else

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/EmptyGraphicsStackException.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/EmptyGraphicsStackException.java?rev=1645372&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/EmptyGraphicsStackException.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/EmptyGraphicsStackException.java Sun Dec 14 00:26:01 2014
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.contentstream.operator.state;
+
+import java.io.IOException;
+
+/**
+ * Throw when restore is executed when the graphics stack is empty.
+ */
+public final class EmptyGraphicsStackException extends IOException
+{
+    EmptyGraphicsStackException()
+    {
+        super("Cannot execute restore, the graphics stack is empty");
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/EmptyGraphicsStackException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/Restore.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/Restore.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/Restore.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/Restore.java Sun Dec 14 00:26:01 2014
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.contentstream.operator.state;
 
+import java.io.IOException;
 import java.util.List;
 
 import org.apache.commons.logging.Log;
@@ -34,7 +35,7 @@ public class Restore extends OperatorPro
     private static final Log LOG = LogFactory.getLog(Restore.class);
 
     @Override
-    public void process(Operator operator, List<COSBase> arguments)
+    public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
         if (context.getGraphicsStackSize() > 1)
         {
@@ -43,7 +44,7 @@ public class Restore extends OperatorPro
         else
         {
             // this shouldn't happen but it does, see PDFBOX-161
-            LOG.error("GRestore: no graphics state left to be restored.");
+            throw new EmptyGraphicsStackException();
         }
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineDashPattern.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineDashPattern.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineDashPattern.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineDashPattern.java Sun Dec 14 00:26:01 2014
@@ -18,13 +18,9 @@ package org.apache.pdfbox.contentstream.
 
 import java.util.List;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSNumber;
-import org.apache.pdfbox.pdmodel.graphics.PDLineDashPattern;
 import org.apache.pdfbox.contentstream.operator.Operator;
 import org.apache.pdfbox.contentstream.operator.OperatorProcessor;
 
@@ -35,23 +31,12 @@ import org.apache.pdfbox.contentstream.o
  */
 public class SetLineDashPattern extends OperatorProcessor
 {
-    /**
-     * log instance
-     */
-    private static final Log LOG = LogFactory.getLog(SetLineDashPattern.class);
-
     @Override
     public void process(Operator operator, List<COSBase> arguments)
     {
         COSArray dashArray = (COSArray) arguments.get(0);
         int dashPhase = ((COSNumber) arguments.get(1)).intValue();
-        if (dashPhase < 0)
-        {
-            LOG.warn("dash phaseStart has negative value " + dashPhase + ", set to 0");
-            dashPhase = 0;
-        }
-        PDLineDashPattern lineDash = new PDLineDashPattern(dashArray, dashPhase);
-        context.getGraphicsState().setLineDashPattern(lineDash);
+        context.setLineDashPattern(dashArray, dashPhase);
     }
 
     @Override

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineWidth.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineWidth.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineWidth.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/state/SetLineWidth.java Sun Dec 14 00:26:01 2014
@@ -18,6 +18,7 @@ package org.apache.pdfbox.contentstream.
 
 import java.util.List;
 
+import org.apache.pdfbox.contentstream.operator.MissingOperandException;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.contentstream.operator.Operator;
@@ -35,9 +36,9 @@ public class SetLineWidth extends Operat
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
-        if (!checkArgumentSize(arguments, 1))
+        if (arguments.size() < 1)
         {
-            return;
+            throw new MissingOperandException(operator, arguments);
         }
         COSNumber width = (COSNumber) arguments.get(0);
         context.getGraphicsState().setLineWidth(width.floatValue());

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/MissingResourceException.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/MissingResourceException.java?rev=1645372&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/MissingResourceException.java (added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/MissingResourceException.java Sun Dec 14 00:26:01 2014
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.pdmodel;
+
+import java.io.IOException;
+
+/**
+ * Thrown when a named resource is missing.
+ */
+public final class MissingResourceException extends IOException
+{
+    public MissingResourceException(String message)
+    {
+        super(message);
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/MissingResourceException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/color/PDColorSpace.java Sun Dec 14 00:26:01 2014
@@ -20,6 +20,7 @@ import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSObject;
+import org.apache.pdfbox.pdmodel.MissingResourceException;
 import org.apache.pdfbox.pdmodel.PDResources;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 
@@ -56,7 +57,7 @@ public abstract class PDColorSpace imple
      * @param colorSpace the color space COS object
      * @param resources the current resources.
      * @return a new color space
-     * @throws MissingException if the color space is missing from the resources dictionary
+     * @throws MissingResourceException if the color space is missing in the resources dictionary
      * @throws IOException if the color space is unknown or cannot be created
      */
     public static PDColorSpace create(COSBase colorSpace,
@@ -120,13 +121,13 @@ public abstract class PDColorSpace imple
             {
                 if (!resources.hasColorSpace(name))
                 {
-                    throw new MissingException("Missing color space: " + name.getName());
+                    throw new MissingResourceException("Missing color space: " + name.getName());
                 }
                 return resources.getColorSpace(name);
             }
             else
             {
-                throw new MissingException("Unknown color space: " + name.getName());
+                throw new MissingResourceException("Unknown color space: " + name.getName());
             }
         }
         else if (colorSpace instanceof COSArray)
@@ -266,12 +267,4 @@ public abstract class PDColorSpace imple
     {
         return array;
     }
-
-    public static class MissingException extends IOException
-    {
-        private MissingException(String message)
-        {
-            super(message);
-        }
-    }
 }

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=1645372&r1=1645371&r2=1645372&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 Sun Dec 14 00:26:01 2014
@@ -135,9 +135,9 @@ public class PreflightContentStream exte
     }
 
     @Override
-    protected void processOperator(Operator operator, List<COSBase> arguments) throws IOException
+    protected void processOperator(Operator operator, List<COSBase> operands) throws IOException
     {
-        super.processOperator(operator, arguments);
+        super.processOperator(operator, operands);
 
         // todo: why are the checks below done here and not in OperatorProcessor classes?
 
@@ -150,10 +150,10 @@ public class PreflightContentStream exte
             validateImageColorSpace(operator);
         }
 
-        checkShowTextOperators(operator, arguments);
+        checkShowTextOperators(operator, operands);
         checkColorOperators(operator.getName());
-        validateRenderingIntent(operator, arguments);
-        checkSetColorSpaceOperators(operator, arguments);
+        validateRenderingIntent(operator, operands);
+        checkSetColorSpaceOperators(operator, operands);
         validateNumberOfGraphicStates(operator);
     }
 

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PreflightType3Stream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PreflightType3Stream.java?rev=1645372&r1=1645371&r2=1645372&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PreflightType3Stream.java (original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/font/util/PreflightType3Stream.java Sun Dec 14 00:26:01 2014
@@ -80,15 +80,15 @@ public class PreflightType3Stream extend
      * 
      * @param operator
      *            The operation to perform.
-     * @param arguments
+     * @param operands
      *            The list of arguments.
      * 
      * @throws IOException
      *             If there is an error processing the operation.
      */
-    protected void processOperator(Operator operator, List arguments) throws IOException
+    protected void processOperator(Operator operator, List operands) throws IOException
     {
-        super.processOperator(operator, arguments);
+        super.processOperator(operator, operands);
         String operation = operator.getName();
 
         if (operation.equals("BI"))
@@ -109,7 +109,7 @@ public class PreflightType3Stream extend
             // width = horizontalWidth.intValue();
             // height = verticalWidth.intValue();
 
-            checkType3FirstOperator(arguments);
+            checkType3FirstOperator(operands);
 
         }
         else if (operation.equals("d1"))
@@ -117,10 +117,10 @@ public class PreflightType3Stream extend
             // set glyph with and bounding box for type 3 font
             // COSNumber horizontalWidth = (COSNumber)arguments.get( 0 );
             // COSNumber verticalWidth = (COSNumber)arguments.get( 1 );
-            COSNumber llx = (COSNumber) arguments.get(2);
-            COSNumber lly = (COSNumber) arguments.get(3);
-            COSNumber urx = (COSNumber) arguments.get(4);
-            COSNumber ury = (COSNumber) arguments.get(5);
+            COSNumber llx = (COSNumber) operands.get(2);
+            COSNumber lly = (COSNumber) operands.get(3);
+            COSNumber urx = (COSNumber) operands.get(4);
+            COSNumber ury = (COSNumber) operands.get(5);
 
             // width = horizontalWidth.intValue();
             // height = verticalWidth.intValue();
@@ -130,12 +130,12 @@ public class PreflightType3Stream extend
             box.setUpperRightX(urx.floatValue());
             box.setUpperRightY(ury.floatValue());
 
-            checkType3FirstOperator(arguments);
+            checkType3FirstOperator(operands);
         }
 
         checkColorOperators(operation);
-        validateRenderingIntent(operator, arguments);
-        checkSetColorSpaceOperators(operator, arguments);
+        validateRenderingIntent(operator, operands);
+        checkSetColorSpaceOperators(operator, operands);
         validateNumberOfGraphicStates(operator);
         firstOperator = false;
     }