Skip to content

Commit 3e9c9d7

Browse files
ars18wrwiText-CI
authored andcommitted
Respect width when placing flex container
Flex items may overflow, but the container's width should be repsected DEVSIX-5098 Autoported commit. Original commit hash: [110246b00]
1 parent f605509 commit 3e9c9d7

17 files changed

+103
-13
lines changed

itext.tests/itext.layout.tests/itext/layout/FlexContainerTest.cs

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,78 @@ public virtual void FlexContainerRotationAngleTest() {
676676
, "diff"));
677677
}
678678

679-
private Div CreateFlexContainer() {
680-
Div flexContainer = new FlexContainer();
679+
[NUnit.Framework.Test]
680+
public virtual void RespectFlexContainersHeightTest() {
681+
// TODO DEVSIX-5174 content should overflow bottom
682+
String outFileName = destinationFolder + "respectFlexContainersHeightTest" + testNumber + ".pdf";
683+
String cmpFileName = sourceFolder + "cmp_respectFlexContainersHeightTest" + testNumber + ".pdf";
684+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
685+
Document document = new Document(pdfDocument);
686+
Style containerStyle = new Style().SetWidth(60).SetHeight(50);
687+
Div flexContainer = GetFlexContainer(null, containerStyle);
688+
Div flexItem = new Div().SetBackgroundColor(ColorConstants.BLUE).Add(new Paragraph("h")).Add(new Paragraph
689+
("e")).Add(new Paragraph("l")).Add(new Paragraph("l")).Add(new Paragraph("o")).Add(new Paragraph("w"))
690+
.Add(new Paragraph("o")).Add(new Paragraph("r")).Add(new Paragraph("l")).Add(new Paragraph("d"));
691+
flexContainer.Add(flexItem);
692+
flexContainer.Add(new Div().SetBackgroundColor(ColorConstants.YELLOW).SetWidth(10).SetHeight(200));
693+
document.Add(flexContainer);
694+
document.Close();
695+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
696+
, "diff"));
697+
}
698+
699+
[NUnit.Framework.Test]
700+
public virtual void RespectFlexContainersWidthTest() {
701+
String outFileName = destinationFolder + "respectFlexContainersWidthTest" + testNumber + ".pdf";
702+
String cmpFileName = sourceFolder + "cmp_respectFlexContainersWidthTest" + testNumber + ".pdf";
703+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
704+
Document document = new Document(pdfDocument);
705+
// default (overflow fit)
706+
OverflowPropertyValue? overflowX = null;
707+
Style containerStyle = new Style().SetWidth(60).SetHeight(200);
708+
Style itemStyle = new Style().SetWidth(60f).SetHeight(100f);
709+
Div flexContainer = GetFlexContainer(overflowX, containerStyle);
710+
flexContainer.Add(GetFlexItem(overflowX, itemStyle)).Add(GetFlexItem(overflowX, itemStyle));
711+
document.Add(flexContainer);
712+
document.Add(new AreaBreak());
713+
// default (overflow visible)
714+
overflowX = OverflowPropertyValue.VISIBLE;
715+
flexContainer = GetFlexContainer(overflowX, containerStyle);
716+
flexContainer.Add(GetFlexItem(overflowX, itemStyle)).Add(GetFlexItem(overflowX, itemStyle));
717+
document.Add(flexContainer);
718+
document.Close();
719+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
720+
, "diff"));
721+
}
722+
723+
private Div GetFlexContainer(OverflowPropertyValue? overflowX, Style style) {
724+
FlexContainer flexContainer = CreateFlexContainer();
725+
flexContainer.SetBackgroundColor(ColorConstants.GREEN).SetBorderRight(new SolidBorder(60));
726+
if (null != style) {
727+
flexContainer.AddStyle(style);
728+
}
729+
if (null != overflowX) {
730+
flexContainer.SetProperty(Property.OVERFLOW_X, overflowX);
731+
}
732+
return flexContainer;
733+
}
734+
735+
private static Div GetFlexItem(OverflowPropertyValue? overflowX, Style style) {
736+
Div flexItem = new Div();
737+
flexItem.SetProperty(Property.FLEX_GROW, 0f);
738+
flexItem.SetProperty(Property.FLEX_SHRINK, 0f);
739+
if (null != style) {
740+
flexItem.AddStyle(style);
741+
}
742+
flexItem.SetBackgroundColor(ColorConstants.BLUE);
743+
if (null != overflowX) {
744+
flexItem.SetProperty(Property.OVERFLOW_X, overflowX);
745+
}
746+
return flexItem;
747+
}
748+
749+
private FlexContainer CreateFlexContainer() {
750+
FlexContainer flexContainer = new FlexContainer();
681751
flexContainer.SetProperty(Property.ALIGN_ITEMS, alignItemsValue);
682752
flexContainer.SetProperty(Property.JUSTIFY_CONTENT, justifyContentValue);
683753
return flexContainer;

0 commit comments

Comments
 (0)