From cc8de67793c578b4e33860db6f11ab18e2aeee20 Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Mon, 14 Jul 2014 21:24:32 +0000 Subject: [PATCH] Delegate function rendering to dedicated class intead of taking as parameter a list of Strings coming from who knows where git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1610535 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFFunction.java | 9 ++++++- .../apache/fop/render/gradient/Function.java | 11 +++++--- .../fop/render/ps/svg/PSSVGGraphics2D.java | 25 ++++++++----------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/fop/pdf/PDFFunction.java b/src/java/org/apache/fop/pdf/PDFFunction.java index 65ec0ea90..be74dfc10 100644 --- a/src/java/org/apache/fop/pdf/PDFFunction.java +++ b/src/java/org/apache/fop/pdf/PDFFunction.java @@ -25,6 +25,7 @@ import java.util.Collections; import java.util.List; import org.apache.fop.render.gradient.Function; +import org.apache.fop.render.gradient.Function.SubFunctionRenderer; /** * class representing a PDF Function. @@ -111,7 +112,13 @@ public class PDFFunction extends PDFObject { for (PDFFunction f : pdfFunctions) { functionsStrings.add(f.referencePDF()); } - return encode(function.toWriteableString(functionsStrings)); + SubFunctionRenderer subFunctionRenderer = new SubFunctionRenderer() { + + public void outputFunction(StringBuilder out, int functionIndex) { + out.append(pdfFunctions.get(functionIndex).referencePDF()); + } + }; + return encode(function.toWriteableString(subFunctionRenderer)); } /** {@inheritDoc} */ diff --git a/src/java/org/apache/fop/render/gradient/Function.java b/src/java/org/apache/fop/render/gradient/Function.java index f37479538..e83f6dc05 100644 --- a/src/java/org/apache/fop/render/gradient/Function.java +++ b/src/java/org/apache/fop/render/gradient/Function.java @@ -24,6 +24,11 @@ import org.apache.fop.pdf.PDFNumber; public class Function { + public interface SubFunctionRenderer { + + void outputFunction(StringBuilder out, int functionIndex); + } + /** * Required: The Type of function (0,2,3,4) default is 0. */ @@ -333,7 +338,7 @@ public class Function { return cOne; } - public String toWriteableString(List functionsStrings) { + public String toWriteableString(SubFunctionRenderer subFunctionRenderer) { StringBuilder out = new StringBuilder(256); out.append("<<\n/FunctionType " + functionType + "\n"); outputDomain(out); @@ -362,8 +367,8 @@ public class Function { outputRange(out); if (!functions.isEmpty()) { out.append("/Functions [ "); - for (String f : functionsStrings) { - out.append(f); + for (int i = 0; i < functions.size(); i++) { + subFunctionRenderer.outputFunction(out, i); out.append(' '); } out.append("]\n"); diff --git a/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java b/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java index 55811f2c9..b8ddc20d8 100644 --- a/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java +++ b/src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java @@ -23,8 +23,6 @@ import java.awt.Graphics; import java.awt.Paint; import java.awt.geom.AffineTransform; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,6 +34,7 @@ import org.apache.xmlgraphics.java2d.ps.PSGraphics2D; import org.apache.xmlgraphics.ps.PSGenerator; import org.apache.fop.render.gradient.Function; +import org.apache.fop.render.gradient.Function.SubFunctionRenderer; import org.apache.fop.render.gradient.GradientMaker; import org.apache.fop.render.gradient.Pattern; import org.apache.fop.render.gradient.Shading; @@ -127,24 +126,20 @@ public class PSSVGGraphics2D extends PSGraphics2D { Shading.FunctionRenderer functionRenderer = new Shading.FunctionRenderer() { public void outputFunction(StringBuilder out) { - List functionsStrings = new ArrayList(function.getFunctions().size()); - for (Function f : function.getFunctions()) { - functionsStrings.add(functionToString(f)); - } - out.append(function.toWriteableString(functionsStrings)); + SubFunctionRenderer subFunctionRenderer = new Function.SubFunctionRenderer() { + + public void outputFunction(StringBuilder out, int functionIndex) { + Function subFunction = function.getFunctions().get(functionIndex); + assert subFunction.getFunctions().isEmpty(); + out.append(subFunction.toWriteableString(null)); + } + }; + out.append(function.toWriteableString(subFunctionRenderer)); } }; shading.output(p, functionRenderer); } - private String functionToString(Function function) { - List functionsStrings = new ArrayList(function.getFunctions().size()); - for (Function f : function.getFunctions()) { - functionsStrings.add(functionToString(f)); - } - return function.toWriteableString(functionsStrings); - } - protected AffineTransform getBaseTransform() { AffineTransform at = new AffineTransform(this.getTransform()); return at; -- 2.39.5