1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
/*
* 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.
*/
package org.apache.fop.render.shading;
import java.util.Collections;
import java.util.List;
public class Function {
/**
* Required: The Type of function (0,2,3,4) default is 0.
*/
protected int functionType = 0; // Default
/**
* Required: 2 * m Array of Double numbers which are possible inputs to the function
*/
protected List<Double> domain = null;
/**
* Required: 2 * n Array of Double numbers which are possible outputs to the function
*/
protected List<Double> range = null;
/* ********************TYPE 0***************************** */
// FunctionType 0 specific function guts
/**
* Required: Array containing the Integer size of the Domain and Range, respectively.
* Note: This is really more like two seperate integers, sizeDomain, and sizeRange,
* but since they're expressed as an array in PDF, my implementation reflects that.
*/
protected List<Double> size = null;
/**
* Required for Type 0: Number of Bits used to represent each sample value.
* Limited to 1,2,4,8,12,16,24, or 32
*/
protected int bitsPerSample = 1;
/**
* Optional for Type 0: order of interpolation between samples.
* Limited to linear (1) or cubic (3). Default is 1
*/
protected int order = 1;
/**
* Optional for Type 0: A 2 * m array of Doubles which provides a
* linear mapping of input values to the domain.
*
* Required for Type 3: A 2 * k array of Doubles that, taken
* in pairs, map each subset of the domain defined by Domain
* and the Bounds array to the domain of the corresponding function.
* Should be two values per function, usually (0,1),
* as in [0 1 0 1] for 2 functions.
*/
protected List<Double> encode = null;
/**
* Optional for Type 0: A 2 * n array of Doubles which provides
* a linear mapping of sample values to the range. Defaults to Range.
*/
protected List<Double> decode = null;
/**
* Optional For Type 0: A stream of sample values
*/
/**
* Required For Type 4: Postscript Calculator function
* composed of arithmetic, boolean, and stack operators + boolean constants
*/
protected StringBuffer functionDataStream = null;
/**
* Required (possibly) For Type 0: A vector of Strings for the
* various filters to be used to decode the stream.
* These are how the string is compressed. Flate, LZW, etc.
*/
protected List<String> filter = null;
/* *************************TYPE 2************************** */
/**
* Required For Type 2: An Array of n Doubles defining
* the function result when x=0. Default is [0].
*/
protected float[] cZero;
/**
* Required For Type 2: An Array of n Doubles defining
* the function result when x=1. Default is [1].
*/
protected float[] cOne;
/**
* Required for Type 2: The interpolation exponent.
* Each value x will return n results.
* Must be greater than 0.
*/
protected double interpolationExponentN = 1;
/* *************************TYPE 3************************** */
/**
* Required for Type 3: An vector of PDFFunctions which
* form an array of k single input functions making up
* the stitching function.
*/
protected List<Function> functions = null;
/**
* Optional for Type 3: An array of (k-1) Doubles that,
* in combination with Domain, define the intervals to which
* each function from the Functions array apply. Bounds
* elements must be in order of increasing magnitude,
* and each value must be within the value of Domain.
* k is the number of functions.
* If you pass null, it will output (1/k) in an array of k-1 elements.
* This makes each function responsible for an equal amount of the stitching function.
* It makes the gradient even.
*/
protected List<Double> bounds = null;
/**
* create an complete Function object of Type 2, an Exponential Interpolation 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 the function, which should be 2.
* @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 of Doubles that is the Range of the function.
* See page 264 of the PDF 1.3 Spec.
* @param theCZero This is a vector of Double objects which defines the function result
* when x=0.
*
* This attribute is optional.
* It's described on page 268 of the PDF 1.3 spec.
* @param cOne This is a vector of Double objects which defines the function result
* when x=1.
*
* This attribute is optional.
* It's described on page 268 of the PDF 1.3 spec.
* @param theInterpolationExponentN This is the inerpolation exponent.
*
* This attribute is required.
* PDF Spec page 268
*/
public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
float[] cZero, float[] cOne, double theInterpolationExponentN) {
this.functionType = 2; // dang well better be 2;
this.cZero = cZero;
this.cOne = cOne;
this.interpolationExponentN = theInterpolationExponentN;
this.domain = theDomain;
this.range = theRange;
}
/**
* create an complete Function object of Type 3, a Stitching 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 function type. It should be 3,
* for a stitching function.
* @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 theFunctions A List of the PDFFunction objects that the stitching function stitches.
*
* This attributed is required.
* It is described on page 269 of the PDF spec.
* @param theBounds This is a vector of Doubles representing the numbers that,
* in conjunction with Domain define the intervals to which each function from
* the 'functions' object applies. It must be in order of increasing magnitude,
* and each must be within Domain.
*
* It basically sets how much of the gradient each function handles.
*
* This attributed is required.
* It's described on page 269 of 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 required.
*
* See page 270 in the PDF 1.3 spec.
*/
public Function(int theFunctionType, List<Double> theDomain, List<Double> theRange,
List<Function> theFunctions, List<Double> theBounds,
List<Double> theEncode) {
this.functionType = 3; // dang well better be 3;
this.functions = theFunctions;
this.bounds = theBounds;
this.encode = theEncode;
this.domain = theDomain;
this.range = theRange;
}
/**
* Gets the function type
*/
public int getFunctionType() {
return functionType;
}
/**
* Gets the function bounds
*/
public List<Double> getBounds() {
return bounds;
}
/**
* The function domain
*/
public List<Double> getDomain() {
return domain;
}
/**
* The function size
*/
public List<Double> getSize() {
return size;
}
/**
* Gets the function encoding
*/
public List<Double> getEncode() {
return encode;
}
/**
* Gets the sub-functions
*/
public List<Function> getFunctions() {
if (functions == null) {
return Collections.emptyList();
} else {
return functions;
}
}
/**
* Gets the function filter
*/
public List<String> getFilter() {
return filter;
}
/**
* Gets the bits per sample of the function
*/
public int getBitsPerSample() {
return bitsPerSample;
}
/**
* Gets the interpolation exponent of the function
*/
public double getInterpolationExponentN() {
return interpolationExponentN;
}
/**
* Gets the function order
*/
public int getOrder() {
return order;
}
/**
* Gets the function range
*/
public List<Double> getRange() {
return range;
}
/**
* Gets the function decoding
*/
public List<Double> getDecode() {
return decode;
}
/**
* Gets the function data stream
*/
public StringBuffer getDataStream() {
return functionDataStream;
}
/**
* Gets the function C0 value (color for gradient)
*/
public float[] getCZero() {
return cZero;
}
/**
* Gets the function C1 value (color for gradient)
*/
public float[] getCOne() {
return cOne;
}
}
|