@@ -39,6 +39,7 @@ This file is part of the iText (R) project.
39
39
import com .itextpdf .layout .properties .Property ;
40
40
import com .itextpdf .layout .properties .UnitValue ;
41
41
import com .itextpdf .test .ExtendedITextTest ;
42
+ import com .itextpdf .test .LogLevelConstants ;
42
43
import com .itextpdf .test .annotations .LogMessage ;
43
44
import com .itextpdf .test .annotations .LogMessages ;
44
45
import com .itextpdf .test .annotations .type .IntegrationTest ;
@@ -366,6 +367,104 @@ public void continuousColumContainerMultipleElementsBorder() throws IOException,
366
367
});
367
368
}
368
369
370
+ @ Test
371
+ @ LogMessages (messages = {
372
+ @ LogMessage (messageTemplate = LayoutLogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , logLevel = LogLevelConstants .WARN )
373
+ })
374
+ public void multicolElementWithKeepTogetherTest () throws IOException , InterruptedException {
375
+ executeTest ("multicolElementWithKeepTogether" , new MulticolContainer (), ctx -> {
376
+ ctx .setProperty (Property .COLUMN_COUNT , 3 );
377
+ ctx .setBackgroundColor (DEFAULT_BACKGROUND_COLOR );
378
+ Div pseudoContainer = new Div ();
379
+ for (int i = 0 ; i < 30 ; i ++) {
380
+ pseudoContainer .add (new Paragraph ("" + i ));
381
+ }
382
+ ctx .setProperty (Property .KEEP_TOGETHER , true );
383
+ ctx .add (pseudoContainer );
384
+ });
385
+ }
386
+
387
+ @ Test
388
+ @ LogMessages (messages = {
389
+ @ LogMessage (messageTemplate = LayoutLogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA , logLevel = LogLevelConstants .WARN )
390
+ })
391
+ public void allChildrenOfMulticolElementWithKeepTogetherTest () throws IOException , InterruptedException {
392
+ executeTest ("allChildrenOfMulticolElementWithKeepTogether" , new MulticolContainer (), ctx -> {
393
+ ctx .setProperty (Property .COLUMN_COUNT , 3 );
394
+ ctx .setBackgroundColor (DEFAULT_BACKGROUND_COLOR );
395
+ Div pseudoContainer = new Div ();
396
+ for (int i = 0 ; i < 30 ; i ++) {
397
+ pseudoContainer .add (new Paragraph ("" + i ));
398
+ }
399
+ pseudoContainer .setProperty (Property .KEEP_TOGETHER , true );
400
+ ctx .add (pseudoContainer );
401
+ });
402
+ }
403
+
404
+ @ Test
405
+ public void childOfMulticolElementWithKeepTogetherTest () throws IOException , InterruptedException {
406
+ executeTest ("childOfMulticolElementWithKeepTogether" , new MulticolContainer (), ctx -> {
407
+ ctx .setProperty (Property .COLUMN_COUNT , 3 );
408
+ ctx .setBackgroundColor (DEFAULT_BACKGROUND_COLOR );
409
+ Div pseudoContainer = new Div ();
410
+ for (int i = 0 ; i < 7 ; i ++) {
411
+ pseudoContainer .add (new Paragraph ("" + i ));
412
+ }
413
+ Div temp = new Div ();
414
+ temp .add (new Paragraph ("7 keep" ));
415
+ temp .add (new Paragraph ("8 keep" ));
416
+ temp .add (new Paragraph ("9 keep" ));
417
+ temp .add (new Paragraph ("10 keep" ));
418
+ temp .add (new Paragraph ("11 keep" ));
419
+ temp .setProperty (Property .KEEP_TOGETHER , true );
420
+ pseudoContainer .add (temp );
421
+
422
+ for (int i = 12 ; i < 30 ; i ++) {
423
+ pseudoContainer .add (new Paragraph ("" + i ));
424
+ }
425
+ ctx .add (pseudoContainer );
426
+ });
427
+ }
428
+
429
+ @ Test
430
+ public void childrenOfMulticolElementWithKeepTogetherTest () throws IOException , InterruptedException {
431
+ executeTest ("childrenOfMulticolElementWithKeepTogether" , new MulticolContainer (), ctx -> {
432
+ ctx .setProperty (Property .COLUMN_COUNT , 3 );
433
+ ctx .setBackgroundColor (DEFAULT_BACKGROUND_COLOR );
434
+ Div pseudoContainer = new Div ();
435
+ for (int i = 0 ; i < 7 ; i ++) {
436
+ pseudoContainer .add (new Paragraph ("" + i ));
437
+ }
438
+ Div temp = new Div ();
439
+ temp .add (new Paragraph ("7 keep" ));
440
+ temp .add (new Paragraph ("8 keep" ));
441
+ temp .add (new Paragraph ("9 keep" ));
442
+ temp .add (new Paragraph ("10 keep" ));
443
+ temp .add (new Paragraph ("11 keep" ));
444
+ temp .setProperty (Property .KEEP_TOGETHER , Boolean .TRUE );
445
+ pseudoContainer .add (temp );
446
+
447
+ for (int i = 12 ; i < 19 ; i ++) {
448
+ pseudoContainer .add (new Paragraph ("" + i ));
449
+ }
450
+ temp = new Div ();
451
+ temp .add (new Paragraph ("19 keep" ));
452
+ temp .add (new Paragraph ("20 keep" ));
453
+ temp .add (new Paragraph ("21 keep" ));
454
+ temp .add (new Paragraph ("22 keep" ));
455
+ temp .add (new Paragraph ("23 keep" ));
456
+ temp .add (new Paragraph ("24 keep" ));
457
+ temp .add (new Paragraph ("25 keep" ));
458
+ temp .setProperty (Property .KEEP_TOGETHER , Boolean .TRUE );
459
+ pseudoContainer .add (temp );
460
+
461
+ for (int i = 26 ; i < 30 ; i ++) {
462
+ pseudoContainer .add (new Paragraph ("" + i ));
463
+ }
464
+ ctx .add (pseudoContainer );
465
+ });
466
+ }
467
+
369
468
@ Test
370
469
public void singleParagraphMultiPageTest () throws IOException , InterruptedException {
371
470
String outFileName = DESTINATION_FOLDER + "singleParagraphMultiPageTest.pdf" ;
@@ -551,7 +650,7 @@ public void overflowingDivWithParagraphMultipageTest() throws IOException, Inter
551
650
Div columnDiv = new Div ();
552
651
columnDiv .setProperty (Property .BORDER , new SolidBorder (1 ));
553
652
columnDiv .setProperty (Property .BACKGROUND , new Background (ColorConstants .BLUE ));
554
- columnDiv .setProperty (Property .KEEP_TOGETHER , true );
653
+ columnDiv .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
555
654
columnDiv .setProperty (Property .WIDTH , UnitValue .createPointValue (50 ));
556
655
columnDiv .setProperty (Property .HEIGHT , UnitValue .createPointValue (150 ));
557
656
@@ -582,7 +681,7 @@ public void marginCantFitCurrentPageTest() throws IOException, InterruptedExcept
582
681
Div columnDiv = new Div ();
583
682
columnDiv .setProperty (Property .BORDER , new SolidBorder (1 ));
584
683
columnDiv .setProperty (Property .BACKGROUND , new Background (ColorConstants .BLUE ));
585
- columnDiv .setProperty (Property .KEEP_TOGETHER , true );
684
+ columnDiv .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
586
685
columnDiv .setProperty (Property .MARGIN_BOTTOM , UnitValue .createPointValue (40 ));
587
686
columnDiv .setProperty (Property .WIDTH , UnitValue .createPointValue (60 ));
588
687
columnDiv .setProperty (Property .HEIGHT , UnitValue .createPointValue (60 ));
@@ -614,7 +713,7 @@ public void paddingCantFitCurrentPageTest() throws IOException, InterruptedExcep
614
713
Div columnDiv = new Div ();
615
714
columnDiv .setProperty (Property .BORDER , new SolidBorder (1 ));
616
715
columnDiv .setProperty (Property .BACKGROUND , new Background (ColorConstants .BLUE ));
617
- columnDiv .setProperty (Property .KEEP_TOGETHER , true );
716
+ columnDiv .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
618
717
columnDiv .setProperty (Property .PADDING_BOTTOM , UnitValue .createPointValue (40 ));
619
718
columnDiv .setProperty (Property .WIDTH , UnitValue .createPointValue (60 ));
620
719
columnDiv .setProperty (Property .HEIGHT , UnitValue .createPointValue (60 ));
@@ -649,7 +748,7 @@ public void keepTogetherBlockingLayoutTest() throws IOException, InterruptedExce
649
748
"id est laborum." );
650
749
paragraph .setBorder (new SolidBorder (2 ));
651
750
paragraph .setFontSize (20 );
652
- paragraph .setProperty (Property .KEEP_TOGETHER , true );
751
+ paragraph .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
653
752
654
753
columnContainer .setBorder (new SolidBorder (ColorConstants .RED , 3 ));
655
754
Div div = new Div ();
@@ -661,14 +760,13 @@ public void keepTogetherBlockingLayoutTest() throws IOException, InterruptedExce
661
760
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , DESTINATION_FOLDER , "diff" ));
662
761
}
663
762
664
- private < T extends IBlockElement > void executeTest (String testName , T container , Consumer <T > executor )
763
+ private void executeTest (String testName , MulticolContainer container , Consumer <MulticolContainer > executor )
665
764
throws IOException , InterruptedException {
666
765
String filename = DESTINATION_FOLDER + testName + ".pdf" ;
667
766
String cmpName = SOURCE_FOLDER + "cmp_" + testName + ".pdf" ;
668
767
try (PdfDocument pdfDoc = new PdfDocument (new com .itextpdf .kernel .pdf .PdfWriter (filename ))) {
669
768
Document doc = new Document (pdfDoc );
670
769
671
- container .setProperty (Property .TREAT_AS_CONTINUOUS_CONTAINER , true );
672
770
executor .accept (container );
673
771
674
772
doc .add (new Paragraph ("ELEMENT ABOVE" ).setBackgroundColor (ColorConstants .YELLOW ));
0 commit comments