From: Vincent Hennebert Date: Thu, 10 Jul 2014 18:10:19 +0000 (+0000) Subject: Extracted function creation into separate method and simplified it X-Git-Tag: fop-2_0~97^2~27 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3a36357fca704d9182047c84bbee79a2ec091b2e;p=xmlgraphics-fop.git Extracted function creation into separate method and simplified it git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609538 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/render/shading/GradientFactory.java b/src/java/org/apache/fop/render/shading/GradientFactory.java index 42024058b..2c74eceed 100644 --- a/src/java/org/apache/fop/render/shading/GradientFactory.java +++ b/src/java/org/apache/fop/render/shading/GradientFactory.java @@ -101,17 +101,23 @@ public abstract class GradientFactory

{ List gradientColors = new ArrayList(svgColors.length + 2); float[] fractions = gradient.getFractions(); if (fractions[0] > 0f) { - gradientColors.add(svgColors[0]); + gradientColors.add(getsRGBColor(svgColors[0])); } for (Color c : svgColors) { - gradientColors.add(c); + gradientColors.add(getsRGBColor(c)); } if (fractions[fractions.length - 1] < 1f) { - gradientColors.add(svgColors[svgColors.length - 1]); + 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? + return c.getColorSpace().isCS_sRGB() ? c : ColorUtil.toSRGBColor(c); + } + private List createBounds(MultipleGradientPaint gradient) { // TODO is the conversion to double necessary? float[] fractions = gradient.getFractions(); @@ -137,35 +143,25 @@ public abstract class GradientFactory

{ */ protected P makeGradient(boolean radial, PDFDeviceColorSpace colorspace, List colors, List bounds, List coords, List matrix) { + List functions = createFunctions(colors); + Function function = makeFunction(3, null, null, functions, bounds, null); + Shading shading = makeShading(radial ? 3 : 2, colorspace, null, null, false, coords, null, function, null); + return makePattern(2, shading, null, null, matrix); + } + + private List createFunctions(List colors) { List functions = new ArrayList(); - // if 5 elements, the penultimate element is 3. - // do not go beyond that, because you always need - // to have a next color when creating the function. - for (int currentPosition = 0, lastPosition = colors.size() - 1; currentPosition < lastPosition; - currentPosition++) { // for every consecutive color pair + for (int currentPosition = 0, lastPosition = colors.size() - 1; + currentPosition < lastPosition; + currentPosition++) { Color currentColor = colors.get(currentPosition); Color nextColor = colors.get(currentPosition + 1); - - // colorspace must be consistent, so we simply convert to sRGB where necessary - if (!currentColor.getColorSpace().isCS_sRGB()) { - //Convert to sRGB - currentColor = ColorUtil.toSRGBColor(currentColor); - colors.set(currentPosition, currentColor); - } - if (!nextColor.getColorSpace().isCS_sRGB()) { - //Convert to sRGB - nextColor = ColorUtil.toSRGBColor(nextColor); - colors.set(currentPosition + 1, nextColor); - } List c0 = toColorVector(currentColor); List c1 = toColorVector(nextColor); Function function = makeFunction(2, null, null, c0, c1, 1.0); functions.add(function); } - - Function function = makeFunction(3, null, null, functions, bounds, null); - Shading shading = makeShading(radial ? 3 : 2, colorspace, null, null, false, coords, null, function, null); - return makePattern(2, shading, null, null, matrix); + return functions; } public abstract Function makeFunction(int functionType, List theDomain,