Skip to content

Commit 8f65d46

Browse files
Kate IvanovaiText-CI
authored andcommitted
Add KeepTogetherTest#keepTogetherInDivWithKidsFloatTest
DEVSIX-4814
1 parent eca659a commit 8f65d46

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

layout/src/test/java/com/itextpdf/layout/KeepTogetherTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This file is part of the iText (R) project.
4545

4646
import com.itextpdf.io.LogMessageConstant;
4747
import com.itextpdf.io.font.constants.StandardFonts;
48+
import com.itextpdf.kernel.colors.Color;
4849
import com.itextpdf.kernel.colors.ColorConstants;
4950
import com.itextpdf.kernel.font.PdfFontFactory;
5051
import com.itextpdf.kernel.geom.PageSize;
@@ -97,6 +98,7 @@ public class KeepTogetherTest extends ExtendedITextTest {
9798
private static final String MEDIUM_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr"
9899
+ " sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua."
99100
+ " At vero eos et accusam et justo duo dolores et ea rebum.\n ";
101+
private static final String SMALL_TEXT = "Short text";
100102

101103

102104
@BeforeClass
@@ -1126,6 +1128,43 @@ public void contentOverlappingDivKeepTogetherInRectTest() throws IOException, In
11261128
Assert.assertNull(new CompareTool().compareByContent(outFile, cmpFileName, destinationFolder));
11271129
}
11281130

1131+
@Test
1132+
//TODO: DEVSIX-4720 (invalid positioning of child element)
1133+
public void keepTogetherInDivWithKidsFloatTest() throws IOException, InterruptedException {
1134+
String filename = "keepTogetherInDivWithKidsFloat.pdf";
1135+
String outFile = destinationFolder + filename;
1136+
String cmpFileName = sourceFolder + "cmp_" + filename;
1137+
1138+
try (Document doc = new Document(new PdfDocument(new PdfWriter(outFile)))) {
1139+
doc.getPdfDocument().addNewPage(PageSize.A5.rotate());
1140+
1141+
Div main = new Div().setKeepTogether(true);
1142+
main.setBackgroundColor(ColorConstants.LIGHT_GRAY);
1143+
1144+
Div child1 = createChildDivWithText(main, SMALL_TEXT);
1145+
child1
1146+
.setBackgroundColor(ColorConstants.YELLOW)
1147+
.setWidth(UnitValue.createPercentValue(30))
1148+
.setProperty(Property.FLOAT, FloatPropertyValue.LEFT);
1149+
1150+
Div child2 = createChildDivWithText(main, BIG_TEXT);
1151+
child2
1152+
.setBackgroundColor(ColorConstants.GREEN)
1153+
.setWidth(UnitValue.createPercentValue(70))
1154+
.setProperty(Property.FLOAT, FloatPropertyValue.LEFT);
1155+
1156+
Div child3 = createChildDivWithText(main, "Test");
1157+
child3.setBackgroundColor(ColorConstants.ORANGE);
1158+
1159+
Div child4 = createChildDivWithText(main, MEDIUM_TEXT);
1160+
child4.setBackgroundColor(ColorConstants.ORANGE);
1161+
1162+
doc.add(main);
1163+
}
1164+
1165+
Assert.assertNull(new CompareTool().compareByContent(outFile, cmpFileName, destinationFolder));
1166+
}
1167+
11291168
private Div createChildDivWithText(Div parent, String text) {
11301169
Div child = new Div();
11311170
if (text != null) {

0 commit comments

Comments
 (0)