Browse Source

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
tags/fop-2_0
Vincent Hennebert 10 years ago
parent
commit
2be89ddec6
1 changed files with 19 additions and 19 deletions
  1. 19
    19
      src/java/org/apache/fop/render/shading/GradientFactory.java

+ 19
- 19
src/java/org/apache/fop/render/shading/GradientFactory.java View File

@@ -75,11 +75,10 @@ public abstract class GradientFactory<P extends Pattern> {
private P createGradient(MultipleGradientPaint gradient, List<Double> coords,
AffineTransform baseTransform, AffineTransform transform) {
List<Double> matrix = createTransform(gradient, baseTransform, transform);
List<Color> colors = createColors(gradient);
List<Double> bounds = createBounds(gradient);
List<Function> functions = createFunctions(gradient);
//Gradients are currently restricted to sRGB
PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
List<Function> 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<P extends Pattern> {
return matrix;
}

private List<Color> createColors(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(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<P extends Pattern> {
return bounds;
}

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

private List<Color> createColors(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(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<Double> theDomain,
List<Double> theRange, List<Function> theFunctions,
List<Double> theBounds, List<Double> theEncode);

Loading…
Cancel
Save