pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1691272 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading: AxialShadingContext.java RadialShadingContext.java
Date Wed, 15 Jul 2015 20:45:08 GMT
Author: jahewson
Date: Wed Jul 15 20:45:07 2015
New Revision: 1691272

URL: http://svn.apache.org/r1691272
Log:
PDFBOX-2881: Take into account the angle of the shading

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java?rev=1691272&r1=1691271&r2=1691272&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/AxialShadingContext.java
Wed Jul 15 20:45:07 2015
@@ -20,6 +20,7 @@ import java.awt.PaintContext;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.NoninvertibleTransformException;
+import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
@@ -115,14 +116,23 @@ public class AxialShadingContext extends
             LOG.error(ex, ex);
         }
 
-        // get the number of steps
-        factor = (int) Math.max(Math.abs(deviceBounds.getWidth()),
-                                Math.abs(deviceBounds.getHeight()));
+        // shading space -> device space
+        AffineTransform shadingToDevice = (AffineTransform)xform.clone();
+        shadingToDevice.concatenate(matrix.createAffineTransform());
+        
+        // convert the start and end coordinates to device space
+        Point2D p0 = new Point2D.Double(coords[0], coords[1]);
+        Point2D p1 = new Point2D.Double(coords[2], coords[3]);
+        shadingToDevice.transform(p0, p0);
+        shadingToDevice.transform(p1, p1);
+        
+        // the distance between them is number of steps
+        factor = (int)Math.round(p0.distance(p1));
         
         // build the color table for the given number of steps
         colorTable = calcColorTable();
     }
-
+    
     /**
      * Calculate the color on the axial line and store them in an array.
      *

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java?rev=1691272&r1=1691271&r2=1691272&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/shading/RadialShadingContext.java
Wed Jul 15 20:45:07 2015
@@ -20,6 +20,7 @@ import java.awt.PaintContext;
 import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.NoninvertibleTransformException;
+import java.awt.geom.Point2D;
 import java.awt.image.ColorModel;
 import java.awt.image.Raster;
 import java.awt.image.WritableRaster;
@@ -121,9 +122,18 @@ public class RadialShadingContext extend
             LOG.error(ex, ex);
         }
 
-        // get the number of steps
-        factor = (int) Math.max(Math.abs(deviceBounds.getWidth()),
-                Math.abs(deviceBounds.getHeight()));
+        // shading space -> device space
+        AffineTransform shadingToDevice = (AffineTransform)xform.clone();
+        shadingToDevice.concatenate(matrix.createAffineTransform());
+
+        // convert connects two circles' centers coordinates to device space
+        Point2D p0 = new Point2D.Double(coords[0], coords[1]);
+        Point2D p1 = new Point2D.Double(coords[3], coords[4]);
+        shadingToDevice.transform(p0, p0);
+        shadingToDevice.transform(p1, p1);
+
+        // the distance between them is number of steps
+        factor = (int)Math.round(p0.distance(p1));
 
         // build the color table for the given number of steps
         colorTable = calcColorTable();



Mime
View raw message