@@ -43,7 +43,9 @@ This file is part of the iText (R) project.
43
43
package com .itextpdf .layout ;
44
44
45
45
import com .itextpdf .io .LogMessageConstant ;
46
+ import com .itextpdf .io .util .MessageFormatUtil ;
46
47
import com .itextpdf .kernel .color .ColorConstants ;
48
+ import com .itextpdf .kernel .color .DeviceGray ;
47
49
import com .itextpdf .kernel .geom .PageSize ;
48
50
import com .itextpdf .kernel .pdf .PdfDocument ;
49
51
import com .itextpdf .kernel .pdf .PdfWriter ;
@@ -53,17 +55,18 @@ This file is part of the iText (R) project.
53
55
import com .itextpdf .layout .element .Cell ;
54
56
import com .itextpdf .layout .element .Paragraph ;
55
57
import com .itextpdf .layout .element .Table ;
58
+ import com .itextpdf .layout .property .UnitValue ;
56
59
import com .itextpdf .test .ExtendedITextTest ;
57
60
import com .itextpdf .test .annotations .LogMessage ;
58
61
import com .itextpdf .test .annotations .LogMessages ;
59
62
import com .itextpdf .test .annotations .type .IntegrationTest ;
60
63
import org .junit .Assert ;
61
64
import org .junit .BeforeClass ;
65
+ import org .junit .Ignore ;
62
66
import org .junit .Test ;
63
67
import org .junit .experimental .categories .Category ;
64
68
65
69
import java .io .IOException ;
66
- import com .itextpdf .io .util .MessageFormatUtil ;
67
70
68
71
@ Category (IntegrationTest .class )
69
72
public class LargeElementTest extends ExtendedITextTest {
@@ -217,7 +220,7 @@ public void largeTableWithHeaderFooterTest01C() throws IOException, InterruptedE
217
220
cell = new Cell (1 , 5 ).add (new Paragraph ("Continue on next page" )).setHeight (30 ).setBorderTop (new SolidBorder (ColorConstants .MAGENTA , 20 ));
218
221
table .addFooterCell (cell );
219
222
for (int i = 0 ; i < 50 ; i ++) {
220
- table .addCell (new Cell ().setBorderLeft (new SolidBorder (ColorConstants .BLUE , 0.5f )).setBorderRight (new SolidBorder (ColorConstants .BLUE , 0.5f )).setHeight (30 ).setBorderBottom (new SolidBorder (ColorConstants .BLUE , 2 * i + 1 > 50 ? 50 : 2 * i + 1 )).setBorderTop (new SolidBorder (ColorConstants .GREEN , (50 - 2 * i + 1 >= 0 ) ? 50 - 2 * i + 1 : 0 )).add (new Paragraph (String .valueOf (i + 1 ))));
223
+ table .addCell (new Cell ().setBorderLeft (new SolidBorder (ColorConstants .BLUE , 0.5f )).setBorderRight (new SolidBorder (ColorConstants .BLUE , 0.5f )).setHeight (30 ).setBorderBottom (new SolidBorder (ColorConstants .BLUE , 2 * i + 1 > 50 ? 50 : 2 * i + 1 )).setBorderTop (new SolidBorder (ColorConstants .GREEN , (50 - 2 * i + 1 >= 0 ) ? 50 - 2 * i + 1 : 0 )).add (new Paragraph (String .valueOf (i + 1 ))));
221
224
table .flush ();
222
225
}
223
226
table .complete ();
@@ -242,7 +245,7 @@ public void largeTableWithHeaderFooterTest01D() throws IOException, InterruptedE
242
245
cell = new Cell (1 , 5 ).add (new Paragraph ("Continue on next page" )).setHeight (30 ).setBorderTop (new SolidBorder (ColorConstants .MAGENTA , 20 ));
243
246
table .addFooterCell (cell );
244
247
for (int i = 0 ; i < 50 ; i ++) {
245
- table .addCell (new Cell ().setBorderLeft (new SolidBorder (ColorConstants .BLUE , 0.5f )).setBorderRight (new SolidBorder (ColorConstants .BLUE , 0.5f )).setHeight (30 ).setBorderBottom (new SolidBorder (ColorConstants .BLUE , 2 * i + 1 > 50 ? 50 : 2 * i + 1 )).setBorderTop (new SolidBorder (ColorConstants .GREEN , (50 - 2 * i + 1 >= 0 ) ? 50 - 2 * i + 1 : 0 )).add (new Paragraph (String .valueOf (i + 1 ))));
248
+ table .addCell (new Cell ().setBorderLeft (new SolidBorder (ColorConstants .BLUE , 0.5f )).setBorderRight (new SolidBorder (ColorConstants .BLUE , 0.5f )).setHeight (30 ).setBorderBottom (new SolidBorder (ColorConstants .BLUE , 2 * i + 1 > 50 ? 50 : 2 * i + 1 )).setBorderTop (new SolidBorder (ColorConstants .GREEN , (50 - 2 * i + 1 >= 0 ) ? 50 - 2 * i + 1 : 0 )).add (new Paragraph (String .valueOf (i + 1 ))));
246
249
table .flush ();
247
250
}
248
251
table .complete ();
@@ -386,6 +389,118 @@ public void largeTableWithHeaderFooterTest04() throws IOException, InterruptedEx
386
389
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , testName + "_diff" ));
387
390
}
388
391
392
+ @ Ignore ("DEVSIX-1646" )
393
+ @ Test
394
+ public void largeTableWithLayoutResultNothingTest01 () throws IOException , InterruptedException {
395
+ String testName = "largeTableWithLayoutResultNothingTest01.pdf" ;
396
+ String outFileName = destinationFolder + testName ;
397
+ String cmpFileName = sourceFolder + "cmp_" + testName ;
398
+
399
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFileName ));
400
+ Document doc = new Document (pdfDoc , PageSize .A1 .rotate ());
401
+
402
+ float [] colWidths = new float []{300 , 150 , 50 , 100 };
403
+
404
+ Table table = new Table (UnitValue .createPointArray (colWidths ), true );
405
+
406
+ int numOfColumns = colWidths .length - 1 ;
407
+ Cell [] cells = new Cell [numOfColumns ];
408
+
409
+ for (int i = 0 ; i < numOfColumns ; i ++) {
410
+ cells [i ] = new Cell (1 , 1 + i % 2 ).add ("Cell" + i );
411
+ cells [i ].setBorder (new SolidBorder (new DeviceGray (i / (float ) numOfColumns ), 10 ));
412
+ table .addCell (cells [i ]);
413
+ }
414
+ doc .add (table );
415
+
416
+ for (int i = 0 ; i < numOfColumns ; i ++) {
417
+ cells [i ].setBorder (new SolidBorder (new DeviceGray (i / (float ) numOfColumns ), 50 ));
418
+ table .addCell (cells [i ]);
419
+ }
420
+ table .flush ();
421
+
422
+ for (int i = 0 ; i < numOfColumns ; i ++) {
423
+ cells [i ].setBorder (new SolidBorder (new DeviceGray (i / (float ) numOfColumns ), 1 ));
424
+ table .addCell (cells [i ]);
425
+ }
426
+ table .flush ();
427
+
428
+ for (int i = 0 ; i < numOfColumns ; i ++) {
429
+ cells [i ].setBorder (new SolidBorder (new DeviceGray (i / (float ) numOfColumns ), 100 ));
430
+ table .addCell (cells [i ]);
431
+ }
432
+ table .flush ();
433
+
434
+ table .complete ();
435
+
436
+ doc .close ();
437
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , testName + "_diff" ));
438
+ }
439
+
440
+
441
+ @ Test
442
+ @ LogMessages (messages = {@ LogMessage (messageTemplate = LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , count = 1 )})
443
+ public void largeTableWithLayoutResultNothingTest02 () throws IOException , InterruptedException {
444
+ String testName = "largeTableWithLayoutResultNothingTest02.pdf" ;
445
+ String outFileName = destinationFolder + testName ;
446
+ String cmpFileName = sourceFolder + "cmp_" + testName ;
447
+
448
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFileName ));
449
+ Document doc = new Document (pdfDoc , PageSize .A4 .rotate ());
450
+
451
+ float [] colWidths = new float []{200 , 1 , 2 , 4 };
452
+
453
+ Table table = new Table (UnitValue .createPointArray (colWidths ), true );
454
+ doc .add (table );
455
+
456
+ Cell cell1 = new Cell ().add ("Cell1" );
457
+ Cell cell2 = new Cell ().add ("Cell2" );
458
+ Cell cell3 = new Cell ().add ("Cell3" );
459
+ Cell cell4 = new Cell ().add ("Cell4" );
460
+
461
+ table .addCell (cell1 );
462
+ table .addCell (cell2 );
463
+ table .addCell (cell3 );
464
+ table .addCell (cell4 );
465
+ table .flush ();
466
+
467
+ table .complete ();
468
+
469
+ doc .close ();
470
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , testName + "_diff" ));
471
+ }
472
+
473
+ @ Test
474
+ public void largeTableWithLayoutResultNothingTest03 () throws IOException , InterruptedException {
475
+ String testName = "largeTableWithLayoutResultNothingTest03.pdf" ;
476
+ String outFileName = destinationFolder + testName ;
477
+ String cmpFileName = sourceFolder + "cmp_" + testName ;
478
+
479
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFileName ));
480
+ Document doc = new Document (pdfDoc , PageSize .A4 .rotate ());
481
+
482
+ float [] colWidths = new float []{200 , -1 , 20 , 40 };
483
+
484
+ Table table = new Table (UnitValue .createPointArray (colWidths ), true );
485
+ doc .add (table );
486
+
487
+ Cell cell1 = new Cell ().add ("Cell1" );
488
+ Cell cell2 = new Cell ().add ("Cell2" );
489
+ Cell cell3 = new Cell ().add ("Cell3" );
490
+ Cell cell4 = new Cell ().add ("Cell4" );
491
+
492
+ table .addCell (cell1 );
493
+ table .addCell (cell2 );
494
+ table .addCell (cell3 );
495
+ table .addCell (cell4 );
496
+ table .flush ();
497
+
498
+ table .complete ();
499
+
500
+ doc .close ();
501
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , testName + "_diff" ));
502
+ }
503
+
389
504
@ Test
390
505
public void largeEmptyTableTest () throws IOException , InterruptedException {
391
506
String testName = "largeEmptyTableTest.pdf" ;
@@ -446,7 +561,7 @@ public void largeEmptyTableTest02() throws IOException, InterruptedException {
446
561
table .addHeaderCell (new Cell ().add (new Paragraph ("Header" + i )));
447
562
table .addFooterCell (new Cell ().add (new Paragraph ("Footer" + i )));
448
563
}
449
- table .addCell (new Cell ().add (new Paragraph ("Cell" )));
564
+ table .addCell (new Cell ().add (new Paragraph ("Cell" )));
450
565
table .complete ();
451
566
doc .add (new Table (1 ).setBorder (new SolidBorder (ColorConstants .ORANGE , 2 )).addCell ("Is my occupied area correct?" ));
452
567
doc .add (new AreaBreak ());
@@ -467,7 +582,7 @@ public void largeEmptyTableTest02() throws IOException, InterruptedException {
467
582
table .addHeaderCell (new Cell ().add (new Paragraph ("Header" + i )));
468
583
table .addFooterCell (new Cell ().add (new Paragraph ("Footer" + i )));
469
584
}
470
- table .addCell (new Cell ().add (new Paragraph ("Cell" )));
585
+ table .addCell (new Cell ().add (new Paragraph ("Cell" )));
471
586
table .complete ();
472
587
doc .add (new Table (1 ).setBorder (new SolidBorder (ColorConstants .ORANGE , 2 )).addCell ("Is my occupied area correct?" ));
473
588
0 commit comments