Skip to content

Commit 222c265

Browse files
committed
Add tests for flex base size determination algorithm
DEVSIX-8768
1 parent c2a8720 commit 222c265

File tree

75 files changed

+909
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+909
-16
lines changed

src/test/java/com/itextpdf/html2pdf/css/FloatTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ public void plainTextIndentAfterBlockAndFloatTest() throws IOException, Interrup
686686
}
687687

688688
@Test
689-
//TODO DEVSIX-5291 change cmp file
689+
// TODO DEVSIX-5291 floating elements are not included in the div
690690
public void floatElementInDivTest() throws IOException, InterruptedException {
691691
runTest("floatElementInDiv", "diff_floatElementInDiv_");
692692
}

src/test/java/com/itextpdf/html2pdf/css/FontFamilyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public void selectFontFromTTCTest() throws IOException, InterruptedException {
6666
String cmpPdfPath = SOURCE_FOLDER + "cmp_selectFontInGroup.pdf";
6767

6868
HtmlConverter.convertToPdf(new File(htmlPath), new File(pdfPath));
69-
//TODO DEVSIX-1104: Change cmp file after supporting ttc#id when selecting font from ttc
70-
//Currently it will look for a font file where #{id} is part of the font path.
69+
// TODO DEVSIX-1104: Change cmp file after supporting ttc#id when selecting font from ttc
70+
// Currently it will look for a font file where #{id} is part of the font path.
7171
Assertions.assertNull(new CompareTool().compareByContent(pdfPath, cmpPdfPath, DESTINATION_FOLDER, "diff_"));
7272
}
7373
}

src/test/java/com/itextpdf/html2pdf/css/LineHeightTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public void textAreaLineHeightShortTest() throws IOException, InterruptedExcepti
157157
}
158158

159159
@Test
160-
// TODO DEVSIX-2485 change cmp after fixing the ticket
160+
// TODO DEVSIX-2485 Html2Pdf inline context handling: support phrasing content in HTML+CSS way
161161
public void inlineElementLineHeightTest() throws IOException, InterruptedException {
162162
testLineHeight("inlineElementLineHeightTest");
163163
}

src/test/java/com/itextpdf/html2pdf/css/flex/DisplayFlexTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public void flexBasisAuto() throws IOException, InterruptedException {
362362
}
363363

364364
@Test
365-
// TODO DEVSIX-5091 change cmp file when working on the thicket
365+
// TODO DEVSIX-5091 Support flex-basis: content
366366
public void flexBasisContentMaxWidth() throws IOException, InterruptedException {
367367
convertToPdfAndCompare("flexBasisContentMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
368368
}
@@ -721,6 +721,16 @@ public void flexWithPageBreakInsideAvoidAndPageSplit2Test() throws IOException,
721721
convertToPdfAndCompare("flexWithPageBreakInsideAvoidAndPageSplit2", SOURCE_FOLDER, DESTINATION_FOLDER);
722722
}
723723

724+
@Test
725+
@LogMessages(messages = {@LogMessage(messageTemplate = LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)})
726+
// Result for image width differs from browser, although min width and flexible lengths are determined according
727+
// to the CSS specification algorithms. Not sure why browser behaves like this: min main size is calculated based on
728+
// transferred size suggestion instead of content size suggestion and aspect ratio is based on specified properties
729+
// (we calculate it based on original image width / height).
730+
public void imageSizeTest() throws IOException, InterruptedException {
731+
convertToPdfAndCompare("imageSize", SOURCE_FOLDER, DESTINATION_FOLDER);
732+
}
733+
724734
private static List<IElement> convertToElements(String name) throws IOException {
725735
String sourceHtml = SOURCE_FOLDER + name + ".html";
726736
ConverterProperties converterProperties = new ConverterProperties().setBaseUri(SOURCE_FOLDER);
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2025 Apryse Group NV
4+
Authors: Apryse Software.
5+
6+
This program is offered under a commercial and under the AGPL license.
7+
For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
8+
9+
AGPL licensing:
10+
This program is free software: you can redistribute it and/or modify
11+
it under the terms of the GNU Affero General Public License as published by
12+
the Free Software Foundation, either version 3 of the License, or
13+
(at your option) any later version.
14+
15+
This program is distributed in the hope that it will be useful,
16+
but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
GNU Affero General Public License for more details.
19+
20+
You should have received a copy of the GNU Affero General Public License
21+
along with this program. If not, see <https://www.gnu.org/licenses/>.
22+
*/
23+
package com.itextpdf.html2pdf.css.flex;
24+
25+
import com.itextpdf.html2pdf.ExtendedHtmlConversionITextTest;
26+
import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
27+
import com.itextpdf.layout.logs.LayoutLogMessageConstant;
28+
import com.itextpdf.test.annotations.LogMessage;
29+
import com.itextpdf.test.annotations.LogMessages;
30+
import org.junit.jupiter.api.BeforeAll;
31+
import org.junit.jupiter.api.Tag;
32+
import org.junit.jupiter.api.Test;
33+
34+
import java.io.IOException;
35+
36+
@Tag("IntegrationTest")
37+
// TODO DEVSIX-5091 Support flex-basis: content
38+
// TODO DEVSIX-5001 Support content, min-content, max-content as width values
39+
public class FlexBaseSizeTest extends ExtendedHtmlConversionITextTest {
40+
private static final String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/html2pdf/css/flex/FlexBaseSizeTest/";
41+
private static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/html2pdf/css/flex/FlexBaseSizeTest/";
42+
43+
@BeforeAll
44+
public static void beforeClass() {
45+
createDestinationFolder(DESTINATION_FOLDER);
46+
}
47+
48+
// A and E – most common cases from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (flex base size algorithm)
49+
50+
@Test
51+
public void flexBasisAutoWidthNumTest() throws IOException, InterruptedException {
52+
convertToPdfAndCompare("flexBasisAutoWidthNum", SOURCE_FOLDER, DESTINATION_FOLDER);
53+
}
54+
55+
@Test
56+
public void flexBasisAutoHeightNumTest() throws IOException, InterruptedException {
57+
convertToPdfAndCompare("flexBasisAutoHeightNum", SOURCE_FOLDER, DESTINATION_FOLDER);
58+
}
59+
60+
@Test
61+
public void flexBasisAutoWidthPercentageTest() throws IOException, InterruptedException {
62+
convertToPdfAndCompare("flexBasisAutoWidthPercentage", SOURCE_FOLDER, DESTINATION_FOLDER);
63+
}
64+
65+
@Test
66+
public void flexBasisAutoHeightPercentageTest() throws IOException, InterruptedException {
67+
convertToPdfAndCompare("flexBasisAutoHeightPercentage", SOURCE_FOLDER, DESTINATION_FOLDER);
68+
}
69+
70+
@Test
71+
public void flexBasisAutoWidthContentTest() throws IOException, InterruptedException {
72+
convertToPdfAndCompare("flexBasisAutoWidthContent", SOURCE_FOLDER, DESTINATION_FOLDER);
73+
}
74+
75+
@Test
76+
public void flexBasisAutoHeightContentTest() throws IOException, InterruptedException {
77+
convertToPdfAndCompare("flexBasisAutoHeightContent", SOURCE_FOLDER, DESTINATION_FOLDER);
78+
}
79+
80+
@Test
81+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
82+
public void flexBasisAutoWidthMinContentTest() throws IOException, InterruptedException {
83+
convertToPdfAndCompare("flexBasisAutoWidthMinContent", SOURCE_FOLDER, DESTINATION_FOLDER);
84+
}
85+
86+
@Test
87+
public void flexBasisAutoWidthMaxContentTest() throws IOException, InterruptedException {
88+
convertToPdfAndCompare("flexBasisAutoWidthMaxContent", SOURCE_FOLDER, DESTINATION_FOLDER);
89+
}
90+
91+
@Test
92+
@LogMessages(messages =
93+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 12))
94+
public void flexBasisContentTest() throws IOException, InterruptedException {
95+
convertToPdfAndCompare("flexBasisContent", SOURCE_FOLDER, DESTINATION_FOLDER);
96+
}
97+
98+
@Test
99+
@LogMessages(messages =
100+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 9))
101+
// TODO DEVSIX-5255 Support aspect-ratio property
102+
public void flexBasisContentAspectRatioTest() throws IOException, InterruptedException {
103+
convertToPdfAndCompare("flexBasisContentAspectRatio", SOURCE_FOLDER, DESTINATION_FOLDER);
104+
}
105+
106+
@Test
107+
@LogMessages(messages = {
108+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 9),
109+
@LogMessage(messageTemplate = LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)
110+
})
111+
// Result for image width differs from browser, although min width and flexible lengths are determined according
112+
// to the CSS specification algorithms. Not sure why browser behaves like this: min main size is calculated based on
113+
// transferred size suggestion instead of content size suggestion and main size property is ignored.
114+
public void flexBasisContentAspectRatioImageTest() throws IOException, InterruptedException {
115+
convertToPdfAndCompare("flexBasisContentAspectRatioImage", SOURCE_FOLDER, DESTINATION_FOLDER);
116+
}
117+
118+
@Test
119+
@LogMessages(messages =
120+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 9))
121+
// flexBasisContentAspectRatioImageTest alternative
122+
public void flexBasisContentAspectRatioImageBrowserTest() throws IOException, InterruptedException {
123+
convertToPdfAndCompare("flexBasisContentAspectRatioImageBrowser", SOURCE_FOLDER, DESTINATION_FOLDER);
124+
}
125+
126+
@Test
127+
public void splitMaxSizesTest() throws IOException, InterruptedException {
128+
convertToPdfAndCompare("splitMaxSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
129+
}
130+
131+
@Test
132+
public void splitMinSizesTest() throws IOException, InterruptedException {
133+
convertToPdfAndCompare("splitMinSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
134+
}
135+
136+
@Test
137+
@LogMessages(messages =
138+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 10))
139+
public void flexBasisContentIgnoreMinMaxWidthTest() throws IOException, InterruptedException {
140+
convertToPdfAndCompare("flexBasisContentIgnoreMinMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
141+
}
142+
143+
@Test
144+
@LogMessages(messages =
145+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 5))
146+
public void flexBasisContentIgnoreMinMaxHeightTest() throws IOException, InterruptedException {
147+
convertToPdfAndCompare("flexBasisContentIgnoreMinMaxHeight", SOURCE_FOLDER, DESTINATION_FOLDER);
148+
}
149+
150+
@Test
151+
public void flexBasisContentMaxWidthTest() throws IOException, InterruptedException {
152+
convertToPdfAndCompare("flexBasisContentMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
153+
}
154+
155+
@Test
156+
public void flexItemWithPercentageMaxWidthTest() throws IOException, InterruptedException {
157+
convertToPdfAndCompare("flexItemWithPercentageMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER);
158+
}
159+
160+
// B from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm)
161+
162+
@Test
163+
@LogMessages(messages = @LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
164+
// TODO DEVSIX-5255 Support aspect-ratio property
165+
public void flexBasisContentAspectRatioDefiniteCrossSizeTest() throws IOException, InterruptedException {
166+
convertToPdfAndCompare("flexBasisContentAspectRatioDefiniteCrossSize", SOURCE_FOLDER, DESTINATION_FOLDER);
167+
}
168+
169+
@Test
170+
@LogMessages(messages = @LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
171+
// TODO DEVSIX-5255 Support aspect-ratio property
172+
public void flexBasisContentAspectRatioDefiniteCrossSizeColumnTest() throws IOException, InterruptedException {
173+
convertToPdfAndCompare("flexBasisContentAspectRatioDefiniteCrossSizeColumn", SOURCE_FOLDER, DESTINATION_FOLDER);
174+
}
175+
176+
// C from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm)
177+
178+
@Test
179+
@LogMessages(messages =
180+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 2))
181+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
182+
public void flexBasisContentInsideMinContentTest() throws IOException, InterruptedException {
183+
convertToPdfAndCompare("flexBasisContentInsideMinContent", SOURCE_FOLDER, DESTINATION_FOLDER);
184+
}
185+
186+
@Test
187+
@LogMessages(messages =
188+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 4))
189+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
190+
public void flexBasisContentInsideMaxContentTest() throws IOException, InterruptedException {
191+
convertToPdfAndCompare("flexBasisContentInsideMaxContent", SOURCE_FOLDER, DESTINATION_FOLDER);
192+
}
193+
194+
@Test
195+
@LogMessages(messages =
196+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 2))
197+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
198+
public void flexBasisContentInsideMinContentColumnTest() throws IOException, InterruptedException {
199+
convertToPdfAndCompare("flexBasisContentInsideMinContentColumn", SOURCE_FOLDER, DESTINATION_FOLDER);
200+
}
201+
202+
@Test
203+
@LogMessages(messages =
204+
@LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, count = 2))
205+
// TODO DEVSIX-5001 min-content and max-content as width are not supported
206+
public void flexBasisContentInsideMaxContentColumnTest() throws IOException, InterruptedException {
207+
convertToPdfAndCompare("flexBasisContentInsideMaxContentColumn", SOURCE_FOLDER, DESTINATION_FOLDER);
208+
}
209+
210+
// D from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm)
211+
212+
@Test
213+
@LogMessages(messages = @LogMessage(messageTemplate = Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET))
214+
// TODO DEVSIX-5182 Support writing-mode property
215+
// E.g. infinite height + vertical main axe for flex container (column) + vertical-writing-mode flex item
216+
public void flexBasisContentOrthogonalFlowTest() throws IOException, InterruptedException {
217+
convertToPdfAndCompare("flexBasisContentOrthogonalFlow", SOURCE_FOLDER, DESTINATION_FOLDER);
218+
}
219+
}

src/test/java/com/itextpdf/html2pdf/css/flex/FlexContainerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,11 @@ public void ulWideTest() throws IOException, InterruptedException {
382382
convertToPdfAndCompare("ulWide", SOURCE_FOLDER, DESTINATION_FOLDER);
383383
}
384384

385+
@Test
386+
public void flexNestedTest() throws IOException, InterruptedException {
387+
convertToPdfAndCompare("flexNested", SOURCE_FOLDER, DESTINATION_FOLDER);
388+
}
389+
385390
@Test
386391
public void deepNestingTest() throws IOException, InterruptedException {
387392
convertToPdfAndCompare("deepNesting", SOURCE_FOLDER, DESTINATION_FOLDER);

src/test/java/com/itextpdf/html2pdf/css/flex/FlexGapTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ public void colGapMarginTest() throws IOException, InterruptedException {
382382
}
383383

384384
@Test
385-
// TODO DEVSIX-9477 Fix issue on page split: cross-size calculated incorrectly
386385
public void colGapMixedSizesTest() throws IOException, InterruptedException {
387386
convertToPdfAndCompare("colGapMixedSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
388387
}
@@ -495,7 +494,6 @@ public void rowGapMarginTest() throws IOException, InterruptedException {
495494
}
496495

497496
@Test
498-
// TODO DEVSIX-9477 Fix issue on page split: cross-size calculated incorrectly
499497
public void rowGapMixedSizesTest() throws IOException, InterruptedException {
500498
convertToPdfAndCompare("rowGapMixedSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
501499
}

src/test/java/com/itextpdf/html2pdf/css/flex/PageSplitTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public static void beforeClass() {
4646
}
4747

4848
@Test
49-
// TODO DEVSIX-9477 Fix issue on page split
5049
public void mixedSizesTest() throws IOException, InterruptedException {
5150
convertToPdfAndCompare("mixedSizes", SOURCE_FOLDER, DESTINATION_FOLDER);
5251
}

src/test/java/com/itextpdf/html2pdf/css/w3c/css21/linebox/LineHeight126Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This file is part of the iText (R) project.
2424

2525
import com.itextpdf.html2pdf.css.w3c.W3CCssTest;
2626

27-
// TODO DEVSIX-3757 change cmp file after completing the ticket
27+
// TODO DEVSIX-3757 Support vertical-align css property
2828
public class LineHeight126Test extends W3CCssTest {
2929
@Override
3030
protected String getHtmlFileName() {

src/test/java/com/itextpdf/html2pdf/css/w3c/css21/linebox/LineHeight129Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This file is part of the iText (R) project.
2424

2525
import com.itextpdf.html2pdf.css.w3c.W3CCssTest;
2626

27-
// TODO DEVSIX-3757 change cmp file after completing the ticket
27+
// TODO DEVSIX-3757 Support vertical-align css property
2828
public class LineHeight129Test extends W3CCssTest {
2929
@Override
3030
protected String getHtmlFileName() {

0 commit comments

Comments
 (0)