@@ -29,6 +29,7 @@ This file is part of the iText (R) project.
29
29
import com .itextpdf .kernel .pdf .PdfWriter ;
30
30
import com .itextpdf .kernel .utils .CompareTool ;
31
31
import com .itextpdf .layout .borders .SolidBorder ;
32
+ import com .itextpdf .layout .element .AreaBreak ;
32
33
import com .itextpdf .layout .element .Div ;
33
34
import com .itextpdf .layout .element .FlexContainer ;
34
35
import com .itextpdf .layout .element .IElement ;
@@ -40,6 +41,7 @@ This file is part of the iText (R) project.
40
41
import com .itextpdf .layout .property .AlignmentPropertyValue ;
41
42
import com .itextpdf .layout .property .JustifyContent ;
42
43
import com .itextpdf .layout .property .ListNumberingType ;
44
+ import com .itextpdf .layout .property .OverflowPropertyValue ;
43
45
import com .itextpdf .layout .property .Property ;
44
46
import com .itextpdf .layout .property .UnitValue ;
45
47
import com .itextpdf .test .ExtendedITextTest ;
@@ -77,7 +79,7 @@ public FlexContainerTest(Object alignItemsValue, Object justifyContentValue, Obj
77
79
this .testNumber = (Integer ) testNumber ;
78
80
}
79
81
80
- @ Parameterized .Parameters (name = "{index}: align-items: {1 }; justify-content: {2 }" )
82
+ @ Parameterized .Parameters (name = "{index}: align-items: {0 }; justify-content: {1 }" )
81
83
public static Iterable <Object []> alignItemsAndJustifyContentProperties () {
82
84
return Arrays .asList (new Object [][]{
83
85
{AlignmentPropertyValue .FLEX_START , JustifyContent .FLEX_START , 1 },
@@ -792,8 +794,110 @@ public void flexContainerRotationAngleTest() throws IOException, InterruptedExce
792
794
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
793
795
}
794
796
795
- private Div createFlexContainer () {
796
- Div flexContainer = new FlexContainer ();
797
+ @ Test
798
+ // TODO DEVSIX-5174 content should overflow bottom
799
+ public void respectFlexContainersHeightTest () throws IOException , InterruptedException {
800
+ String outFileName = destinationFolder + "respectFlexContainersHeightTest" + testNumber + ".pdf" ;
801
+ String cmpFileName = sourceFolder + "cmp_respectFlexContainersHeightTest" + testNumber + ".pdf" ;
802
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFileName ));
803
+
804
+ Document document = new Document (pdfDocument );
805
+ Style containerStyle = new Style ()
806
+ .setWidth (60 )
807
+ .setHeight (50 );
808
+
809
+ Div flexContainer = getFlexContainer (null , containerStyle );
810
+ Div flexItem = new Div ()
811
+ .setBackgroundColor (ColorConstants .BLUE )
812
+ .add (new Paragraph ("h" ))
813
+ .add (new Paragraph ("e" ))
814
+ .add (new Paragraph ("l" ))
815
+ .add (new Paragraph ("l" ))
816
+ .add (new Paragraph ("o" ))
817
+ .add (new Paragraph ("w" ))
818
+ .add (new Paragraph ("o" ))
819
+ .add (new Paragraph ("r" ))
820
+ .add (new Paragraph ("l" ))
821
+ .add (new Paragraph ("d" ));
822
+ flexContainer .add (flexItem );
823
+ flexContainer .add (new Div ().setBackgroundColor (ColorConstants .YELLOW ).setWidth (10 ).setHeight (200 ));
824
+
825
+ document .add (flexContainer );
826
+
827
+ document .close ();
828
+
829
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
830
+ }
831
+
832
+ @ Test
833
+ public void respectFlexContainersWidthTest () throws IOException , InterruptedException {
834
+ String outFileName = destinationFolder + "respectFlexContainersWidthTest" + testNumber + ".pdf" ;
835
+ String cmpFileName = sourceFolder + "cmp_respectFlexContainersWidthTest" + testNumber + ".pdf" ;
836
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFileName ));
837
+
838
+ Document document = new Document (pdfDocument );
839
+
840
+ // default (overflow fit)
841
+ OverflowPropertyValue overflowX = null ;
842
+ Style containerStyle = new Style ()
843
+ .setWidth (60 )
844
+ .setHeight (200 );
845
+
846
+ Style itemStyle = new Style ()
847
+ .setWidth (60f )
848
+ .setHeight (100f );
849
+
850
+ Div flexContainer = getFlexContainer (overflowX , containerStyle );
851
+ flexContainer
852
+ .add (getFlexItem (overflowX , itemStyle ))
853
+ .add (getFlexItem (overflowX , itemStyle ));
854
+ document .add (flexContainer );
855
+
856
+ document .add (new AreaBreak ());
857
+
858
+ // default (overflow visible)
859
+ overflowX = OverflowPropertyValue .VISIBLE ;
860
+ flexContainer = getFlexContainer (overflowX , containerStyle );
861
+ flexContainer
862
+ .add (getFlexItem (overflowX , itemStyle ))
863
+ .add (getFlexItem (overflowX , itemStyle ));
864
+ document .add (flexContainer );
865
+
866
+ document .close ();
867
+
868
+ Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
869
+ }
870
+
871
+ private Div getFlexContainer (OverflowPropertyValue overflowX , Style style ) {
872
+ FlexContainer flexContainer = createFlexContainer ();
873
+ flexContainer
874
+ .setBackgroundColor (ColorConstants .GREEN )
875
+ .setBorderRight (new SolidBorder (60 ));
876
+ if (null != style ) {
877
+ flexContainer .addStyle (style );
878
+ }
879
+ if (null != overflowX ) {
880
+ flexContainer .setProperty (Property .OVERFLOW_X , overflowX );
881
+ }
882
+ return flexContainer ;
883
+ }
884
+
885
+ private static Div getFlexItem (OverflowPropertyValue overflowX , Style style ) {
886
+ Div flexItem = new Div ();
887
+ flexItem .setProperty (Property .FLEX_GROW , 0f );
888
+ flexItem .setProperty (Property .FLEX_SHRINK , 0f );
889
+ if (null != style ) {
890
+ flexItem .addStyle (style );
891
+ }
892
+ flexItem .setBackgroundColor (ColorConstants .BLUE );
893
+ if (null != overflowX ) {
894
+ flexItem .setProperty (Property .OVERFLOW_X , overflowX );
895
+ }
896
+ return flexItem ;
897
+ }
898
+
899
+ private FlexContainer createFlexContainer () {
900
+ FlexContainer flexContainer = new FlexContainer ();
797
901
flexContainer .setProperty (Property .ALIGN_ITEMS , alignItemsValue );
798
902
flexContainer .setProperty (Property .JUSTIFY_CONTENT , justifyContentValue );
799
903
return flexContainer ;
0 commit comments