@@ -22,27 +22,43 @@ This file is part of the iText (R) project.
2222 */
2323package com .itextpdf .layout .renderer ;
2424
25+ import com .itextpdf .io .image .ImageDataFactory ;
2526import com .itextpdf .io .logs .IoLogMessageConstant ;
2627import com .itextpdf .io .source .ByteArrayOutputStream ;
28+ import com .itextpdf .kernel .colors .ColorConstants ;
2729import com .itextpdf .kernel .geom .Rectangle ;
2830import com .itextpdf .kernel .pdf .PdfDocument ;
2931import com .itextpdf .kernel .pdf .PdfWriter ;
32+ import com .itextpdf .kernel .utils .CompareTool ;
3033import com .itextpdf .layout .Document ;
34+ import com .itextpdf .layout .borders .SolidBorder ;
3135import com .itextpdf .layout .element .Cell ;
36+ import com .itextpdf .layout .element .Image ;
37+ import com .itextpdf .layout .element .Paragraph ;
3238import com .itextpdf .layout .element .Table ;
3339import com .itextpdf .layout .minmaxwidth .MinMaxWidth ;
3440import com .itextpdf .layout .properties .Property ;
3541import com .itextpdf .layout .properties .UnitValue ;
3642import com .itextpdf .test .ExtendedITextTest ;
43+ import com .itextpdf .test .TestUtil ;
3744import com .itextpdf .test .annotations .LogMessage ;
3845import com .itextpdf .test .annotations .LogMessages ;
3946
47+ import java .io .IOException ;
4048import org .junit .jupiter .api .Assertions ;
41- import org .junit .jupiter .api .Test ;
49+ import org .junit .jupiter .api .BeforeAll ;
4250import org .junit .jupiter .api .Tag ;
51+ import org .junit .jupiter .api .Test ;
4352
4453@ Tag ("IntegrationTest" )
4554public class TableRendererTest extends ExtendedITextTest {
55+ private static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/layout/TableRendererTest/" ;
56+ private static final String DESTINATION_FOLDER = TestUtil .getOutputPath () + "/layout/TableRendererTest/" ;
57+
58+ @ BeforeAll
59+ public static void beforeClass () {
60+ createDestinationFolder (DESTINATION_FOLDER );
61+ }
4662
4763 @ Test
4864 @ LogMessages (messages = {
@@ -96,4 +112,43 @@ public void testIsOriginalNonSplitRenderer() {
96112
97113 Assertions .assertFalse (grandChildren [0 ].isOriginalNonSplitRenderer );
98114 }
115+
116+ @ Test
117+ @ LogMessages (messages = {
118+ @ LogMessage (messageTemplate = IoLogMessageConstant .TABLE_WIDTH_IS_MORE_THAN_EXPECTED_DUE_TO_MIN_WIDTH ),
119+ })
120+ public void nestedTableWithSpecifiedWidthTest () throws IOException , InterruptedException {
121+ String outFileName = DESTINATION_FOLDER + "nestedTableWithSpecifiedWidth.pdf" ;
122+ String cmpFileName = SOURCE_FOLDER + "cmp_nestedTableWithSpecifiedWidth.pdf" ;
123+
124+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (outFileName ));
125+ Document doc = new Document (pdfDoc );
126+
127+ Table table = new Table (2 );
128+
129+ Cell cell1 = new Cell (1 , 1 );
130+ cell1 .setBorder (new SolidBorder (ColorConstants .GRAY , 1.5f ));
131+
132+ Table nestedTable = new Table (1 );
133+ nestedTable .setWidth (422.25f );
134+ nestedTable .setHeight (52.5f );
135+ Paragraph paragraph = new Paragraph ("Hello" );
136+ paragraph .setBorder (new SolidBorder (ColorConstants .GREEN , 1.5f ));
137+ nestedTable .addCell (paragraph );
138+ cell1 .add (nestedTable );
139+ table .addCell (cell1 );
140+
141+ Cell cell2 = new Cell (2 , 1 );
142+ cell2 .setBorder (new SolidBorder (ColorConstants .YELLOW , 1.5f ));
143+ Image image = new Image (ImageDataFactory .create (SOURCE_FOLDER + "itis.jpg" ));
144+ image .setWidth (406.5f );
145+ image .setHeight (7.5f );
146+ cell2 .add (image );
147+ table .addCell (cell2 );
148+
149+ doc .add (table );
150+ doc .close ();
151+
152+ Assertions .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , DESTINATION_FOLDER ));
153+ }
99154}
0 commit comments