Author: vhennebert
Date: Thu Jul 10 17:37:30 2014
New Revision: 1609518

URL: http://svn.apache.org/r1609518
Log:
Factorized creation of gradient bounds

Modified:
    
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java

Modified: 
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java?rev=1609518&r1=1609517&r2=1609518&view=diff
==============================================================================
--- 
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
 (original)
+++ 
xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/svg/PDFGraphics2D.java
 Thu Jul 10 17:37:30 2014
@@ -880,19 +880,12 @@ public class PDFGraphics2D extends Abstr
 
         List<Color> colors = createGradientColors(gp);
 
-        float[] fractions = gp.getFractions();
-        List<Double> theBounds = new java.util.ArrayList<Double>();
-        for (int count = 0; count < fractions.length; count++) {
-            float offset = fractions[count];
-            if (0f < offset && offset < 1f) {
-                theBounds.add(new Double(offset));
-            }
-        }
+        List<Double> bounds = createGradientBounds(gp);
 
         //Gradients are currently restricted to sRGB
         PDFDeviceColorSpace colSpace = new 
PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
         PDFGradientFactory gradientFactory = new PDFGradientFactory(this);
-        PDFPattern myPat = gradientFactory.createGradient(false, colSpace, 
colors, theBounds,
+        PDFPattern myPat = gradientFactory.createGradient(false, colSpace, 
colors, bounds,
                 theCoords, matrix);
         currentStream.write(myPat.getColorSpaceOut(fill));
 
@@ -941,19 +934,12 @@ public class PDFGraphics2D extends Abstr
 
         List<Color> colors = createGradientColors(gp);
 
-        float[] fractions = gp.getFractions();
-        List<Double> theBounds = new java.util.ArrayList<Double>();
-        for (int count = 0; count < fractions.length; count++) {
-            float offset = fractions[count];
-            if (0f < offset && offset < 1f) {
-                theBounds.add(new Double(offset));
-            }
-        }
+        List<Double> bounds = createGradientBounds(gp);
 
         //Gradients are currently restricted to sRGB
         PDFDeviceColorSpace colSpace = new 
PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
         PDFGradientFactory gradientFactory = new PDFGradientFactory(this);
-        PDFPattern myPat = gradientFactory.createGradient(true, colSpace, 
colors, theBounds,
+        PDFPattern myPat = gradientFactory.createGradient(true, colSpace, 
colors, bounds,
                 theCoords, matrix);
         currentStream.write(myPat.getColorSpaceOut(fill));
 
@@ -991,6 +977,18 @@ public class PDFGraphics2D extends Abstr
         return gradientColors;
     }
 
+    private List<Double> createGradientBounds(MultipleGradientPaint gradient) {
+        // TODO is the conversion to double necessary?
+        float[] fractions = gradient.getFractions();
+        List<Double> bounds = new 
java.util.ArrayList<Double>(fractions.length);
+        for (float offset : fractions) {
+            if (0f < offset && offset < 1f) {
+                bounds.add(Double.valueOf(offset));
+            }
+        }
+        return bounds;
+    }
+
     private boolean createPattern(PatternPaint pp, boolean fill) {
         preparePainting();
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to