]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Factorized creation of gradient bounds
authorVincent Hennebert <vhennebert@apache.org>
Thu, 10 Jul 2014 17:48:11 +0000 (17:48 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Thu, 10 Jul 2014 17:48:11 +0000 (17:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609524 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java

index 43212aebd55bbaad77532c6f168050f0421c390a..b3799262ef1153f2107184ca8a84a6b11e00e3dc 100644 (file)
@@ -112,20 +112,13 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar {
 
         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);
         PDFDeviceColorSpace colSpace;
         colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
 
         PSGradientFactory gradientFactory = new PSGradientFactory();
         PSPattern myPattern = gradientFactory.createGradient(false, colSpace,
-                colors, theBounds, theCoords, matrix);
+                colors, bounds, theCoords, matrix);
 
         gen.write(myPattern.toString());
 
@@ -163,20 +156,13 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar {
 
         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);
         PDFDeviceColorSpace colSpace;
         colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
 
         PSGradientFactory gradientFactory = new PSGradientFactory();
         PSPattern myPattern = gradientFactory.createGradient(true, colSpace,
-                colors, theBounds, theCoords, matrix);
+                colors, bounds, theCoords, matrix);
 
         gen.write(myPattern.toString());
     }
@@ -210,6 +196,18 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar {
         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 AffineTransform applyTransform(AffineTransform base, double posX, double posY) {
         AffineTransform result = AffineTransform.getTranslateInstance(posX, posY);
         AffineTransform orig = base;