From 5166be88be7e259cff51b0f5d38abc67c51309d3 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Mon, 14 Jul 2014 21:25:13 +0000 Subject: [PATCH] Factorized outputDoubles into GradientMaker Removed conversion to Double when unnecessary git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1610538 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/render/gradient/Function.java | 25 ++++++------------ .../fop/render/gradient/GradientMaker.java | 10 +++++++ .../apache/fop/render/gradient/Shading.java | 26 ++++++------------- 3 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/java/org/apache/fop/render/gradient/Function.java b/src/java/org/apache/fop/render/gradient/Function.java index 220c5f791..ca87d509d 100644 --- a/src/java/org/apache/fop/render/gradient/Function.java +++ b/src/java/org/apache/fop/render/gradient/Function.java @@ -375,14 +375,14 @@ public class Function { outputEncode(out); out.append("/Bounds "); if (bounds != null) { - outputDoubles(out, bounds); + GradientMaker.outputDoubles(out, bounds); } else if (!functions.isEmpty()) { // if there are n functions, // there must be n-1 bounds. // so let each function handle an equal portion // of the whole. e.g. if there are 4, then [ 0.25 0.25 0.25 ] int numberOfFunctions = functions.size(); - String functionsFraction = PDFNumber.doubleOut(Double.valueOf(1.0 / (numberOfFunctions))); + String functionsFraction = PDFNumber.doubleOut(1.0 / numberOfFunctions); out.append("[ "); for (int i = 0; i + 1 < numberOfFunctions; i++) { out.append(functionsFraction); @@ -407,7 +407,7 @@ public class Function { private void outputDomain(StringBuilder p) { if (domain != null) { p.append("/Domain "); - outputDoubles(p, domain); + GradientMaker.outputDoubles(p, domain); p.append("\n"); } else { p.append("/Domain [ 0 1 ]\n"); @@ -417,7 +417,7 @@ public class Function { private void outputSize(StringBuilder out) { if (size != null) { out.append("/Size "); - outputDoubles(out, size); + GradientMaker.outputDoubles(out, size); out.append("\n"); } } @@ -435,7 +435,7 @@ public class Function { private void outputRange(StringBuilder out) { if (range != null) { out.append("/Range "); - outputDoubles(out, range); + GradientMaker.outputDoubles(out, range); out.append("\n"); } } @@ -443,7 +443,7 @@ public class Function { private void outputEncode(StringBuilder out) { if (encode != null) { out.append("/Encode "); - outputDoubles(out, encode); + GradientMaker.outputDoubles(out, encode); out.append("\n"); } else { out.append("/Encode [ "); @@ -458,7 +458,7 @@ public class Function { private void outputDecode(StringBuilder out) { if (decode != null) { out.append("/Decode "); - outputDoubles(out, decode); + GradientMaker.outputDoubles(out, decode); out.append("\n"); } } @@ -503,17 +503,8 @@ public class Function { private void outputInterpolationExponentN(StringBuilder out) { out.append("/N "); - out.append(PDFNumber.doubleOut(Double.valueOf(interpolationExponentN))); + out.append(PDFNumber.doubleOut(interpolationExponentN)); out.append("\n"); } - private void outputDoubles(StringBuilder out, List doubles) { - out.append("[ "); - for (Double d : doubles) { - out.append(PDFNumber.doubleOut(d)); - out.append(" "); - } - out.append("]"); - } - } diff --git a/src/java/org/apache/fop/render/gradient/GradientMaker.java b/src/java/org/apache/fop/render/gradient/GradientMaker.java index 02db2c5fe..1f378e465 100644 --- a/src/java/org/apache/fop/render/gradient/GradientMaker.java +++ b/src/java/org/apache/fop/render/gradient/GradientMaker.java @@ -32,6 +32,7 @@ import org.apache.batik.ext.awt.RadialGradientPaint; import org.apache.xmlgraphics.java2d.color.ColorUtil; import org.apache.fop.pdf.PDFDeviceColorSpace; +import org.apache.fop.pdf.PDFNumber; public final class GradientMaker { @@ -151,4 +152,13 @@ public final class GradientMaker { return gradientColors; } + static void outputDoubles(StringBuilder out, List doubles) { + out.append("[ "); + for (Double d : doubles) { + out.append(PDFNumber.doubleOut(d)); + out.append(" "); + } + out.append("]"); + } + } diff --git a/src/java/org/apache/fop/render/gradient/Shading.java b/src/java/org/apache/fop/render/gradient/Shading.java index 61f933cdd..593a22dd2 100644 --- a/src/java/org/apache/fop/render/gradient/Shading.java +++ b/src/java/org/apache/fop/render/gradient/Shading.java @@ -20,7 +20,6 @@ package org.apache.fop.render.gradient; import java.util.List; import org.apache.fop.pdf.PDFDeviceColorSpace; -import org.apache.fop.pdf.PDFNumber; public class Shading { @@ -220,13 +219,13 @@ public class Shading { if (background != null) { out.append("/Background "); - outputDoubles(out, background); + GradientMaker.outputDoubles(out, background); out.append("\n"); } if (bbox != null) { out.append("/BBox"); - outputDoubles(out, bbox); + GradientMaker.outputDoubles(out, bbox); out.append("\n"); } @@ -255,19 +254,10 @@ public class Shading { out.append(">>"); } - private void outputDoubles(StringBuilder out, List doubles) { - out.append("[ "); - for (Double d : doubles) { - out.append(PDFNumber.doubleOut(d)); - out.append(" "); - } - out.append("]"); - } - private void outputShadingType1(StringBuilder out, Shading.FunctionRenderer functionRenderer) { if (domain != null) { out.append("/Domain "); - outputDoubles(out, domain); + GradientMaker.outputDoubles(out, domain); out.append("\n"); } else { out.append("/Domain [ 0 1 ] \n"); @@ -275,7 +265,7 @@ public class Shading { if (matrix != null) { out.append("/Matrix "); - outputDoubles(out, matrix); + GradientMaker.outputDoubles(out, matrix); out.append("\n"); } outputFunction(out, functionRenderer); @@ -284,13 +274,13 @@ public class Shading { private void outputShadingType2or3(StringBuilder out, Shading.FunctionRenderer functionRenderer) { if (coords != null) { out.append("/Coords "); - outputDoubles(out, coords); + GradientMaker.outputDoubles(out, coords); out.append("\n"); } if (domain != null) { out.append("/Domain "); - outputDoubles(out, domain); + GradientMaker.outputDoubles(out, domain); out.append("\n"); } else { out.append("/Domain [ 0 1 ] \n"); @@ -331,7 +321,7 @@ public class Shading { if (decode != null) { out.append("/Decode "); - outputDoubles(out, decode); + GradientMaker.outputDoubles(out, decode); out.append("\n"); } @@ -353,7 +343,7 @@ public class Shading { if (decode != null) { out.append("/Decode "); - outputDoubles(out, decode); + GradientMaker.outputDoubles(out, decode); out.append("\n"); } -- 2.39.5