From 1ead2b6ba0e8eda9eb06da4fab5ed9bf1cd8611e Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Fri, 11 Jul 2014 17:07:29 +0000 Subject: [PATCH] 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 --- .../apache/fop/render/ps/svg/PSFunction.java | 84 ------------------- .../apache/fop/render/ps/svg/PSShading.java | 23 +++-- .../fop/render/shading/GradientFactory.java | 12 +-- .../render/shading/PDFGradientFactory.java | 15 ---- .../fop/render/shading/PSGradientFactory.java | 18 ---- 5 files changed, 16 insertions(+), 136 deletions(-) delete mode 100644 src/java/org/apache/fop/render/ps/svg/PSFunction.java 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 theDomain, - List theRange, List theFunctions, - List theBounds, List 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 theDomain, - List theRange, List theCZero, List 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 functionsStrings = new ArrayList(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 functionsStrings = new ArrayList(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

{ List 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

{ Color nextColor = colors.get(currentPosition + 1); List c0 = toColorVector(currentColor); List 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

{ return gradientColors; } - public abstract Function makeFunction(int functionType, List theDomain, - List theRange, List theFunctions, - List theBounds, List theEncode); - - public abstract Function makeFunction(int functionType, List theDomain, - List theRange, List theCZero, List theCOne, - double theInterpolationExponentN); - public abstract Shading makeShading(int theShadingType, PDFDeviceColorSpace theColorSpace, List theBackground, List theBBox, boolean theAntiAlias, List theCoords, List 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 @@ -34,21 +34,6 @@ public class PDFGradientFactory extends GradientFactory { this.graphics2D = pdfGraphics2D; } - @Override - public Function makeFunction(int functionType, List theDomain, - List theRange, List theFunctions, - List theBounds, List theEncode) { - return new Function(functionType, theDomain, theRange, theFunctions, theBounds, theEncode); - } - - public Function makeFunction(int functionType, List theDomain, - List theRange, List theCZero, List theCOne, - double theInterpolationExponentN) { - Function newFunction = new Function(functionType, theDomain, theRange, theCZero, - theCOne, theInterpolationExponentN); - return newFunction; - } - @Override public Shading makeShading(int theShadingType, PDFDeviceColorSpace theColorSpace, List theBackground, List theBBox, 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 { - public Function makeFunction(int functionType, List theDomain, - List theRange, List theFunctions, - List theBounds, List theEncode) { - Function newFunction = new PSFunction(functionType, theDomain, theRange, theFunctions, - theBounds, theEncode); - return newFunction; - } - - @Override - public Function makeFunction(int functionType, List theDomain, - List theRange, List theCZero, List theCOne, - double theInterpolationExponentN) { - Function newFunction = new PSFunction(functionType, theDomain, theRange, theCZero, - theCOne, theInterpolationExponentN); - return newFunction; - } - @Override public Shading makeShading(int theShadingType, PDFDeviceColorSpace theColorSpace, List theBackground, List theBBox, -- 2.39.5