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/31 04:17:53 UTC

svn commit: r1648650 - in /pdfbox/trunk/pdfbox/src: main/java/org/apache/pdfbox/rendering/TilingPaint.java main/java/org/apache/pdfbox/util/Matrix.java test/java/org/apache/pdfbox/util/TestMatrix.java

Author: jahewson
Date: Wed Dec 31 03:17:52 2014
New Revision: 1648650

URL: http://svn.apache.org/r1648650
Log:
PDFBOX-1094: Take into account page rotation when calculating pattern scale

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/Matrix.java
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestMatrix.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java?rev=1648650&r1=1648649&r2=1648650&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/TilingPaint.java Wed Dec 31 03:17:52 2014
@@ -121,9 +121,10 @@ class TilingPaint implements Paint
         float width = (float)Math.abs(anchor.getWidth());
         float height = (float)Math.abs(anchor.getHeight());
 
-        // device transform (i.e. DPI)
-        width *= (float)xform.getScaleX();
-        height *= (float)xform.getScaleY();
+        // device scale transform (i.e. DPI) (see PDFBOX-1466.pdf)
+        Matrix xformMatrix = new Matrix(xform);
+        width *= xformMatrix.getScalingFactorX();
+        height *= xformMatrix.getScalingFactorY();
 
         int rasterWidth = Math.max(1, ceiling(width));
         int rasterHeight = Math.max(1, ceiling(height));
@@ -148,8 +149,8 @@ class TilingPaint implements Paint
             graphics.scale(-1, 1);
         }
 
-        // device transform (i.e. DPI)
-        graphics.transform(xform);
+        // device scale transform (i.e. DPI)
+        graphics.scale(xformMatrix.getScalingFactorX(), xformMatrix.getScalingFactorY());
 
         // apply only the scaling from the pattern transform, doing scaling here improves the
         // image quality and prevents large scale-down factors from creating huge tiling cells.

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=1648650&r1=1648649&r2=1648650&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 Wed Dec 31 03:17:52 2014
@@ -45,11 +45,11 @@ public final class Matrix implements Clo
     public Matrix()
     {
         single = new float[DEFAULT_SINGLE.length];
-        reset();
+        System.arraycopy(DEFAULT_SINGLE, 0, single, 0, DEFAULT_SINGLE.length);
     }
 
     /**
-     * Constructor.
+     * Creates a matrix from a 6-element COS array.
      */
     public Matrix(COSArray array)
     {
@@ -64,7 +64,7 @@ public final class Matrix implements Clo
     }
 
     /**
-     * Constructor.
+     * Creates a matrix with the given 6 elements.
      */
     public Matrix(float a, float b, float c, float d, float e, float f)
     {
@@ -79,9 +79,27 @@ public final class Matrix implements Clo
     }
 
     /**
+     * Creates a matrix with the same elements as the given AffineTransform.
+     */
+    public Matrix(AffineTransform at)
+    {
+        single = new float[DEFAULT_SINGLE.length];
+        System.arraycopy(DEFAULT_SINGLE, 0, single, 0, DEFAULT_SINGLE.length);
+        single[0] = (float)at.getScaleX();
+        single[1] = (float)at.getShearY();
+        single[3] = (float)at.getShearX();
+        single[4] = (float)at.getScaleY();
+        single[6] = (float)at.getTranslateX();
+        single[7] = (float)at.getTranslateY();
+    }
+
+    /**
      * This method resets the numbers in this Matrix to the original values, which are
      * the values that a newly constructed Matrix would have.
+     *
+     * @deprecated This method will be removed.
      */
+    @Deprecated
     public void reset()
     {
         System.arraycopy(DEFAULT_SINGLE, 0, single, 0, DEFAULT_SINGLE.length);
@@ -104,7 +122,7 @@ public final class Matrix implements Clo
      * Set the values of the matrix from the AffineTransform.
      *
      * @param af The transform to get the values from.
-     * @deprecated This method is due to be removed, please contact us if you make use of it.
+     * @deprecated Use the {@link #Matrix(AffineTransform)} constructor instead.
      */
     @Deprecated
     public void setFromAffineTransform( AffineTransform af )

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestMatrix.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestMatrix.java?rev=1648650&r1=1648649&r2=1648650&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestMatrix.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/util/TestMatrix.java Wed Dec 31 03:17:52 2014
@@ -88,10 +88,6 @@ public class TestMatrix extends TestCase
         assertMatrixValuesEqualTo(new float[] {5,  8,  11,
                                                8,  14, 20,
                                                11, 20, 29}, product);
-        product.reset();
-        assertMatrixIsPristine(product);
-
-
 
         // Multiply two matrices together with the result being written to a third matrix
         // (Any existing values there will be overwritten).