aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/svg/PDFGraphics2D.java
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2014-07-10 17:36:43 +0000
committerVincent Hennebert <vhennebert@apache.org>2014-07-10 17:36:43 +0000
commitea7fa816d2fa119cdb8eabe87ff70ee3abf862a6 (patch)
treefa0a1c4c700b81e1f504573d5d03ee8484a76b39 /src/java/org/apache/fop/svg/PDFGraphics2D.java
parentc085138424b647fa00983d3e2539210cb385e634 (diff)
downloadxmlgraphics-fop-ea7fa816d2fa119cdb8eabe87ff70ee3abf862a6.tar.gz
xmlgraphics-fop-ea7fa816d2fa119cdb8eabe87ff70ee3abf862a6.zip
Factorized creation of gradient colors
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609517 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/svg/PDFGraphics2D.java')
-rw-r--r--src/java/org/apache/fop/svg/PDFGraphics2D.java51
1 files changed, 23 insertions, 28 deletions
diff --git a/src/java/org/apache/fop/svg/PDFGraphics2D.java b/src/java/org/apache/fop/svg/PDFGraphics2D.java
index 36f39190e..06dd1f575 100644
--- a/src/java/org/apache/fop/svg/PDFGraphics2D.java
+++ b/src/java/org/apache/fop/svg/PDFGraphics2D.java
@@ -50,6 +50,7 @@ import java.awt.image.renderable.RenderableImage;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringWriter;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -877,20 +878,9 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
theEncode.add(new Double(0));
theEncode.add(new Double(1));
- float[] fractions = gp.getFractions();
- Color[] cols = gp.getColors();
- List<Color> someColors = new java.util.ArrayList<Color>();
- if (fractions[0] > 0f) {
- someColors.add(cols[0]);
- }
- for (int count = 0; count < cols.length; count++) {
- Color cc = cols[count];
- someColors.add(cc);
- }
- if (fractions[fractions.length - 1] < 1f) {
- someColors.add(cols[cols.length - 1]);
- }
+ List<Color> colors = createGradientColors(gp);
+ float[] fractions = gp.getFractions();
List<Double> theBounds = new java.util.ArrayList<Double>();
for (int count = 0; count < fractions.length; count++) {
float offset = fractions[count];
@@ -902,7 +892,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
//Gradients are currently restricted to sRGB
PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
PDFGradientFactory gradientFactory = new PDFGradientFactory(this);
- PDFPattern myPat = gradientFactory.createGradient(false, colSpace, someColors, theBounds,
+ PDFPattern myPat = gradientFactory.createGradient(false, colSpace, colors, theBounds,
theCoords, matrix);
currentStream.write(myPat.getColorSpaceOut(fill));
@@ -949,20 +939,9 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
theCoords.add(new Double(ac.getY()));
theCoords.add(new Double(ar));
- float[] fractions = gp.getFractions();
- Color[] cols = gp.getColors();
- List<Color> someColors = new java.util.ArrayList<Color>();
- if (fractions[0] > 0f) {
- someColors.add(cols[0]);
- }
- for (int count = 0; count < cols.length; count++) {
- Color cc = cols[count];
- someColors.add(cc);
- }
- if (fractions[fractions.length - 1] < 1f) {
- someColors.add(cols[cols.length - 1]);
- }
+ List<Color> colors = createGradientColors(gp);
+ float[] fractions = gp.getFractions();
List<Double> theBounds = new java.util.ArrayList<Double>();
for (int count = 0; count < fractions.length; count++) {
float offset = fractions[count];
@@ -974,7 +953,7 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
//Gradients are currently restricted to sRGB
PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
PDFGradientFactory gradientFactory = new PDFGradientFactory(this);
- PDFPattern myPat = gradientFactory.createGradient(true, colSpace, someColors, theBounds,
+ PDFPattern myPat = gradientFactory.createGradient(true, colSpace, colors, theBounds,
theCoords, matrix);
currentStream.write(myPat.getColorSpaceOut(fill));
@@ -996,6 +975,22 @@ public class PDFGraphics2D extends AbstractGraphics2D implements NativeImageHand
return matrix;
}
+ private List<Color> createGradientColors(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(svgColors[0]);
+ }
+ for (Color c : svgColors) {
+ gradientColors.add(c);
+ }
+ if (fractions[fractions.length - 1] < 1f) {
+ gradientColors.add(svgColors[svgColors.length - 1]);
+ }
+ return gradientColors;
+ }
+
private boolean createPattern(PatternPaint pp, boolean fill) {
preparePainting();