Skip to content

Commit 1e3aa61

Browse files
yulian-gaponenkoLodrKumquat
authored andcommitted
Add new test for collapsing margins
DEVSIX-1858
1 parent 504117c commit 1e3aa61

File tree

2 files changed

+42
-46
lines changed

2 files changed

+42
-46
lines changed

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

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,18 @@ This file is part of the iText (R) project.
7474

7575
@Category(IntegrationTest.class)
7676
public class CollapsingMarginsTest extends ExtendedITextTest {
77-
public static final String sourceFolder = "./src/test/resources/com/itextpdf/layout/CollapsingMarginsTest/";
78-
public static final String destinationFolder = "./target/test/com/itextpdf/layout/CollapsingMarginsTest/";
77+
private static final String sourceFolder = "./src/test/resources/com/itextpdf/layout/CollapsingMarginsTest/";
78+
private static final String destinationFolder = "./target/test/com/itextpdf/layout/CollapsingMarginsTest/";
79+
80+
private final String textByron = "When a man hath no freedom to fight for at home,\n" +
81+
" Let him combat for that of his neighbours;\n" +
82+
"Let him think of the glories of Greece and of Rome,\n" +
83+
" And get knocked on the head for his labours.\n" +
84+
"\n" +
85+
"To do good to Mankind is the chivalrous plan,\n" +
86+
" And is always as nobly requited;\n" +
87+
"Then battle for Freedom wherever you can,\n" +
88+
" And, if not shot or hanged, you'll get knighted.";
7989

8090
@BeforeClass
8191
public static void beforeClass() {
@@ -142,17 +152,6 @@ public void collapsingMarginsTest02() throws IOException, InterruptedException {
142152

143153
drawPageBorders(pdfDocument, 3);
144154

145-
String textByron =
146-
"When a man hath no freedom to fight for at home,\n" +
147-
" Let him combat for that of his neighbours;\n" +
148-
"Let him think of the glories of Greece and of Rome,\n" +
149-
" And get knocked on the head for his labours.\n" +
150-
"\n" +
151-
"To do good to Mankind is the chivalrous plan,\n" +
152-
" And is always as nobly requited;\n" +
153-
"Then battle for Freedom wherever you can,\n" +
154-
" And, if not shot or hanged, you'll get knighted.";
155-
156155
Document doc = new Document(pdfDocument);
157156
doc.setProperty(Property.COLLAPSING_MARGINS, true);
158157

@@ -197,17 +196,6 @@ public void collapsingMarginsTest03() throws IOException, InterruptedException {
197196

198197
drawPageBorders(pdfDocument, 3);
199198

200-
String textByron =
201-
"When a man hath no freedom to fight for at home,\n" +
202-
" Let him combat for that of his neighbours;\n" +
203-
"Let him think of the glories of Greece and of Rome,\n" +
204-
" And get knocked on the head for his labours.\n" +
205-
"\n" +
206-
"To do good to Mankind is the chivalrous plan,\n" +
207-
" And is always as nobly requited;\n" +
208-
"Then battle for Freedom wherever you can,\n" +
209-
" And, if not shot or hanged, you'll get knighted.";
210-
211199
Document doc = new Document(pdfDocument);
212200
doc.setProperty(Property.COLLAPSING_MARGINS, true);
213201

@@ -249,17 +237,6 @@ public void collapsingMarginsTest04() throws IOException, InterruptedException {
249237

250238
drawPageBorders(pdfDocument, 3);
251239

252-
String textByron =
253-
"When a man hath no freedom to fight for at home,\n" +
254-
" Let him combat for that of his neighbours;\n" +
255-
"Let him think of the glories of Greece and of Rome,\n" +
256-
" And get knocked on the head for his labours.\n" +
257-
"\n" +
258-
"To do good to Mankind is the chivalrous plan,\n" +
259-
" And is always as nobly requited;\n" +
260-
"Then battle for Freedom wherever you can,\n" +
261-
" And, if not shot or hanged, you'll get knighted.";
262-
263240
Document doc = new Document(pdfDocument);
264241
doc.setProperty(Property.COLLAPSING_MARGINS, true);
265242

@@ -306,17 +283,6 @@ public void collapsingMarginsTest05() throws IOException, InterruptedException {
306283

307284
drawPageBorders(pdfDocument, 2);
308285

309-
String textByron =
310-
"When a man hath no freedom to fight for at home,\n" +
311-
" Let him combat for that of his neighbours;\n" +
312-
"Let him think of the glories of Greece and of Rome,\n" +
313-
" And get knocked on the head for his labours.\n" +
314-
"\n" +
315-
"To do good to Mankind is the chivalrous plan,\n" +
316-
" And is always as nobly requited;\n" +
317-
"Then battle for Freedom wherever you can,\n" +
318-
" And, if not shot or hanged, you'll get knighted.";
319-
320286
Document doc = new Document(pdfDocument);
321287
doc.setProperty(Property.COLLAPSING_MARGINS, true);
322288

@@ -338,6 +304,36 @@ public void collapsingMarginsTest05() throws IOException, InterruptedException {
338304
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
339305
}
340306

307+
@Test
308+
public void elementCollapsingMarginsTest01() throws IOException, InterruptedException {
309+
String outFileName = destinationFolder + "elementCollapsingMarginsTest01.pdf";
310+
String cmpFileName = sourceFolder + "cmp_elementCollapsingMarginsTest01.pdf";
311+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
312+
313+
drawPageBorders(pdfDocument, 1);
314+
315+
Document doc = new Document(pdfDocument);
316+
317+
Paragraph markerText = new Paragraph("Margin between this paragraph and next block is expected to be 170pt.")
318+
.setBackgroundColor(new DeviceRgb(65, 151, 29)); // greenish
319+
320+
Div div = new Div();
321+
Paragraph p = new Paragraph(textByron);
322+
div.add(p).setBackgroundColor(new DeviceRgb(209,247,29)); // yellowish
323+
div.setProperty(Property.COLLAPSING_MARGINS, true);
324+
325+
markerText.setMarginBottom(20);
326+
p.setMarginTop(50);
327+
div.setMarginTop(150);
328+
329+
doc.add(markerText);
330+
doc.add(div);
331+
332+
doc.close();
333+
334+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
335+
}
336+
341337
private void drawPageBorders(PdfDocument pdfDocument, int pageNum) {
342338
for (int i = 1; i <= pageNum; ++i) {
343339
while (pdfDocument.getNumberOfPages() < i) {

0 commit comments

Comments
 (0)