|
| 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 | +using System; |
| 24 | +using iText.Html2pdf; |
| 25 | +using iText.Html2pdf.Logs; |
| 26 | +using iText.Layout.Logs; |
| 27 | +using iText.Test.Attributes; |
| 28 | + |
| 29 | +namespace iText.Html2pdf.Css.Flex { |
| 30 | + [NUnit.Framework.Category("IntegrationTest")] |
| 31 | + public class FlexBaseSizeTest : ExtendedHtmlConversionITextTest { |
| 32 | + // TODO DEVSIX-5091 Support flex-basis: content |
| 33 | + // TODO DEVSIX-5001 Support content, min-content, max-content as width values |
| 34 | + private static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext |
| 35 | + .CurrentContext.TestDirectory) + "/resources/itext/html2pdf/css/flex/FlexBaseSizeTest/"; |
| 36 | + |
| 37 | + private static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory |
| 38 | + + "/test/itext/html2pdf/css/flex/FlexBaseSizeTest/"; |
| 39 | + |
| 40 | + [NUnit.Framework.OneTimeSetUp] |
| 41 | + public static void BeforeClass() { |
| 42 | + CreateDestinationFolder(DESTINATION_FOLDER); |
| 43 | + } |
| 44 | + |
| 45 | + // A and E – most common cases from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (flex base size algorithm) |
| 46 | + [NUnit.Framework.Test] |
| 47 | + public virtual void FlexBasisAutoWidthNumTest() { |
| 48 | + ConvertToPdfAndCompare("flexBasisAutoWidthNum", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 49 | + } |
| 50 | + |
| 51 | + [NUnit.Framework.Test] |
| 52 | + public virtual void FlexBasisAutoHeightNumTest() { |
| 53 | + ConvertToPdfAndCompare("flexBasisAutoHeightNum", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 54 | + } |
| 55 | + |
| 56 | + [NUnit.Framework.Test] |
| 57 | + public virtual void FlexBasisAutoWidthPercentageTest() { |
| 58 | + ConvertToPdfAndCompare("flexBasisAutoWidthPercentage", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 59 | + } |
| 60 | + |
| 61 | + [NUnit.Framework.Test] |
| 62 | + public virtual void FlexBasisAutoHeightPercentageTest() { |
| 63 | + ConvertToPdfAndCompare("flexBasisAutoHeightPercentage", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 64 | + } |
| 65 | + |
| 66 | + [NUnit.Framework.Test] |
| 67 | + public virtual void FlexBasisAutoWidthContentTest() { |
| 68 | + ConvertToPdfAndCompare("flexBasisAutoWidthContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 69 | + } |
| 70 | + |
| 71 | + [NUnit.Framework.Test] |
| 72 | + public virtual void FlexBasisAutoHeightContentTest() { |
| 73 | + ConvertToPdfAndCompare("flexBasisAutoHeightContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 74 | + } |
| 75 | + |
| 76 | + [NUnit.Framework.Test] |
| 77 | + public virtual void FlexBasisAutoWidthMinContentTest() { |
| 78 | + // TODO DEVSIX-5001 min-content and max-content as width are not supported |
| 79 | + ConvertToPdfAndCompare("flexBasisAutoWidthMinContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 80 | + } |
| 81 | + |
| 82 | + [NUnit.Framework.Test] |
| 83 | + public virtual void FlexBasisAutoWidthMaxContentTest() { |
| 84 | + ConvertToPdfAndCompare("flexBasisAutoWidthMaxContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 85 | + } |
| 86 | + |
| 87 | + [NUnit.Framework.Test] |
| 88 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 12)] |
| 89 | + public virtual void FlexBasisContentTest() { |
| 90 | + ConvertToPdfAndCompare("flexBasisContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 91 | + } |
| 92 | + |
| 93 | + [NUnit.Framework.Test] |
| 94 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 9)] |
| 95 | + public virtual void FlexBasisContentAspectRatioTest() { |
| 96 | + // TODO DEVSIX-5255 Support aspect-ratio property |
| 97 | + ConvertToPdfAndCompare("flexBasisContentAspectRatio", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 98 | + } |
| 99 | + |
| 100 | + [NUnit.Framework.Test] |
| 101 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 9)] |
| 102 | + [LogMessage(LayoutLogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)] |
| 103 | + public virtual void FlexBasisContentAspectRatioImageTest() { |
| 104 | + // Result for image width differs from browser, although min width and flexible lengths are determined according |
| 105 | + // to the CSS specification algorithms. Not sure why browser behaves like this: min main size is calculated based on |
| 106 | + // transferred size suggestion instead of content size suggestion and main size property is ignored. |
| 107 | + ConvertToPdfAndCompare("flexBasisContentAspectRatioImage", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 108 | + } |
| 109 | + |
| 110 | + [NUnit.Framework.Test] |
| 111 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 9)] |
| 112 | + public virtual void FlexBasisContentAspectRatioImageBrowserTest() { |
| 113 | + // flexBasisContentAspectRatioImageTest alternative |
| 114 | + ConvertToPdfAndCompare("flexBasisContentAspectRatioImageBrowser", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 115 | + } |
| 116 | + |
| 117 | + [NUnit.Framework.Test] |
| 118 | + public virtual void SplitMaxSizesTest() { |
| 119 | + ConvertToPdfAndCompare("splitMaxSizes", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 120 | + } |
| 121 | + |
| 122 | + [NUnit.Framework.Test] |
| 123 | + public virtual void SplitMinSizesTest() { |
| 124 | + ConvertToPdfAndCompare("splitMinSizes", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 125 | + } |
| 126 | + |
| 127 | + [NUnit.Framework.Test] |
| 128 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 10)] |
| 129 | + public virtual void FlexBasisContentIgnoreMinMaxWidthTest() { |
| 130 | + ConvertToPdfAndCompare("flexBasisContentIgnoreMinMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 131 | + } |
| 132 | + |
| 133 | + [NUnit.Framework.Test] |
| 134 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 5)] |
| 135 | + public virtual void FlexBasisContentIgnoreMinMaxHeightTest() { |
| 136 | + ConvertToPdfAndCompare("flexBasisContentIgnoreMinMaxHeight", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 137 | + } |
| 138 | + |
| 139 | + [NUnit.Framework.Test] |
| 140 | + public virtual void FlexBasisContentMaxWidthTest() { |
| 141 | + ConvertToPdfAndCompare("flexBasisContentMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 142 | + } |
| 143 | + |
| 144 | + [NUnit.Framework.Test] |
| 145 | + public virtual void FlexItemWithPercentageMaxWidthTest() { |
| 146 | + ConvertToPdfAndCompare("flexItemWithPercentageMaxWidth", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 147 | + } |
| 148 | + |
| 149 | + // B from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm) |
| 150 | + [NUnit.Framework.Test] |
| 151 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET)] |
| 152 | + public virtual void FlexBasisContentAspectRatioDefiniteCrossSizeTest() { |
| 153 | + // TODO DEVSIX-5255 Support aspect-ratio property |
| 154 | + ConvertToPdfAndCompare("flexBasisContentAspectRatioDefiniteCrossSize", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 155 | + } |
| 156 | + |
| 157 | + [NUnit.Framework.Test] |
| 158 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET)] |
| 159 | + public virtual void FlexBasisContentAspectRatioDefiniteCrossSizeColumnTest() { |
| 160 | + // TODO DEVSIX-5255 Support aspect-ratio property |
| 161 | + ConvertToPdfAndCompare("flexBasisContentAspectRatioDefiniteCrossSizeColumn", SOURCE_FOLDER, DESTINATION_FOLDER |
| 162 | + ); |
| 163 | + } |
| 164 | + |
| 165 | + // C from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm) |
| 166 | + [NUnit.Framework.Test] |
| 167 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 2)] |
| 168 | + public virtual void FlexBasisContentInsideMinContentTest() { |
| 169 | + // TODO DEVSIX-5001 min-content and max-content as width are not supported |
| 170 | + ConvertToPdfAndCompare("flexBasisContentInsideMinContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 171 | + } |
| 172 | + |
| 173 | + [NUnit.Framework.Test] |
| 174 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 4)] |
| 175 | + public virtual void FlexBasisContentInsideMaxContentTest() { |
| 176 | + // TODO DEVSIX-5001 min-content and max-content as width are not supported |
| 177 | + ConvertToPdfAndCompare("flexBasisContentInsideMaxContent", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 178 | + } |
| 179 | + |
| 180 | + [NUnit.Framework.Test] |
| 181 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 2)] |
| 182 | + public virtual void FlexBasisContentInsideMinContentColumnTest() { |
| 183 | + // TODO DEVSIX-5001 min-content and max-content as width are not supported |
| 184 | + ConvertToPdfAndCompare("flexBasisContentInsideMinContentColumn", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 185 | + } |
| 186 | + |
| 187 | + [NUnit.Framework.Test] |
| 188 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET, Count = 2)] |
| 189 | + public virtual void FlexBasisContentInsideMaxContentColumnTest() { |
| 190 | + // TODO DEVSIX-5001 min-content and max-content as width are not supported |
| 191 | + ConvertToPdfAndCompare("flexBasisContentInsideMaxContentColumn", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 192 | + } |
| 193 | + |
| 194 | + // D from https://www.w3.org/TR/css-flexbox-1/#algo-main-item (Determine the flex base size algorithm) |
| 195 | + [NUnit.Framework.Test] |
| 196 | + [LogMessage(Html2PdfLogMessageConstant.FLEX_PROPERTY_IS_NOT_SUPPORTED_YET)] |
| 197 | + public virtual void FlexBasisContentOrthogonalFlowTest() { |
| 198 | + // TODO DEVSIX-5182 Support writing-mode property |
| 199 | + // E.g. infinite height + vertical main axe for flex container (column) + vertical-writing-mode flex item |
| 200 | + ConvertToPdfAndCompare("flexBasisContentOrthogonalFlow", SOURCE_FOLDER, DESTINATION_FOLDER); |
| 201 | + } |
| 202 | + } |
| 203 | +} |
0 commit comments