@@ -71,18 +71,16 @@ This file is part of the iText (R) project.
71
71
import com .itextpdf .kernel .pdf .colorspace .PdfPattern ;
72
72
import com .itextpdf .kernel .pdf .colorspace .PdfShading ;
73
73
import com .itextpdf .kernel .pdf .colorspace .PdfSpecialCs ;
74
+ import com .itextpdf .kernel .pdf .function .PdfType4Function ;
74
75
import com .itextpdf .kernel .utils .CompareTool ;
75
76
import com .itextpdf .test .ExtendedITextTest ;
76
77
import com .itextpdf .test .annotations .type .IntegrationTest ;
77
78
78
79
import java .io .ByteArrayInputStream ;
79
80
import java .io .FileInputStream ;
80
81
import java .io .IOException ;
81
-
82
82
import java .nio .charset .StandardCharsets ;
83
-
84
83
import java .util .ArrayList ;
85
-
86
84
import org .junit .Assert ;
87
85
import org .junit .BeforeClass ;
88
86
import org .junit .Test ;
@@ -263,7 +261,8 @@ public void colorTest06() throws Exception {
263
261
PdfDocument document = new PdfDocument (writer );
264
262
PdfPage page = document .addNewPage ();
265
263
266
- PdfSpecialCs .Indexed indexed = new PdfSpecialCs .Indexed (com .itextpdf .kernel .pdf .PdfName .DeviceRGB , 255 , new PdfString (new String (bytes , "UTF-8" )));
264
+ PdfSpecialCs .Indexed indexed = new PdfSpecialCs .Indexed (com .itextpdf .kernel .pdf .PdfName .DeviceRGB , 255 , new PdfString (new String (bytes ,
265
+ StandardCharsets .UTF_8 )));
267
266
PdfCanvas canvas = new PdfCanvas (page );
268
267
canvas .setFillColor (new Indexed (indexed , 85 )).rectangle (50 , 500 , 50 , 50 ).fill ();
269
268
canvas .setFillColor (new Indexed (indexed , 127 )).rectangle (150 , 500 , 50 , 50 ).fill ();
@@ -276,7 +275,7 @@ public void colorTest06() throws Exception {
276
275
}
277
276
278
277
@ Test
279
- public void colorTest07 () throws Exception {
278
+ public void colorTest07Depr () throws Exception {
280
279
PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + "colorTest07.pdf" );
281
280
writer .setCompressionLevel (CompressionConstants .NO_COMPRESSION );
282
281
PdfDocument document = new PdfDocument (writer );
@@ -297,7 +296,29 @@ public void colorTest07() throws Exception {
297
296
}
298
297
299
298
@ Test
300
- public void colorTest08 () throws Exception {
299
+ public void colorTest07 () throws Exception {
300
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + "colorTest07.pdf" );
301
+ writer .setCompressionLevel (CompressionConstants .NO_COMPRESSION );
302
+ PdfDocument document = new PdfDocument (writer );
303
+ PdfPage page = document .addNewPage ();
304
+
305
+ //com.itextpdf.kernel.pdf.function.PdfFunction.Type4 function = new com.itextpdf.kernel.pdf.function.PdfFunction.Type4(new PdfArray(new float[]{0, 1}), new PdfArray(new float[]{0, 1, 0, 1, 0, 1}), "{0 0}".getBytes(StandardCharsets.ISO_8859_1));
306
+ PdfType4Function function = new PdfType4Function (new double []{0 , 1 }, new double []{0 , 1 , 0 , 1 , 0 , 1 }, "{0 0}" .getBytes (StandardCharsets .ISO_8859_1 ));
307
+ PdfSpecialCs .Separation separation = new PdfSpecialCs .Separation ("MyRed" , new PdfDeviceCs .Rgb (), function );
308
+
309
+ PdfCanvas canvas = new PdfCanvas (page );
310
+ canvas .setFillColor (new Separation (separation , 0.25f )).rectangle (50 , 500 , 50 , 50 ).fill ();
311
+ canvas .setFillColor (new Separation (separation , 0.5f )).rectangle (150 , 500 , 50 , 50 ).fill ();
312
+ canvas .setFillColor (new Separation (separation , 0.75f )).rectangle (250 , 500 , 50 , 50 ).fill ();
313
+ canvas .release ();
314
+ document .close ();
315
+
316
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + "colorTest07.pdf" ,
317
+ SOURCE_FOLDER + "cmp_colorTest07.pdf" , DESTINATION_FOLDER , "diff_" ));
318
+ }
319
+
320
+ @ Test
321
+ public void colorTest08Depr () throws Exception {
301
322
PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + "colorTest08.pdf" );
302
323
writer .setCompressionLevel (CompressionConstants .NO_COMPRESSION );
303
324
PdfDocument document = new PdfDocument (writer );
@@ -322,63 +343,39 @@ public void colorTest08() throws Exception {
322
343
}
323
344
324
345
@ Test
325
- public void setColorsSameColorSpaces () throws IOException , InterruptedException {
326
- setColorSameColorSpacesTest ("setColorsSameColorSpaces.pdf" , false );
327
- }
328
-
329
- @ Test
330
- public void setColorsSameColorSpacesPattern () throws IOException , InterruptedException {
331
- setColorSameColorSpacesTest ("setColorsSameColorSpacesPattern.pdf" , true );
332
- }
346
+ public void colorTest08 () throws Exception {
347
+ PdfWriter writer = new PdfWriter (DESTINATION_FOLDER + "colorTest08.pdf" );
348
+ writer .setCompressionLevel (CompressionConstants .NO_COMPRESSION );
349
+ PdfDocument document = new PdfDocument (writer );
350
+ PdfPage page = document .addNewPage ();
333
351
334
- private void setColorSameColorSpacesTest (String pdfName , boolean pattern ) throws IOException , InterruptedException {
335
- String cmpFile = SOURCE_FOLDER + "cmp_" + pdfName ;
336
- String destFile = DESTINATION_FOLDER + pdfName ;
352
+ PdfType4Function function = new PdfType4Function (new double []{0 , 1 , 0 , 1 }, new double []{0 , 1 , 0 , 1 , 0 , 1 }, "{0}" .getBytes (StandardCharsets .ISO_8859_1 ));
337
353
338
- PdfDocument document = new PdfDocument (new PdfWriter (destFile ));
354
+ ArrayList <String > tmpArray = new ArrayList <String >(2 );
355
+ tmpArray .add ("MyRed" );
356
+ tmpArray .add ("MyGreen" );
357
+ PdfSpecialCs .DeviceN deviceN = new PdfSpecialCs .DeviceN (tmpArray , new PdfDeviceCs .Rgb (), function );
339
358
340
- PdfPage page = document .addNewPage ();
341
359
PdfCanvas canvas = new PdfCanvas (page );
360
+ canvas .setFillColor (new DeviceN (deviceN , new float []{0 , 0 })).rectangle (50 , 500 , 50 , 50 ).fill ();
361
+ canvas .setFillColor (new DeviceN (deviceN , new float []{0 , 1 })).rectangle (150 , 500 , 50 , 50 ).fill ();
362
+ canvas .setFillColor (new DeviceN (deviceN , new float []{1 , 0 })).rectangle (250 , 500 , 50 , 50 ).fill ();
363
+ canvas .release ();
364
+ document .close ();
342
365
343
- PdfColorSpace space = pattern ? new PdfSpecialCs .Pattern () : PdfColorSpace .makeColorSpace (PdfName .DeviceRGB );
344
- float [] colorValue1 = pattern ? null : new float []{1.0f , 0.6f , 0.7f };
345
- float [] colorValue2 = pattern ? null : new float []{0.1f , 0.9f , 0.9f };
346
-
347
- PdfPattern pattern1 = pattern ? new PdfPattern .Shading (new PdfShading .Axial (new PdfDeviceCs .Rgb (), 45 , 750 , ColorConstants .PINK .getColorValue (),
348
- 100 , 760 , ColorConstants .MAGENTA .getColorValue ())) : null ;
349
- PdfPattern pattern2 = pattern ? new PdfPattern .Shading (new PdfShading .Axial (new PdfDeviceCs .Rgb (), 45 , 690 , ColorConstants .BLUE .getColorValue (),
350
- 100 , 710 , ColorConstants .CYAN .getColorValue ())) : null ;
351
-
352
- canvas .setColor (space , colorValue1 , pattern1 , true );
353
- canvas .saveState ();
354
- canvas .beginText ()
355
- .moveText (50 , 750 )
356
- .setFontAndSize (PdfFontFactory .createFont (), 16 )
357
- .showText ("pinkish" )
358
- .endText ();
359
- canvas .saveState ()
360
- .beginText ()
361
- .setColor (space , colorValue2 , pattern2 , true )
362
- .moveText (50 , 720 )
363
- .setFontAndSize (PdfFontFactory .createFont (), 16 )
364
- .showText ("bluish" )
365
- .endText ()
366
- .restoreState ();
367
- canvas .restoreState ();
368
- canvas .saveState ()
369
- .beginText ()
370
- .moveText (50 , 690 )
371
- .setColor (space , colorValue2 , pattern2 , true )
372
- .setFontAndSize (PdfFontFactory .createFont (), 16 )
373
- .showText ("bluish" )
374
- .endText ()
375
- .restoreState ();
366
+ Assert .assertNull (new CompareTool ().compareByContent (DESTINATION_FOLDER + "colorTest08.pdf" ,
367
+ SOURCE_FOLDER + "cmp_colorTest08.pdf" , DESTINATION_FOLDER , "diff_" ));
368
+ }
376
369
377
- canvas .release ();
378
370
379
- document .close ();
371
+ @ Test
372
+ public void setColorsSameColorSpaces () throws IOException , InterruptedException {
373
+ setColorSameColorSpacesTest ("setColorsSameColorSpaces.pdf" , false );
374
+ }
380
375
381
- Assert .assertNull (new CompareTool ().compareByContent (destFile , cmpFile , DESTINATION_FOLDER , "diff_" ));
376
+ @ Test
377
+ public void setColorsSameColorSpacesPattern () throws IOException , InterruptedException {
378
+ setColorSameColorSpacesTest ("setColorsSameColorSpacesPattern.pdf" , true );
382
379
}
383
380
384
381
@ Test
@@ -628,6 +625,56 @@ public void patternColorUncoloredPatternColorUnitTest() {
628
625
Assert .assertThrows (IllegalArgumentException .class , () -> new PatternColor (circle , redCirclePattern ));
629
626
}
630
627
628
+ private void setColorSameColorSpacesTest (String pdfName , boolean pattern ) throws IOException , InterruptedException {
629
+ String cmpFile = SOURCE_FOLDER + "cmp_" + pdfName ;
630
+ String destFile = DESTINATION_FOLDER + pdfName ;
631
+
632
+ PdfDocument document = new PdfDocument (new PdfWriter (destFile ));
633
+
634
+ PdfPage page = document .addNewPage ();
635
+ PdfCanvas canvas = new PdfCanvas (page );
636
+
637
+ PdfColorSpace space = pattern ? new PdfSpecialCs .Pattern () : PdfColorSpace .makeColorSpace (PdfName .DeviceRGB );
638
+ float [] colorValue1 = pattern ? null : new float []{1.0f , 0.6f , 0.7f };
639
+ float [] colorValue2 = pattern ? null : new float []{0.1f , 0.9f , 0.9f };
640
+
641
+ PdfPattern pattern1 = pattern ? new PdfPattern .Shading (new PdfShading .Axial (new PdfDeviceCs .Rgb (), 45 , 750 , ColorConstants .PINK .getColorValue (),
642
+ 100 , 760 , ColorConstants .MAGENTA .getColorValue ())) : null ;
643
+ PdfPattern pattern2 = pattern ? new PdfPattern .Shading (new PdfShading .Axial (new PdfDeviceCs .Rgb (), 45 , 690 , ColorConstants .BLUE .getColorValue (),
644
+ 100 , 710 , ColorConstants .CYAN .getColorValue ())) : null ;
645
+
646
+ canvas .setColor (space , colorValue1 , pattern1 , true );
647
+ canvas .saveState ();
648
+ canvas .beginText ()
649
+ .moveText (50 , 750 )
650
+ .setFontAndSize (PdfFontFactory .createFont (), 16 )
651
+ .showText ("pinkish" )
652
+ .endText ();
653
+ canvas .saveState ()
654
+ .beginText ()
655
+ .setColor (space , colorValue2 , pattern2 , true )
656
+ .moveText (50 , 720 )
657
+ .setFontAndSize (PdfFontFactory .createFont (), 16 )
658
+ .showText ("bluish" )
659
+ .endText ()
660
+ .restoreState ();
661
+ canvas .restoreState ();
662
+ canvas .saveState ()
663
+ .beginText ()
664
+ .moveText (50 , 690 )
665
+ .setColor (space , colorValue2 , pattern2 , true )
666
+ .setFontAndSize (PdfFontFactory .createFont (), 16 )
667
+ .showText ("bluish" )
668
+ .endText ()
669
+ .restoreState ();
670
+
671
+ canvas .release ();
672
+
673
+ document .close ();
674
+
675
+ Assert .assertNull (new CompareTool ().compareByContent (destFile , cmpFile , DESTINATION_FOLDER , "diff_" ));
676
+ }
677
+
631
678
private static int countSubstringOccurrences (String str , String findStr ) {
632
679
int lastIndex = 0 ;
633
680
int count = 0 ;
0 commit comments