@@ -74,8 +74,18 @@ This file is part of the iText (R) project.
74
74
75
75
@ Category (IntegrationTest .class )
76
76
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." ;
79
89
80
90
@ BeforeClass
81
91
public static void beforeClass () {
@@ -142,17 +152,6 @@ public void collapsingMarginsTest02() throws IOException, InterruptedException {
142
152
143
153
drawPageBorders (pdfDocument , 3 );
144
154
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
-
156
155
Document doc = new Document (pdfDocument );
157
156
doc .setProperty (Property .COLLAPSING_MARGINS , true );
158
157
@@ -197,17 +196,6 @@ public void collapsingMarginsTest03() throws IOException, InterruptedException {
197
196
198
197
drawPageBorders (pdfDocument , 3 );
199
198
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
-
211
199
Document doc = new Document (pdfDocument );
212
200
doc .setProperty (Property .COLLAPSING_MARGINS , true );
213
201
@@ -249,17 +237,6 @@ public void collapsingMarginsTest04() throws IOException, InterruptedException {
249
237
250
238
drawPageBorders (pdfDocument , 3 );
251
239
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
-
263
240
Document doc = new Document (pdfDocument );
264
241
doc .setProperty (Property .COLLAPSING_MARGINS , true );
265
242
@@ -306,17 +283,6 @@ public void collapsingMarginsTest05() throws IOException, InterruptedException {
306
283
307
284
drawPageBorders (pdfDocument , 2 );
308
285
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
-
320
286
Document doc = new Document (pdfDocument );
321
287
doc .setProperty (Property .COLLAPSING_MARGINS , true );
322
288
@@ -338,6 +304,36 @@ public void collapsingMarginsTest05() throws IOException, InterruptedException {
338
304
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
339
305
}
340
306
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
+
341
337
private void drawPageBorders (PdfDocument pdfDocument , int pageNum ) {
342
338
for (int i = 1 ; i <= pageNum ; ++i ) {
343
339
while (pdfDocument .getNumberOfPages () < i ) {
0 commit comments