@@ -43,18 +43,19 @@ This file is part of the iText (R) project.
43
43
*/
44
44
package com .itextpdf .kernel .pdf .colorspace ;
45
45
46
- import com .itextpdf .kernel .exceptions .PdfException ;
47
46
import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
47
+ import com .itextpdf .kernel .exceptions .PdfException ;
48
48
import com .itextpdf .kernel .pdf .PdfArray ;
49
49
import com .itextpdf .kernel .pdf .PdfDictionary ;
50
50
import com .itextpdf .kernel .pdf .PdfDocument ;
51
51
import com .itextpdf .kernel .pdf .PdfName ;
52
52
import com .itextpdf .kernel .pdf .PdfNumber ;
53
53
import com .itextpdf .kernel .pdf .PdfObject ;
54
54
import com .itextpdf .kernel .pdf .PdfString ;
55
- import com .itextpdf .kernel .pdf .function .PdfFunctionFactory ;
55
+ import com .itextpdf .kernel .pdf .function .AbstractPdfFunction ;
56
56
import com .itextpdf .kernel .pdf .function .IPdfFunction ;
57
57
import com .itextpdf .kernel .pdf .function .PdfFunction ;
58
+ import com .itextpdf .kernel .pdf .function .PdfFunctionFactory ;
58
59
59
60
import java .util .Arrays ;
60
61
import java .util .List ;
@@ -125,6 +126,17 @@ public Separation(PdfName name, PdfObject alternateSpace, PdfObject tintTransfor
125
126
this (getSeparationCsArray (name , alternateSpace , tintTransform ));
126
127
}
127
128
129
+ /**
130
+ * Creates a new separation color space.
131
+ *
132
+ * @param name The name for the separation color
133
+ * @param alternateSpace The alternate colorspace
134
+ * @param tintTransform The function how the transform colors in the separation color space
135
+ * to the alternate color space
136
+ * @deprecated This constructor has been replaced
137
+ * by {@link #Separation(String, PdfColorSpace, IPdfFunction)}
138
+ */
139
+ @ Deprecated
128
140
public Separation (String name , PdfColorSpace alternateSpace , PdfFunction tintTransform ) {
129
141
this (new PdfName (name ), alternateSpace .getPdfObject (), tintTransform .getPdfObject ());
130
142
if (!tintTransform .checkCompatibilityWithColorSpace (alternateSpace )) {
@@ -133,6 +145,22 @@ public Separation(String name, PdfColorSpace alternateSpace, PdfFunction tintTra
133
145
}
134
146
}
135
147
148
+ /**
149
+ * Creates a new separation color space.
150
+ *
151
+ * @param name The name for the separation color
152
+ * @param alternateSpace The alternate colorspace
153
+ * @param tintTransform The function how the transform colors in the separation color space
154
+ * to the alternate color space
155
+ */
156
+ public Separation (String name , PdfColorSpace alternateSpace , IPdfFunction tintTransform ) {
157
+ this (new PdfName (name ), alternateSpace .getPdfObject (), ((AbstractPdfFunction )tintTransform ).getPdfObject ());
158
+ if (!tintTransform .checkCompatibilityWithColorSpace (alternateSpace )) {
159
+ throw new PdfException (
160
+ KernelExceptionMessageConstant .FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE , this );
161
+ }
162
+ }
163
+
136
164
@ Override
137
165
public int getNumberOfComponents () {
138
166
return 1 ;
@@ -180,9 +208,38 @@ public DeviceN(PdfArray names, PdfObject alternateSpace, PdfObject tintTransform
180
208
this (getDeviceNCsArray (names , alternateSpace , tintTransform ));
181
209
}
182
210
211
+ /**
212
+ * Creates a new DeviceN colorspace.
213
+ *
214
+ * @param names the names of the components
215
+ * @param alternateSpace the alternate colorspace
216
+ * @param tintTransform the function to transform colors to the alternate colorspace
217
+ *
218
+ * @deprecated Use constructor {@link #DeviceN(List, PdfColorSpace, IPdfFunction)} instead.
219
+ */
220
+
221
+ @ Deprecated
183
222
public DeviceN (List <String > names , PdfColorSpace alternateSpace , PdfFunction tintTransform ) {
184
223
this (new PdfArray (names , true ), alternateSpace .getPdfObject (), tintTransform .getPdfObject ());
185
- if (tintTransform .getInputSize () != getNumberOfComponents () || tintTransform .getOutputSize () != alternateSpace .getNumberOfComponents ()) {
224
+ if (tintTransform .getInputSize () != numOfComponents ||
225
+ tintTransform .getOutputSize () != alternateSpace .getNumberOfComponents ()) {
226
+ throw new PdfException (
227
+ KernelExceptionMessageConstant .FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE , this );
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Creates a new DiviceN colorspace.
233
+ *
234
+ * @param names the names of the components
235
+ * @param alternateSpace the alternate colorspace
236
+ * @param tintTransform the function to transform colors to the alternate colorspace
237
+ */
238
+ public DeviceN (List <String > names , PdfColorSpace alternateSpace , IPdfFunction tintTransform ) {
239
+ this (new PdfArray (names , true ), alternateSpace .getPdfObject (),
240
+ ((AbstractPdfFunction )tintTransform ).getPdfObject ());
241
+ if (tintTransform .getInputSize () != numOfComponents ||
242
+ tintTransform .getOutputSize () != alternateSpace .getNumberOfComponents ()) {
186
243
throw new PdfException (
187
244
KernelExceptionMessageConstant .FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE , this );
188
245
}
@@ -223,15 +280,49 @@ public NChannel(PdfArray names, PdfObject alternateSpace, PdfObject tintTransfor
223
280
this (getNChannelCsArray (names , alternateSpace , tintTransform , attributes ));
224
281
}
225
282
226
- public NChannel (List <String > names , PdfColorSpace alternateSpace , PdfFunction tintTransform , PdfDictionary attributes ) {
283
+ /**
284
+ * Creates a new NChannel colorspace.
285
+ *
286
+ * @param names the names for the components
287
+ * @param alternateSpace the alternative colorspace
288
+ * @param tintTransform the function to transform colors to the alternate color space
289
+ * @param attributes NChannel specific attributes
290
+ * @deprecated Use constructor {@link #NChannel(PdfArray, PdfObject, PdfObject, PdfDictionary) NChannel} instead
291
+ */
292
+
293
+ @ Deprecated
294
+ public NChannel (List <String > names , PdfColorSpace alternateSpace , PdfFunction tintTransform ,
295
+ PdfDictionary attributes ) {
227
296
this (new PdfArray (names , true ), alternateSpace .getPdfObject (), tintTransform .getPdfObject (), attributes );
228
- if (tintTransform .getInputSize () != 1 || tintTransform .getOutputSize () != alternateSpace .getNumberOfComponents ()) {
297
+ if (tintTransform .getInputSize () != 1 ||
298
+ tintTransform .getOutputSize () != alternateSpace .getNumberOfComponents ()) {
299
+ throw new PdfException (
300
+ KernelExceptionMessageConstant .FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE , this );
301
+ }
302
+ }
303
+
304
+ /**
305
+ * Creates a new NChannel colorspace.
306
+ *
307
+ * @param names the names for the components
308
+ * @param alternateSpace the alternative colorspace
309
+ * @param tintTransform the function to transform colors to the alternate color space
310
+ * @param attributes NChannel specific attributes
311
+ */
312
+ public NChannel (List <String > names , PdfColorSpace alternateSpace , IPdfFunction tintTransform ,
313
+ PdfDictionary attributes ) {
314
+ this (new PdfArray (names , true ), alternateSpace .getPdfObject (),
315
+ ((AbstractPdfFunction )tintTransform ).getPdfObject (), attributes );
316
+ if (tintTransform .getInputSize () != 1 ||
317
+ tintTransform .getOutputSize () != alternateSpace .getNumberOfComponents ()) {
229
318
throw new PdfException (
230
319
KernelExceptionMessageConstant .FUNCTION_IS_NOT_COMPATIBLE_WITH_COLOR_SPACE , this );
231
320
}
232
321
}
233
322
234
- protected static PdfArray getNChannelCsArray (PdfArray names , PdfObject alternateSpace , PdfObject tintTransform , PdfDictionary attributes ) {
323
+
324
+ protected static PdfArray getNChannelCsArray (PdfArray names , PdfObject alternateSpace , PdfObject tintTransform ,
325
+ PdfDictionary attributes ) {
235
326
PdfArray nChannel = getDeviceNCsArray (names , alternateSpace , tintTransform );
236
327
nChannel .add (attributes );
237
328
return nChannel ;
@@ -242,11 +333,6 @@ protected static PdfArray getNChannelCsArray(PdfArray names, PdfObject alternate
242
333
public static class Pattern extends PdfColorSpace {
243
334
244
335
245
- @ Override
246
- protected boolean isWrappedObjectMustBeIndirect () {
247
- return false ;
248
- }
249
-
250
336
public Pattern () {
251
337
super (PdfName .Pattern );
252
338
}
@@ -258,12 +344,25 @@ protected Pattern(PdfObject pdfObj) {
258
344
@ Override
259
345
public int getNumberOfComponents () {
260
346
return 0 ;
347
+ }
348
+
349
+ @ Override
350
+ protected boolean isWrappedObjectMustBeIndirect () {
351
+ return false ;
261
352
}
262
353
}
263
354
264
355
public static class UncoloredTilingPattern extends Pattern {
265
356
266
357
358
+ public UncoloredTilingPattern (PdfArray pdfObject ) {
359
+ super (pdfObject );
360
+ }
361
+
362
+ public UncoloredTilingPattern (PdfColorSpace underlyingColorSpace ) {
363
+ super (new PdfArray (Arrays .asList (PdfName .Pattern , underlyingColorSpace .getPdfObject ())));
364
+ }
365
+
267
366
/**
268
367
* To manually flush a {@code PdfObject} behind this wrapper, you have to ensure
269
368
* that this object is added to the document, i.e. it has an indirect reference.
@@ -276,26 +375,18 @@ public void flush() {
276
375
super .flush ();
277
376
}
278
377
279
- @ Override
280
- protected boolean isWrappedObjectMustBeIndirect () {
281
- return true ;
282
- }
283
-
284
- public UncoloredTilingPattern (PdfArray pdfObject ) {
285
- super (pdfObject );
286
- }
287
-
288
- public UncoloredTilingPattern (PdfColorSpace underlyingColorSpace ) {
289
- super (new PdfArray (Arrays .asList (PdfName .Pattern , underlyingColorSpace .getPdfObject ())));
378
+ public PdfColorSpace getUnderlyingColorSpace () {
379
+ return PdfColorSpace .makeColorSpace (((PdfArray ) getPdfObject ()).get (1 ));
290
380
}
291
381
292
382
@ Override
293
383
public int getNumberOfComponents () {
294
384
return PdfColorSpace .makeColorSpace (((PdfArray ) getPdfObject ()).get (1 )).getNumberOfComponents ();
295
385
}
296
386
297
- public PdfColorSpace getUnderlyingColorSpace () {
298
- return PdfColorSpace .makeColorSpace (((PdfArray ) getPdfObject ()).get (1 ));
387
+ @ Override
388
+ protected boolean isWrappedObjectMustBeIndirect () {
389
+ return true ;
299
390
}
300
391
}
301
392
0 commit comments