+++ /dev/null
-/*
- * 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];
- }
- }
-
-}
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;
* 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
this.coords = theCoords;
this.domain = theDomain;
- assert theFunction instanceof PSFunction;
- this.function = (PSFunction)theFunction;
+ this.function = theFunction;
this.extend = theExtend;
}
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
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);
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;
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,
this.graphics2D = pdfGraphics2D;
}
- @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,
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,