aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org
diff options
context:
space:
mode:
authorVincent Hennebert <vhennebert@apache.org>2014-07-11 17:07:29 +0000
committerVincent Hennebert <vhennebert@apache.org>2014-07-11 17:07:29 +0000
commit1ead2b6ba0e8eda9eb06da4fab5ed9bf1cd8611e (patch)
tree76f0b9c881a0f16eed5820aee7bb481142ee9b55 /src/java/org
parentd2b8aba1131ab23985a4f390779bd5e8f76e7b53 (diff)
downloadxmlgraphics-fop-1ead2b6ba0e8eda9eb06da4fab5ed9bf1cd8611e.tar.gz
xmlgraphics-fop-1ead2b6ba0e8eda9eb06da4fab5ed9bf1cd8611e.zip
Removed makeFunction methods, whose implementations are the same for both PDF and PS
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP-2393_gradient-rendering@1609746 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org')
-rw-r--r--src/java/org/apache/fop/render/ps/svg/PSFunction.java84
-rw-r--r--src/java/org/apache/fop/render/ps/svg/PSShading.java23
-rw-r--r--src/java/org/apache/fop/render/shading/GradientFactory.java12
-rw-r--r--src/java/org/apache/fop/render/shading/PDFGradientFactory.java15
-rw-r--r--src/java/org/apache/fop/render/shading/PSGradientFactory.java18
5 files changed, 16 insertions, 136 deletions
diff --git a/src/java/org/apache/fop/render/ps/svg/PSFunction.java b/src/java/org/apache/fop/render/ps/svg/PSFunction.java
deleted file mode 100644
index 4ae7b6058..000000000
--- a/src/java/org/apache/fop/render/ps/svg/PSFunction.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.ps.svg;
-
-import java.io.UnsupportedEncodingException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.fop.render.shading.Function;
-import org.apache.fop.render.shading.FunctionPattern;
-
-public class PSFunction extends Function {
-
- /**
- * Creates a Postscript function dictionary
- * @param theFunctionType The function type (0 = Sampled, 2 = Exponential
- * Interpolation, 3 = Stitching)
- * @param theDomain The function domain
- * @param theRange Range used for clipping
- * @param theFunctions An array of sub-functions such as determining the
- * colour values used in a gradient.
- * @param theBounds Bounds determines where each boundary exists for whatever
- * the function is mean't. In a gradient case, it would be the point between
- * colours.
- * @param theEncode The function encoding
- */
- public PSFunction(int theFunctionType, List<Double> theDomain,
- List<Double> theRange, List<Function> theFunctions,
- List<Double> theBounds, List<Double> theEncode) {
- super(theFunctionType, theDomain, theRange, theFunctions, theBounds, theEncode);
- }
-
- /**
- * Creates a Postscript function dictionary
- * @param theFunctionType The function type (0 = Sampled, 2 = Exponential
- * Interpolation, 3 = Stitching)
- * @param theDomain The function domain
- * @param theRange Range used for clipping
- * @param theCZero In a gradient, this would be the first colour
- * @param theCOne In a gradient, this would be the second colour
- * @param theInterpolationExponentN Determines the number of values
- * the function returns.
- */
- public PSFunction(int theFunctionType, List<Double> theDomain,
- List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
- double theInterpolationExponentN) {
- super(theFunctionType, theDomain, theRange, theCZero, theCOne, theInterpolationExponentN);
- }
-
- /**
- * Outputs the function to a byte array
- */
- public byte[] toByteString() {
- FunctionPattern pattern = new FunctionPattern(this);
- try {
- List<String> functionsStrings = new ArrayList<String>(getFunctions().size());
- for (Function f : getFunctions()) {
- functionsStrings.add(new String(((PSFunction) f).toByteString(), "UTF-8"));
- }
- return pattern.toWriteableString(functionsStrings).getBytes("UTF-8");
- } catch (UnsupportedEncodingException ex) {
- //This should have been made an enum type to avoid throwing exceptions.
- return new byte[0];
- }
- }
-
-}
diff --git a/src/java/org/apache/fop/render/ps/svg/PSShading.java b/src/java/org/apache/fop/render/ps/svg/PSShading.java
index 7465fcadb..68be4fcd8 100644
--- a/src/java/org/apache/fop/render/ps/svg/PSShading.java
+++ b/src/java/org/apache/fop/render/ps/svg/PSShading.java
@@ -19,12 +19,13 @@
package org.apache.fop.render.ps.svg;
-import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
import java.util.List;
import org.apache.fop.pdf.PDFDeviceColorSpace;
import org.apache.fop.pdf.PDFNumber;
import org.apache.fop.render.shading.Function;
+import org.apache.fop.render.shading.FunctionPattern;
import org.apache.fop.render.shading.Shading;
import org.apache.fop.render.shading.ShadingPattern;
@@ -72,7 +73,7 @@ public class PSShading implements Shading {
* The object of the color mapping function (usually type 2 or 3).
* Optional for Type 4,5,6, and 7: When it's nearly the same thing.
*/
- protected PSFunction function = null;
+ protected Function function;
/**
* Required for Type 2: An Array of four numbers specifying
@@ -125,8 +126,7 @@ public class PSShading implements Shading {
this.coords = theCoords;
this.domain = theDomain;
- assert theFunction instanceof PSFunction;
- this.function = (PSFunction)theFunction;
+ this.function = theFunction;
this.extend = theExtend;
}
@@ -187,15 +187,20 @@ public class PSShading implements Shading {
if (this.function != null) {
p.append("\t/Function ");
- try {
- p.append(new String(this.function.toByteString(), "UTF-8") + " \n");
- } catch (UnsupportedEncodingException ex) {
- //This should have been made an enum type to avoid throwing exceptions.
- }
+ p.append(functionToString(function) + " \n");
}
return p;
}
+ private String functionToString(Function function) {
+ FunctionPattern pattern = new FunctionPattern(function);
+ List<String> functionsStrings = new ArrayList<String>(function.getFunctions().size());
+ for (Function f : function.getFunctions()) {
+ functionsStrings.add(functionToString(f));
+ }
+ return pattern.toWriteableString(functionsStrings);
+ }
+
/**
* A method to write a type 1 shading object
* @param p The StringBuffer to write the shading object
diff --git a/src/java/org/apache/fop/render/shading/GradientFactory.java b/src/java/org/apache/fop/render/shading/GradientFactory.java
index 81467d88d..f17a0e74c 100644
--- a/src/java/org/apache/fop/render/shading/GradientFactory.java
+++ b/src/java/org/apache/fop/render/shading/GradientFactory.java
@@ -79,7 +79,7 @@ public abstract class GradientFactory<P extends Pattern> {
List<Function> functions = createFunctions(gradient);
//Gradients are currently restricted to sRGB
PDFDeviceColorSpace colSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
- Function function = makeFunction(3, null, null, functions, bounds, null);
+ Function function = new Function(3, null, null, functions, bounds, null);
Shading shading = makeShading(gradient instanceof LinearGradientPaint ? 2 : 3,
colSpace, null, null, false, coords, null, function, null);
return makePattern(2, shading, null, null, matrix);
@@ -127,7 +127,7 @@ public abstract class GradientFactory<P extends Pattern> {
Color nextColor = colors.get(currentPosition + 1);
List<Double> c0 = toColorVector(currentColor);
List<Double> c1 = toColorVector(nextColor);
- Function function = makeFunction(2, null, null, c0, c1, 1.0);
+ Function function = new Function(2, null, null, c0, c1, 1.0);
functions.add(function);
}
return functions;
@@ -149,14 +149,6 @@ public abstract class GradientFactory<P extends Pattern> {
return gradientColors;
}
- public abstract Function makeFunction(int functionType, List<Double> theDomain,
- List<Double> theRange, List<Function> theFunctions,
- List<Double> theBounds, List<Double> theEncode);
-
- public abstract Function makeFunction(int functionType, List<Double> theDomain,
- List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
- double theInterpolationExponentN);
-
public abstract Shading makeShading(int theShadingType,
PDFDeviceColorSpace theColorSpace, List<Double> theBackground, List<Double> theBBox,
boolean theAntiAlias, List<Double> theCoords, List<Double> theDomain,
diff --git a/src/java/org/apache/fop/render/shading/PDFGradientFactory.java b/src/java/org/apache/fop/render/shading/PDFGradientFactory.java
index 1e57e72ea..86c4e7e79 100644
--- a/src/java/org/apache/fop/render/shading/PDFGradientFactory.java
+++ b/src/java/org/apache/fop/render/shading/PDFGradientFactory.java
@@ -35,21 +35,6 @@ public class PDFGradientFactory extends GradientFactory<PDFPattern> {
}
@Override
- public Function makeFunction(int functionType, List<Double> theDomain,
- List<Double> theRange, List<Function> theFunctions,
- List<Double> theBounds, List<Double> theEncode) {
- return new Function(functionType, theDomain, theRange, theFunctions, theBounds, theEncode);
- }
-
- public Function makeFunction(int functionType, List<Double> theDomain,
- List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
- double theInterpolationExponentN) {
- Function newFunction = new Function(functionType, theDomain, theRange, theCZero,
- theCOne, theInterpolationExponentN);
- return newFunction;
- }
-
- @Override
public Shading makeShading(int theShadingType,
PDFDeviceColorSpace theColorSpace, List<Double> theBackground, List<Double> theBBox,
boolean theAntiAlias, List<Double> theCoords, List<Double> theDomain,
diff --git a/src/java/org/apache/fop/render/shading/PSGradientFactory.java b/src/java/org/apache/fop/render/shading/PSGradientFactory.java
index afd23ad75..03011fa35 100644
--- a/src/java/org/apache/fop/render/shading/PSGradientFactory.java
+++ b/src/java/org/apache/fop/render/shading/PSGradientFactory.java
@@ -20,29 +20,11 @@ package org.apache.fop.render.shading;
import java.util.List;
import org.apache.fop.pdf.PDFDeviceColorSpace;
-import org.apache.fop.render.ps.svg.PSFunction;
import org.apache.fop.render.ps.svg.PSPattern;
import org.apache.fop.render.ps.svg.PSShading;
public class PSGradientFactory extends GradientFactory<PSPattern> {
- public Function makeFunction(int functionType, List<Double> theDomain,
- List<Double> theRange, List<Function> theFunctions,
- List<Double> theBounds, List<Double> theEncode) {
- Function newFunction = new PSFunction(functionType, theDomain, theRange, theFunctions,
- theBounds, theEncode);
- return newFunction;
- }
-
- @Override
- public Function makeFunction(int functionType, List<Double> theDomain,
- List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
- double theInterpolationExponentN) {
- Function newFunction = new PSFunction(functionType, theDomain, theRange, theCZero,
- theCOne, theInterpolationExponentN);
- return newFunction;
- }
-
@Override
public Shading makeShading(int theShadingType,
PDFDeviceColorSpace theColorSpace, List<Double> theBackground, List<Double> theBBox,