瀏覽代碼

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
tags/fop-2_0
Vincent Hennebert 9 年之前
父節點
當前提交
cc8de67793

+ 8
- 1
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} */

+ 8
- 3
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<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");

+ 10
- 15
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<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;

Loading…
取消
儲存