import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Iterator;
* @return the PDF function that was created
*/
public PDFFunction makeFunction(int theFunctionType, List theDomain,
- List theRange, List theCZero,
- List theCOne,
+ List theRange, float[] theCZero,
+ float[] theCOne,
double theInterpolationExponentN) { // type 2
PDFFunction function = new PDFFunction(theFunctionType, theDomain,
theRange, theCZero, theCOne,
final Double one = new Double(1d);
List theDomain = Arrays.asList(new Double[] {zero, one});
List theRange = Arrays.asList(new Double[] {zero, one, zero, one, zero, one});
- List theCZero = Arrays.asList(new Double[] {one, one, one});
- List theCOne = new ArrayList();
- float[] comps = ncs.getRGBColor().getColorComponents(null);
- for (int i = 0, c = comps.length; i < c; i++) {
- theCOne.add(new Double(comps[i]));
- }
- PDFFunction tintFunction = makeFunction(2, theDomain, theRange,
- theCZero, theCOne, 1.0d);
+ float[] cZero = new float[] {1f, 1f, 1f};
+ float[] cOne = ncs.getRGBColor().getColorComponents(null);
+ PDFFunction tintFunction = makeFunction(2, theDomain, theRange, cZero, cOne, 1.0d);
PDFSeparationColorSpace cs = new PDFSeparationColorSpace(colorName, tintFunction);
getDocument().registerObject(cs);
if (res != null) {
package org.apache.fop.pdf;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
* @param theFunctionType The type of the function, which should be 2.
*/
public PDFFunction(int theFunctionType, List<Double> theDomain,
- List<Double> theRange, List<Double> theCZero, List<Double> theCOne,
+ List<Double> theRange, float[] theCZero, float[] theCOne,
double theInterpolationExponentN) {
this(new Function(theFunctionType, theDomain, theRange,
theCZero, theCOne, theInterpolationExponentN));
} else if (func.getFilter() != null) {
return false;
}
- if (function.getCZero() != null) {
- if (!function.getCZero().equals(func.getCZero())) {
- return false;
- }
- } else if (func.getCZero() != null) {
+ if (!Arrays.equals(function.getCZero(), func.getCZero())) {
return false;
}
- if (function.getCOne() != null) {
- if (!function.getCOne().equals(func.getCOne())) {
- return false;
- }
- } else if (func.getCOne() != null) {
+ if (!Arrays.equals(function.getCOne(), func.getCOne())) {
return false;
}
if (!pdfFunctions.equals(((PDFFunction) obj).pdfFunctions)) {
* Required For Type 2: An Array of n Doubles defining
* the function result when x=0. Default is [0].
*/
- protected List<Double> cZero = null;
+ protected float[] cZero;
/**
* Required For Type 2: An Array of n Doubles defining
* the function result when x=1. Default is [1].
*/
- protected List<Double> cOne = null;
+ protected float[] cOne;
/**
* Required for Type 2: The interpolation exponent.
*/
protected List<Double> bounds = null;
- /**
- * create an complete Function object of Type 0, A Sampled function.
- *
- * Use null for an optional object parameter if you choose not to use it.
- * For optional int parameters, pass the default.
- * @param theFunctionType This is the type of function (0,2,3, or 4).
- * It should be 0 as this is the constructor for sampled functions.
- * @param theDomain List objects of Double objects.
- * This is the domain of the function.
- * See page 264 of the PDF 1.3 Spec.
- * @param theRange List objects of Double objects.
- * This is the Range of the function.
- * See page 264 of the PDF 1.3 Spec.
- * @param theSize A List object of Integer objects.
- * This is the number of samples in each input dimension.
- * I can't imagine there being more or less than two input dimensions,
- * so maybe this should be an array of length 2.
- *
- * See page 265 of the PDF 1.3 Spec.
- * @param theBitsPerSample An int specifying the number of bits
- used to represent each sample value.
- * Limited to 1,2,4,8,12,16,24 or 32.
- * See page 265 of the 1.3 PDF Spec.
- * @param theOrder The order of interpolation between samples. Default is 1 (one). Limited
- * to 1 (one) or 3, which means linear or cubic-spline interpolation.
- *
- * This attribute is optional.
- *
- * See page 265 in the PDF 1.3 spec.
- * @param theEncode List objects of Double objects.
- * This is the linear mapping of input values intop the domain
- * of the function's sample table. Default is hard to represent in
- * ascii, but basically [0 (Size0 1) 0 (Size1 1)...].
- * This attribute is optional.
- *
- * See page 265 in the PDF 1.3 spec.
- * @param theDecode List objects of Double objects.
- * This is a linear mapping of sample values into the range.
- * The default is just the range.
- *
- * This attribute is optional.
- * Read about it on page 265 of the PDF 1.3 spec.
- * @param theFunctionDataStream The sample values that specify
- * the function are provided in a stream.
- *
- * This is optional, but is almost always used.
- *
- * Page 265 of the PDF 1.3 spec has more.
- * @param theFilter This is a vector of String objects which are the various filters that
- * have are to be applied to the stream to make sense of it. Order matters,
- * so watch out.
- *
- * This is not documented in the Function section of the PDF 1.3 spec,
- * it was deduced from samples that this is sometimes used, even if we may never
- * use it in FOP. It is added for completeness sake.
- */
- public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
- List<Double> theSize, int theBitsPerSample, int theOrder,
- List<Double> theEncode, List<Double> theDecode, StringBuffer theFunctionDataStream,
- List<String> theFilter) {
- this.functionType = 0; // dang well better be 0;
- this.size = theSize;
- this.bitsPerSample = theBitsPerSample;
- this.order = theOrder; // int
- this.encode = theEncode; // vector of int
- this.decode = theDecode; // vector of int
- this.functionDataStream = theFunctionDataStream;
- this.filter = theFilter; // vector of Strings
-
- // the domain and range are actually two dimensional arrays.
- // so if there's not an even number of items, bad stuff
- // happens.
- this.domain = theDomain;
- this.range = theRange;
- }
-
/**
* create an complete Function object of Type 2, an Exponential Interpolation function.
*
*
* This attribute is optional.
* It's described on page 268 of the PDF 1.3 spec.
- * @param theCOne This is a vector of Double objects which defines the function result
+ * @param cOne This is a vector of Double objects which defines the function result
* when x=1.
*
* This attribute is optional.
* PDF Spec page 268
*/
public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
- List<Double> theCZero, List<Double> theCOne, double theInterpolationExponentN) {
+ float[] cZero, float[] cOne, double theInterpolationExponentN) {
this.functionType = 2; // dang well better be 2;
- this.cZero = theCZero;
- this.cOne = theCOne;
+ this.cZero = cZero;
+ this.cOne = cOne;
this.interpolationExponentN = theInterpolationExponentN;
this.domain = theDomain;
}
- /**
- * create an complete Function object of Type 4, a postscript calculator function.
- *
- * Use null for an optional object parameter if you choose not to use it.
- * For optional int parameters, pass the default.
- * @param theFunctionType The type of function which should be 4, as this is
- * a Postscript calculator function
- * @param theDomain List object of Double objects.
- * This is the domain of the function.
- * See page 264 of the PDF 1.3 Spec.
- * @param theRange List object of Double objects.
- * This is the Range of the function.
- * See page 264 of the PDF 1.3 Spec.
- * @param theFunctionDataStream This is a stream of arithmetic,
- * boolean, and stack operators and boolean constants.
- * I end up enclosing it in the '{' and '}' braces for you, so don't do it
- * yourself.
- *
- * This attribute is required.
- * It's described on page 269 of the PDF 1.3 spec.
- */
- public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
- StringBuffer theFunctionDataStream) {
- this.functionType = 4; // dang well better be 4;
- this.functionDataStream = theFunctionDataStream;
-
- this.domain = theDomain;
-
- this.range = theRange;
-
- }
-
/**
* Gets the function type
*/
/**
* Gets the function C0 value (color for gradient)
*/
- public List<Double> getCZero() {
+ public float[] getCZero() {
return cZero;
}
/**
* Gets the function C1 value (color for gradient)
*/
- public List<Double> getCOne() {
+ public float[] getCOne() {
return cOne;
}