@@ -47,6 +47,7 @@ This file is part of the iText (R) project.
47
47
import com .itextpdf .io .util .UrlUtil ;
48
48
import com .itextpdf .kernel .colors .ColorConstants ;
49
49
import com .itextpdf .kernel .geom .PageSize ;
50
+ import com .itextpdf .kernel .geom .Rectangle ;
50
51
import com .itextpdf .kernel .pdf .PdfDocument ;
51
52
import com .itextpdf .kernel .pdf .PdfWriter ;
52
53
import com .itextpdf .kernel .pdf .xobject .PdfImageXObject ;
@@ -63,6 +64,10 @@ This file is part of the iText (R) project.
63
64
import com .itextpdf .layout .element .Paragraph ;
64
65
import com .itextpdf .layout .element .Table ;
65
66
import com .itextpdf .layout .element .Text ;
67
+ import com .itextpdf .layout .layout .LayoutArea ;
68
+ import com .itextpdf .layout .layout .LayoutContext ;
69
+ import com .itextpdf .layout .layout .LayoutResult ;
70
+ import com .itextpdf .layout .minmaxwidth .MinMaxWidth ;
66
71
import com .itextpdf .layout .property .BorderCollapsePropertyValue ;
67
72
import com .itextpdf .layout .property .CaptionSide ;
68
73
import com .itextpdf .layout .property .HorizontalAlignment ;
@@ -82,6 +87,7 @@ This file is part of the iText (R) project.
82
87
import org .junit .experimental .categories .Category ;
83
88
import org .junit .rules .ExpectedException ;
84
89
90
+ import java .io .ByteArrayOutputStream ;
85
91
import java .io .IOException ;
86
92
87
93
@ Category (IntegrationTest .class )
@@ -2432,6 +2438,59 @@ public void tableMinMaxWidthTest06() throws IOException, InterruptedException {
2432
2438
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , testName + "_diff" ));
2433
2439
}
2434
2440
2441
+ @ Test
2442
+ @ LogMessages (messages = {
2443
+ @ LogMessage (messageTemplate = LogMessageConstant .TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH )
2444
+ })
2445
+ public void splitTableMinMaxWidthTest01 () {
2446
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (new ByteArrayOutputStream ()));
2447
+ Document doc = new Document (pdfDoc );
2448
+
2449
+ Table table = new Table (2 );
2450
+ for (int i = 0 ; i < 26 ; i ++) {
2451
+ table .addCell (new Cell ().add (new Paragraph ("abba a" )));
2452
+ table .addCell (new Cell ().add (new Paragraph ("ab ab ab" )));
2453
+ }
2454
+
2455
+ // not enough to place even if min-width approach is used
2456
+ float areaWidth = 20 ;
2457
+
2458
+ LayoutResult result = table .createRendererSubTree ().setParent (doc .getRenderer ())
2459
+ .layout (new LayoutContext (new LayoutArea (1 , new Rectangle (areaWidth , 100 ))));
2460
+ TableRenderer overflowRenderer = (TableRenderer ) result .getOverflowRenderer ();
2461
+
2462
+ MinMaxWidth minMaxWidth = overflowRenderer .getMinMaxWidth ();
2463
+
2464
+ Assert .assertEquals (result .getOccupiedArea ().getBBox ().getWidth (), minMaxWidth .getMaxWidth (), 0.0001 );
2465
+ Assert .assertEquals (minMaxWidth .getMaxWidth (), minMaxWidth .getMinWidth (), 0.0001 );
2466
+
2467
+ // not enough to place using max-width approach, but more than required for min-width approach
2468
+ areaWidth = 70 ;
2469
+
2470
+ result = table .createRendererSubTree ().setParent (doc .getRenderer ())
2471
+ .layout (new LayoutContext (new LayoutArea (1 , new Rectangle (areaWidth , 100 ))));
2472
+ overflowRenderer = (TableRenderer ) result .getOverflowRenderer ();
2473
+
2474
+ minMaxWidth = overflowRenderer .getMinMaxWidth ();
2475
+
2476
+ Assert .assertEquals (result .getOccupiedArea ().getBBox ().getWidth (), minMaxWidth .getMaxWidth (), 0.0001 );
2477
+ Assert .assertEquals (minMaxWidth .getMaxWidth (), minMaxWidth .getMinWidth (), 0.0001 );
2478
+
2479
+
2480
+ // enough to place using max-width approach
2481
+ areaWidth = 400f ;
2482
+
2483
+ result = table .createRendererSubTree ().setParent (doc .getRenderer ())
2484
+ .layout (new LayoutContext (new LayoutArea (1 , new Rectangle (areaWidth , 100 ))));
2485
+ overflowRenderer = (TableRenderer ) result .getOverflowRenderer ();
2486
+
2487
+ minMaxWidth = overflowRenderer .getMinMaxWidth ();
2488
+
2489
+ Assert .assertEquals (result .getOccupiedArea ().getBBox ().getWidth (), minMaxWidth .getMaxWidth (), 0.0001 );
2490
+ Assert .assertEquals (minMaxWidth .getMaxWidth (), minMaxWidth .getMinWidth (), 0.0001 );
2491
+ }
2492
+
2493
+
2435
2494
@ Test
2436
2495
public void marginPaddingTest01 () throws IOException , InterruptedException {
2437
2496
String testName = "marginPaddingTest01.pdf" ;
0 commit comments