From: Vincent Hennebert Date: Thu, 10 Jul 2014 17:36:43 +0000 (+0000) Subject: Factorized creation of gradient colors X-Git-Tag: fop-2_0~97^2~42 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ea7fa816d2fa119cdb8eabe87ff70ee3abf862a6;p=xmlgraphics-fop.git 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 --- 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 someColors = new java.util.ArrayList(); - 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 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]; @@ -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 someColors = new java.util.ArrayList(); - 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 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]; @@ -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 createGradientColors(MultipleGradientPaint gradient) { + Color[] svgColors = gradient.getColors(); + List gradientColors = new ArrayList(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();