@@ -39,6 +39,7 @@ This file is part of the iText (R) project.
3939import com .itextpdf .layout .properties .Property ;
4040import com .itextpdf .layout .properties .UnitValue ;
4141import com .itextpdf .test .ExtendedITextTest ;
42+ import com .itextpdf .test .LogLevelConstants ;
4243import com .itextpdf .test .annotations .LogMessage ;
4344import com .itextpdf .test .annotations .LogMessages ;
4445import com .itextpdf .test .annotations .type .IntegrationTest ;
@@ -366,6 +367,104 @@ public void continuousColumContainerMultipleElementsBorder() throws IOException,
366367 });
367368 }
368369
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+
369468 @ Test
370469 public void singleParagraphMultiPageTest () throws IOException , InterruptedException {
371470 String outFileName = DESTINATION_FOLDER + "singleParagraphMultiPageTest.pdf" ;
@@ -551,7 +650,7 @@ public void overflowingDivWithParagraphMultipageTest() throws IOException, Inter
551650 Div columnDiv = new Div ();
552651 columnDiv .setProperty (Property .BORDER , new SolidBorder (1 ));
553652 columnDiv .setProperty (Property .BACKGROUND , new Background (ColorConstants .BLUE ));
554- columnDiv .setProperty (Property .KEEP_TOGETHER , true );
653+ columnDiv .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
555654 columnDiv .setProperty (Property .WIDTH , UnitValue .createPointValue (50 ));
556655 columnDiv .setProperty (Property .HEIGHT , UnitValue .createPointValue (150 ));
557656
@@ -582,7 +681,7 @@ public void marginCantFitCurrentPageTest() throws IOException, InterruptedExcept
582681 Div columnDiv = new Div ();
583682 columnDiv .setProperty (Property .BORDER , new SolidBorder (1 ));
584683 columnDiv .setProperty (Property .BACKGROUND , new Background (ColorConstants .BLUE ));
585- columnDiv .setProperty (Property .KEEP_TOGETHER , true );
684+ columnDiv .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
586685 columnDiv .setProperty (Property .MARGIN_BOTTOM , UnitValue .createPointValue (40 ));
587686 columnDiv .setProperty (Property .WIDTH , UnitValue .createPointValue (60 ));
588687 columnDiv .setProperty (Property .HEIGHT , UnitValue .createPointValue (60 ));
@@ -614,7 +713,7 @@ public void paddingCantFitCurrentPageTest() throws IOException, InterruptedExcep
614713 Div columnDiv = new Div ();
615714 columnDiv .setProperty (Property .BORDER , new SolidBorder (1 ));
616715 columnDiv .setProperty (Property .BACKGROUND , new Background (ColorConstants .BLUE ));
617- columnDiv .setProperty (Property .KEEP_TOGETHER , true );
716+ columnDiv .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
618717 columnDiv .setProperty (Property .PADDING_BOTTOM , UnitValue .createPointValue (40 ));
619718 columnDiv .setProperty (Property .WIDTH , UnitValue .createPointValue (60 ));
620719 columnDiv .setProperty (Property .HEIGHT , UnitValue .createPointValue (60 ));
@@ -649,7 +748,7 @@ public void keepTogetherBlockingLayoutTest() throws IOException, InterruptedExce
649748 "id est laborum." );
650749 paragraph .setBorder (new SolidBorder (2 ));
651750 paragraph .setFontSize (20 );
652- paragraph .setProperty (Property .KEEP_TOGETHER , true );
751+ paragraph .setProperty (Property .KEEP_TOGETHER , Boolean . TRUE );
653752
654753 columnContainer .setBorder (new SolidBorder (ColorConstants .RED , 3 ));
655754 Div div = new Div ();
@@ -661,14 +760,13 @@ public void keepTogetherBlockingLayoutTest() throws IOException, InterruptedExce
661760 Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , DESTINATION_FOLDER , "diff" ));
662761 }
663762
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 )
665764 throws IOException , InterruptedException {
666765 String filename = DESTINATION_FOLDER + testName + ".pdf" ;
667766 String cmpName = SOURCE_FOLDER + "cmp_" + testName + ".pdf" ;
668767 try (PdfDocument pdfDoc = new PdfDocument (new com .itextpdf .kernel .pdf .PdfWriter (filename ))) {
669768 Document doc = new Document (pdfDoc );
670769
671- container .setProperty (Property .TREAT_AS_CONTINUOUS_CONTAINER , true );
672770 executor .accept (container );
673771
674772 doc .add (new Paragraph ("ELEMENT ABOVE" ).setBackgroundColor (ColorConstants .YELLOW ));
0 commit comments