xmlgraphics-fop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vhenneb...@apache.org
Subject svn commit: r1609523 - /xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
Date Thu, 10 Jul 2014 17:46:23 GMT
Author: vhennebert
Date: Thu Jul 10 17:46:23 2014
New Revision: 1609523

URL: http://svn.apache.org/r1609523
Log:
Factorized creation of gradient colors

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

Modified: xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java?rev=1609523&r1=1609522&r2=1609523&view=diff
==============================================================================
--- xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
(original)
+++ xmlgraphics/fop/branches/FOP-2393_gradient-rendering/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java
Thu Jul 10 17:46:23 2014
@@ -110,21 +110,9 @@ public class PSSVGGraphics2D extends PSG
         theCoords.add(gp.getEndPoint().getX());
         theCoords.add(gp.getEndPoint().getY());
 
+        List<Color> colors = createGradientColors(gp);
 
-        Color[] cols = gp.getColors();
-        List<Color> someColors = new java.util.ArrayList<Color>();
         float[] fractions = gp.getFractions();
-        if (fractions[0] > 0f) {
-            someColors.add(cols[0]);
-        }
-        for (int count = 0; count < cols.length; count++) {
-            Color c = cols[count];
-            someColors.add(c);
-        }
-        if (fractions[fractions.length - 1] < 1f) {
-            someColors.add(cols[cols.length - 1]);
-        }
-
         List<Double> theBounds = new java.util.ArrayList<Double>();
         for (int count = 0; count < fractions.length; count++) {
             float offset = fractions[count];
@@ -137,7 +125,7 @@ public class PSSVGGraphics2D extends PSG
 
         PSGradientFactory gradientFactory = new PSGradientFactory();
         PSPattern myPattern = gradientFactory.createGradient(false, colSpace,
-                someColors, theBounds, theCoords, matrix);
+                colors, theBounds, theCoords, matrix);
 
         gen.write(myPattern.toString());
 
@@ -173,20 +161,9 @@ public class PSSVGGraphics2D extends PSG
         theCoords.add(new Double(ac.getY()));
         theCoords.add(new Double(ar));
 
-        Color[] cols = gp.getColors();
-        List<Color> someColors = new java.util.ArrayList<Color>();
-        float[] fractions = gp.getFractions();
-        if (fractions[0] > 0f) {
-            someColors.add(cols[0]);
-        }
-        for (int count = 0; count < cols.length; count++) {
-            Color c = cols[count];
-            someColors.add(c);
-        }
-        if (fractions[fractions.length - 1] < 1f) {
-            someColors.add(cols[cols.length - 1]);
-        }
+        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];
@@ -199,7 +176,7 @@ public class PSSVGGraphics2D extends PSG
 
         PSGradientFactory gradientFactory = new PSGradientFactory();
         PSPattern myPattern = gradientFactory.createGradient(true, colSpace,
-                someColors, theBounds, theCoords, matrix);
+                colors, theBounds, theCoords, matrix);
 
         gen.write(myPattern.toString());
     }
@@ -217,6 +194,22 @@ public class PSSVGGraphics2D extends PSG
         return matrix;
     }
 
+    private List<Color> createGradientColors(MultipleGradientPaint gradient) {
+        Color[] svgColors = gradient.getColors();
+        List<Color> gradientColors = new ArrayList<Color>(svgColors.length +
2);
+        float[] fractions = gradient.getFractions();
+        if (fractions[0] > 0f) {
+            gradientColors.add(svgColors[0]);
+        }
+        for (Color c : svgColors) {
+            gradientColors.add(c);
+        }
+        if (fractions[fractions.length - 1] < 1f) {
+            gradientColors.add(svgColors[svgColors.length - 1]);
+        }
+        return gradientColors;
+    }
+
     private AffineTransform applyTransform(AffineTransform base, double posX, double posY)
{
         AffineTransform result = AffineTransform.getTranslateInstance(posX, posY);
         AffineTransform orig = base;



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org


Mime
View raw message