From: Vincent Hennebert Date: Thu, 10 Jul 2014 17:46:23 +0000 (+0000) Subject: Factorized creation of gradient colors X-Git-Tag: fop-2_0~97^2~37 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a201927a5e8f1600da9c307a642699515ecfdb02;p=xmlgraphics-fop.git Factorized creation of gradient colors git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609523 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java b/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java index c4035a3f4..43212aebd 100644 --- a/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java @@ -110,21 +110,9 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar { theCoords.add(gp.getEndPoint().getX()); theCoords.add(gp.getEndPoint().getY()); + List colors = createGradientColors(gp); - Color[] cols = gp.getColors(); - List someColors = new java.util.ArrayList(); 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 theBounds = new java.util.ArrayList(); for (int count = 0; count < fractions.length; count++) { float offset = fractions[count]; @@ -137,7 +125,7 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar { 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 PSGraphics2D implements GradientRegistrar { theCoords.add(new Double(ac.getY())); theCoords.add(new Double(ar)); - Color[] cols = gp.getColors(); - List someColors = new java.util.ArrayList(); - 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 colors = createGradientColors(gp); + float[] fractions = gp.getFractions(); List theBounds = new java.util.ArrayList(); for (int count = 0; count < fractions.length; count++) { float offset = fractions[count]; @@ -199,7 +176,7 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar { 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 PSGraphics2D implements GradientRegistrar { return matrix; } + private List createGradientColors(MultipleGradientPaint gradient) { + Color[] svgColors = gradient.getColors(); + List gradientColors = new ArrayList(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;