pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1646060 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text: SetCharSpacing.java SetFontAndSize.java
Date Tue, 16 Dec 2014 19:44:12 GMT
Author: jahewson
Date: Tue Dec 16 19:44:11 2014
New Revision: 1646060

URL: http://svn.apache.org/r1646060
Log:
PDFBOX-2566: Throw MissingOperandException for missing operands

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetCharSpacing.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetFontAndSize.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetCharSpacing.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetCharSpacing.java?rev=1646060&r1=1646059&r2=1646060&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetCharSpacing.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetCharSpacing.java
Tue Dec 16 19:44:11 2014
@@ -16,8 +16,10 @@
  */
 package org.apache.pdfbox.contentstream.operator.text;
 
+import java.io.IOException;
 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;
@@ -31,20 +33,21 @@ import org.apache.pdfbox.contentstream.o
 public class SetCharSpacing extends OperatorProcessor
 {
     @Override
-    public void process(Operator operator, List<COSBase> arguments)
+    public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
-        //set character spacing
-        if(arguments.size() > 0)
+        if (arguments.size() == 0)
         {
-            //There are some documents which are incorrectly structured, and have
-            //a wrong number of arguments to this, so we will assume the last argument
-            //in the list
-            Object charSpacing = arguments.get(arguments.size()-1);
-            if(charSpacing instanceof COSNumber)
-            {
-                COSNumber characterSpacing = (COSNumber)charSpacing;
-                context.getGraphicsState().getTextState().setCharacterSpacing(characterSpacing.floatValue());
-            }
+            throw new MissingOperandException(operator, arguments);
+        }
+
+        // there are some documents which are incorrectly structured, and have
+        // a wrong number of arguments to this, so we will assume the last argument
+        // in the list
+        Object charSpacing = arguments.get(arguments.size()-1);
+        if (charSpacing instanceof COSNumber)
+        {
+            COSNumber characterSpacing = (COSNumber)charSpacing;
+            context.getGraphicsState().getTextState().setCharacterSpacing(characterSpacing.floatValue());
         }
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetFontAndSize.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetFontAndSize.java?rev=1646060&r1=1646059&r2=1646060&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetFontAndSize.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/text/SetFontAndSize.java
Tue Dec 16 19:44:11 2014
@@ -19,6 +19,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.COSName;
 import org.apache.pdfbox.cos.COSNumber;
@@ -38,18 +39,16 @@ public class SetFontAndSize extends Oper
     @Override
     public void process(Operator operator, List<COSBase> arguments) throws IOException
     {
-        // there are some documents that are incorrectly structured and
-        // arguments are in the wrong spot, so we will silently ignore them
-        // if there are no arguments
-        if(arguments.size() >= 2)
+        if (arguments.size() < 2)
         {
-            // set font and size
-            COSName fontName = (COSName)arguments.get(0);
-            float fontSize = ((COSNumber)arguments.get(1)).floatValue();
-            context.getGraphicsState().getTextState().setFontSize(fontSize);
-            PDFont font = context.getResources().getFont(fontName);
-            context.getGraphicsState().getTextState().setFont(font);
+            throw new MissingOperandException(operator, arguments);
         }
+
+        COSName fontName = (COSName)arguments.get(0);
+        float fontSize = ((COSNumber)arguments.get(1)).floatValue();
+        context.getGraphicsState().getTextState().setFontSize(fontSize);
+        PDFont font = context.getResources().getFont(fontName);
+        context.getGraphicsState().getTextState().setFont(font);
     }
 
     @Override



Mime
View raw message