pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1669278 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics: ClosePath.java CurveTo.java LineTo.java
Date Thu, 26 Mar 2015 07:08:37 GMT
Author: tilman
Date: Thu Mar 26 07:08:36 2015
New Revision: 1669278

URL: http://svn.apache.org/r1669278
Log:
PDFBOX-2728: fail gracefully if initial MoveTo is missing

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/ClosePath.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/CurveTo.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/LineTo.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/ClosePath.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/ClosePath.java?rev=1669278&r1=1669277&r2=1669278&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/ClosePath.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/ClosePath.java
Thu Mar 26 07:08:36 2015
@@ -19,6 +19,8 @@ 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.contentstream.operator.Operator;
 
@@ -29,9 +31,16 @@ import org.apache.pdfbox.contentstream.o
  */
 public final class ClosePath extends GraphicsOperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(ClosePath.class);
+    
     @Override
     public void process(Operator operator, List<COSBase> operands) throws IOException
     {
+        if (context.getCurrentPoint() == null)
+        {
+            LOG.warn("ClosePath without initial MoveTo");
+            return;
+        }
         context.closePath();
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/CurveTo.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/CurveTo.java?rev=1669278&r1=1669277&r2=1669278&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/CurveTo.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/CurveTo.java
Thu Mar 26 07:08:36 2015
@@ -19,6 +19,8 @@ package org.apache.pdfbox.contentstream.
 import java.io.IOException;
 import java.util.List;
 import java.awt.geom.Point2D;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSNumber;
@@ -31,6 +33,8 @@ import org.apache.pdfbox.contentstream.o
  */
 public class CurveTo extends GraphicsOperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(CurveTo.class);
+    
     @Override
     public void process(Operator operator, List<COSBase> operands) throws IOException
     {
@@ -45,9 +49,17 @@ public class CurveTo extends GraphicsOpe
         Point2D.Float point2 = context.transformedPoint(x2.floatValue(), y2.floatValue());
         Point2D.Float point3 = context.transformedPoint(x3.floatValue(), y3.floatValue());
 
-        context.curveTo(point1.x, point1.y,
-                        point2.x, point2.y,
-                        point3.x, point3.y);
+        if (context.getCurrentPoint() == null)
+        {
+            LOG.warn("curveTo (" + point3.x + "," + point3.y + ") without initial MoveTo");
+            context.moveTo(point3.x, point3.y);
+        }
+        else
+        {
+            context.curveTo(point1.x, point1.y,
+                    point2.x, point2.y,
+                    point3.x, point3.y);
+        }
     }
 
     @Override

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/LineTo.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/LineTo.java?rev=1669278&r1=1669277&r2=1669278&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/LineTo.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/operator/graphics/LineTo.java
Thu Mar 26 07:08:36 2015
@@ -20,6 +20,8 @@ import java.io.IOException;
 import java.util.List;
 import java.awt.geom.Point2D;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.contentstream.operator.Operator;
@@ -31,6 +33,8 @@ import org.apache.pdfbox.contentstream.o
  */
 public class LineTo extends GraphicsOperatorProcessor
 {
+    private static final Log LOG = LogFactory.getLog(LineTo.class);
+    
     @Override
     public void process(Operator operator, List<COSBase> operands) throws IOException
     {
@@ -39,7 +43,16 @@ public class LineTo extends GraphicsOper
         COSNumber y = (COSNumber)operands.get(1);
 
         Point2D.Float pos = context.transformedPoint(x.floatValue(), y.floatValue());
-        context.lineTo(pos.x, pos.y);
+
+        if (context.getCurrentPoint() == null)
+        {
+            LOG.warn("LineTo (" + pos.x + "," + pos.y + ") without initial MoveTo");
+            context.moveTo(pos.x, pos.y);
+        }
+        else
+        {
+            context.lineTo(pos.x, pos.y);
+        }
     }
 
     @Override



Mime
View raw message