Return-Path: X-Original-To: apmail-pdfbox-commits-archive@www.apache.org Delivered-To: apmail-pdfbox-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BE034107AD for ; Tue, 16 Dec 2014 19:44:16 +0000 (UTC) Received: (qmail 77659 invoked by uid 500); 16 Dec 2014 19:44:16 -0000 Delivered-To: apmail-pdfbox-commits-archive@pdfbox.apache.org Received: (qmail 77640 invoked by uid 500); 16 Dec 2014 19:44:16 -0000 Mailing-List: contact commits-help@pdfbox.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pdfbox.apache.org Delivered-To: mailing list commits@pdfbox.apache.org Received: (qmail 77630 invoked by uid 99); 16 Dec 2014 19:44:16 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Dec 2014 19:44:16 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id CB7BEAC0958; Tue, 16 Dec 2014 19:44:14 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@pdfbox.apache.org From: jahewson@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20141216194415.CB7BEAC0958@hades.apache.org> 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 arguments) + public void process(Operator operator, List 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 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