pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1635700 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: contentstream/PDFStreamEngine.java pdmodel/common/PDRectangle.java pdmodel/graphics/state/PDGraphicsState.java rendering/PageDrawer.java util/Matrix.java
Date Fri, 31 Oct 2014 06:47:28 GMT
Author: jahewson
Date: Fri Oct 31 06:47:27 2014
New Revision: 1635700

URL: http://svn.apache.org/r1635700
Log:
PDFBOX-2423: Use GeneralPath rather than Rectangle2D

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/contentstream/PDFStreamEngine.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java

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=1635700&r1=1635699&r2=1635700&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
Fri Oct 31 06:47:27 2014
@@ -514,7 +514,7 @@ public class PDFStreamEngine
         if (rectangle != null)
         {
             PDRectangle clip = rectangle.transform(getGraphicsState().getCurrentTransformationMatrix());
-            getGraphicsState().intersectClippingPath(new Area(clip.toRectangle2D()));
+            getGraphicsState().intersectClippingPath(new Area(clip.toGeneralPath()));
         }
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java?rev=1635700&r1=1635699&r2=1635700&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDRectangle.java Fri
Oct 31 06:47:27 2014
@@ -16,8 +16,8 @@
  */
 package org.apache.pdfbox.pdmodel.common;
 
+import java.awt.geom.GeneralPath;
 import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSFloat;
@@ -25,7 +25,6 @@ import org.apache.pdfbox.cos.COSNumber;
 
 import org.apache.fontbox.util.BoundingBox;
 
-import java.awt.Dimension;
 import org.apache.pdfbox.util.Matrix;
 
 /**
@@ -307,11 +306,22 @@ public class PDRectangle implements COSO
     }
 
     /**
-     * Returns a new Rectangle2D which is equivalent to this PDRectangle.
+     * Returns a general path equivalent to this rectangle. This method avoids the problems
+     * caused by Rectangle2D not working well with -ve rectangles.
      */
-    public Rectangle2D toRectangle2D()
+    public GeneralPath toGeneralPath()
     {
-        return new Rectangle2D.Float(getLowerLeftX(), getLowerLeftY(), getWidth(), getHeight());
+        float x1 = getLowerLeftX();
+        float y1 = getLowerLeftY();
+        float x2 = getUpperRightX();
+        float y2 = getUpperRightY();
+        GeneralPath path = new GeneralPath();
+        path.moveTo(x1, y1);
+        path.lineTo(x2, y1);
+        path.lineTo(x2, y2);
+        path.lineTo(x1, y2);
+        path.closePath();
+        return path;
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java?rev=1635700&r1=1635699&r2=1635700&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/state/PDGraphicsState.java
Fri Oct 31 06:47:27 2014
@@ -74,7 +74,7 @@ public class PDGraphicsState implements 
      */
     public PDGraphicsState(PDRectangle page)
     {
-        clippingPath = new Area(new GeneralPath(page.toRectangle2D()));
+        clippingPath = new Area(page.toGeneralPath());
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1635700&r1=1635699&r2=1635700&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Fri Oct
31 06:47:27 2014
@@ -826,7 +826,7 @@ public class PageDrawer extends PDFGraph
             // check underlying g2d
 
             Area groupClip = new Area(getGraphicsState().getCurrentClippingPath());
-            Area clippingPath = new Area(new GeneralPath(form.getBBox().toRectangle2D()));
+            Area clippingPath = new Area(form.getBBox().toGeneralPath());
             Area newArea = new Area(clippingPath);
             groupClip.intersect(newArea);
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java?rev=1635700&r1=1635699&r2=1635700&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java Fri Oct 31 06:47:27
2014
@@ -436,28 +436,6 @@ public class Matrix implements Cloneable
     }
 
     /**
-     * This will return a string representation of the matrix.
-     *
-     * @return The matrix as a string.
-     */
-    public String toString()
-    {
-        StringBuffer result = new StringBuffer( "" );
-        result.append( "[[" );
-        result.append( single[0] + "," );
-        result.append( single[1] + "," );
-        result.append( single[2] + "][");
-        result.append( single[3] + "," );
-        result.append( single[4] + "," );
-        result.append( single[5] + "][");
-        result.append( single[6] + "," );
-        result.append( single[7] + "," );
-        result.append( single[8] + "]]");
-
-        return result.toString();
-    }
-
-    /**
      * Get the xscaling factor of this matrix.
      * @return The x-scale.
      */
@@ -537,4 +515,18 @@ public class Matrix implements Cloneable
         array.add(new COSFloat(7));
         return array;
     }
+
+    @Override
+    public String toString()
+    {
+        StringBuffer sb = new StringBuffer( "" );
+        sb.append("[");
+        sb.append(single[0] + ",");
+        sb.append(single[1] + ",");
+        sb.append(single[3] + ",");
+        sb.append(single[4] + ",");
+        sb.append(single[6] + ",");
+        sb.append(single[7] + "]");
+        return sb.toString();
+    }
 }



Mime
View raw message