|
| 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 | +} |
0 commit comments