From e848ca20e352c28cab6c7426cd8079e215d82d34 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Thu, 10 Jul 2014 17:48:11 +0000 Subject: [PATCH] Factorized creation of gradient bounds git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609524 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/ps/svg/PSSVGGraphics2D.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) 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 43212aebd..b3799262e 100644 --- a/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java @@ -112,20 +112,13 @@ public class PSSVGGraphics2D extends PSGraphics2D implements GradientRegistrar { 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]; - if (0f < offset && offset < 1f) { - theBounds.add(new Double(offset)); - } - } + List 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 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]; - if (0f < offset && offset < 1f) { - theBounds.add(new Double(offset)); - } - } + List 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 createGradientBounds(MultipleGradientPaint gradient) { + // TODO is the conversion to double necessary? + float[] fractions = gradient.getFractions(); + List bounds = new java.util.ArrayList(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; -- 2.39.5