From 2be89ddec6f3381d98cb3a9f9732245573b0ea88 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Thu, 10 Jul 2014 18:21:59 +0000 Subject: [PATCH] Moved creation of colors into createFunctions git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609547 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/render/shading/GradientFactory.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/fop/render/shading/GradientFactory.java b/src/java/org/apache/fop/render/shading/GradientFactory.java index ba76f3071..81467d88d 100644 --- a/src/java/org/apache/fop/render/shading/GradientFactory.java +++ b/src/java/org/apache/fop/render/shading/GradientFactory.java @@ -75,11 +75,10 @@ public abstract class GradientFactory

{ private P createGradient(MultipleGradientPaint gradient, List coords, AffineTransform baseTransform, AffineTransform transform) { List matrix = createTransform(gradient, baseTransform, transform); - List colors = createColors(gradient); List bounds = createBounds(gradient); + List functions = createFunctions(gradient); //Gradients are currently restricted to sRGB PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB); - List functions = createFunctions(colors); Function function = makeFunction(3, null, null, functions, bounds, null); Shading shading = makeShading(gradient instanceof LinearGradientPaint ? 2 : 3, colSpace, null, null, false, coords, null, function, null); @@ -100,22 +99,6 @@ public abstract class GradientFactory

{ return matrix; } - private List createColors(MultipleGradientPaint gradient) { - Color[] svgColors = gradient.getColors(); - List gradientColors = new ArrayList(svgColors.length + 2); - float[] fractions = gradient.getFractions(); - if (fractions[0] > 0f) { - gradientColors.add(getsRGBColor(svgColors[0])); - } - for (Color c : svgColors) { - gradientColors.add(getsRGBColor(c)); - } - if (fractions[fractions.length - 1] < 1f) { - gradientColors.add(getsRGBColor(svgColors[svgColors.length - 1])); - } - return gradientColors; - } - private Color getsRGBColor(Color c) { // Color space must be consistent, so convert to sRGB if necessary // TODO really? @@ -134,7 +117,8 @@ public abstract class GradientFactory

{ return bounds; } - private List createFunctions(List colors) { + private List createFunctions(MultipleGradientPaint gradient) { + List colors = createColors(gradient); List functions = new ArrayList(); for (int currentPosition = 0, lastPosition = colors.size() - 1; currentPosition < lastPosition; @@ -149,6 +133,22 @@ public abstract class GradientFactory

{ return functions; } + private List createColors(MultipleGradientPaint gradient) { + Color[] svgColors = gradient.getColors(); + List gradientColors = new ArrayList(svgColors.length + 2); + float[] fractions = gradient.getFractions(); + if (fractions[0] > 0f) { + gradientColors.add(getsRGBColor(svgColors[0])); + } + for (Color c : svgColors) { + gradientColors.add(getsRGBColor(c)); + } + if (fractions[fractions.length - 1] < 1f) { + gradientColors.add(getsRGBColor(svgColors[svgColors.length - 1])); + } + return gradientColors; + } + public abstract Function makeFunction(int functionType, List theDomain, List theRange, List theFunctions, List theBounds, List theEncode); -- 2.39.5