]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Delegate function rendering to dedicated class intead of taking as parameter a list...
authorVincent Hennebert <vhennebert@apache.org>
Mon, 14 Jul 2014 21:24:32 +0000 (21:24 +0000)
committerVincent Hennebert <vhennebert@apache.org>
Mon, 14 Jul 2014 21:24:32 +0000 (21:24 +0000)
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
src/java/org/apache/fop/render/gradient/Function.java
src/java/org/apache/fop/render/ps/svg/PSSVGGraphics2D.java

index 65ec0ea90b403adaeeda53860474dd4ec13fefa5..be74dfc10f4ef1cbf7e20ffe5b27f608b1ea2620 100644 (file)
@@ -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} */
index f37479538950ea23698db9653799e21b96713e9a..e83f6dc0535179d5fad033655e182fce81b222b4 100644 (file)
@@ -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<String> 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");
index 55811f2c954ada49c3e1ff3759c2faaa9cb48315..b8ddc20d80de7d5140f9d9d34a992c16f4e0fbfb 100644 (file)
@@ -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<String> functionsStrings = new ArrayList<String>(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<String> functionsStrings = new ArrayList<String>(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;