diff --git a/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs b/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs index 7a82e11478..92d5c7b777 100644 --- a/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs @@ -52,9 +52,9 @@ public virtual void BasicThreeColumnsTest() { String filename = DESTINATION_FOLDER + "basicThreeColumnsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(150.0f)); - templateColumns.Add((TemplateValue)new PointValue(150.0f)); - templateColumns.Add((TemplateValue)new PointValue(150.0f)); + templateColumns.Add(new PointValue(150.0f)); + templateColumns.Add(new PointValue(150.0f)); + templateColumns.Add(new PointValue(150.0f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -137,10 +137,10 @@ public virtual void ThreeColumnsWithAdjacentWideCellsTest() { String filename = DESTINATION_FOLDER + "threeColumnsWithAdjacentWideCellsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_threeColumnsWithAdjacentWideCellsTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); GridContainer grid = new GridContainer(); @@ -173,9 +173,9 @@ public virtual void BasicThreeColumnsWithCustomRowIndexesTest() { String filename = DESTINATION_FOLDER + "basicThreeColumnsWithCustomRowIndexesTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsWithCustomRowIndexesTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -201,9 +201,9 @@ public virtual void BasicThreeColumnsWithCustomColumnAndRowIndexesTest() { String filename = DESTINATION_FOLDER + "basicThreeColumnsWithCustomColumnAndRowIndexesTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsWithCustomColumnAndRowIndexesTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -230,9 +230,9 @@ public virtual void BasicThreeColumnsWithReversedIndexesTest() { String filename = DESTINATION_FOLDER + "basicThreeColumnsWithReversedIndexesTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsWithReversedIndexesTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -267,9 +267,9 @@ public virtual void BasicThreeColumnsWithoutColumnEndTest() { String filename = DESTINATION_FOLDER + "basicThreeColumnsWithoutColumnEndTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsWithoutColumnEndTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -302,9 +302,9 @@ public virtual void FixedColumnRowGoesFirstTest() { String filename = DESTINATION_FOLDER + "fixedColumnRowGoesFirstTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_fixedColumnRowGoesFirstTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -347,9 +347,9 @@ public virtual void FixedColumnRowGoesFirstTest() { public virtual void OverlapWithExistingColumnTest() { String filename = DESTINATION_FOLDER + "overlapWithExistingColumnTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -381,9 +381,9 @@ public virtual void BasicThreeColumnsWithPtAndPercentTest() { String filename = DESTINATION_FOLDER + "basicThreeColumnsWithPtAndPercentTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_basicThreeColumnsWithPtAndPercentTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PercentValue(15.0f)); - templateColumns.Add((TemplateValue)new PercentValue(50.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PercentValue(15.0f)); + templateColumns.Add(new PercentValue(50.0f)); + templateColumns.Add(new PointValue(100.0f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -402,9 +402,9 @@ public virtual void ThirdColumnNotLayoutedTest() { String filename = DESTINATION_FOLDER + "thirdColumnNotLayoutedTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_thirdColumnNotLayoutedTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(200.0f)); - templateColumns.Add((TemplateValue)new PointValue(200.0f)); - templateColumns.Add((TemplateValue)new PointValue(200.0f)); + templateColumns.Add(new PointValue(200.0f)); + templateColumns.Add(new PointValue(200.0f)); + templateColumns.Add(new PointValue(200.0f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -423,9 +423,9 @@ public virtual void ThreeColumnsWithSquareAndVerticalCellsTest() { String filename = DESTINATION_FOLDER + "threeColumnsWithSquareAndVerticalCellsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_threeColumnsWithSquareAndVerticalCellsTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -457,9 +457,9 @@ public virtual void ThreeColumnsWithSquareCellAndCellWithExplicitHeightTest() { String filename = DESTINATION_FOLDER + "threeColumnsWithSquareCellAndCellWithExplicitHeightTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_threeColumnsWithSquareCellAndCellWithExplicitHeightTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); grid.SetBackgroundColor(ColorConstants.GREEN); @@ -488,9 +488,9 @@ public virtual void ThreeColumnsWithVerticalCellWithSeveralNeighboursToTheLeftTe String filename = DESTINATION_FOLDER + "threeColumnsWithVerticalCellWithSeveralNeighboursToTheLeftTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_threeColumnsWithVerticalCellWithSeveralNeighboursToTheLeftTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -522,7 +522,7 @@ public virtual void BigCellMinContentTest() { String cmpName = SOURCE_FOLDER + "cmp_bigCellMinContentTest.pdf"; SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); IList templateColumns = new List(); - templateColumns.Add((TemplateValue)MinContentValue.VALUE); + templateColumns.Add(MinContentValue.VALUE); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns); @@ -540,8 +540,8 @@ public virtual void ColumnRowGapTest() { String filename = DESTINATION_FOLDER + "columnRowGapTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_columnRowGapTest.pdf"; IList template = new List(); - template.Add((TemplateValue)new PointValue(50.0f)); - template.Add((TemplateValue)new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, template); @@ -646,9 +646,9 @@ public virtual void FewBigCellsWithGapTest() { String filename = DESTINATION_FOLDER + "fewBigCellsWithGapTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_fewBigCellsWithGapTest.pdf"; IList template = new List(); - template.Add((TemplateValue)new PointValue(50.0f)); - template.Add((TemplateValue)new PointValue(50.0f)); - template.Add((TemplateValue)new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, template); @@ -685,9 +685,9 @@ public virtual void ColumnFlowWithBigCellsTest() { String filename = DESTINATION_FOLDER + "columnFlowWithBigCellsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_columnFlowWithBigCellsTest.pdf"; IList template = new List(); - template.Add((TemplateValue)new PointValue(50.0f)); - template.Add((TemplateValue)new PointValue(50.0f)); - template.Add((TemplateValue)new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); + template.Add(new PointValue(50.0f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); grid.SetProperty(Property.GRID_FLOW, GridFlow.COLUMN); @@ -726,8 +726,8 @@ public virtual void FrInRowsTest() { String filename = DESTINATION_FOLDER + "frInRowsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_frInRowsTest.pdf"; IList template = new List(); - template.Add((TemplateValue)new FlexValue(1f)); - template.Add((TemplateValue)new FlexValue(3f)); + template.Add(new FlexValue(1f)); + template.Add(new FlexValue(3f)); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); grid.SetProperty(Property.GRID_TEMPLATE_ROWS, template); @@ -746,9 +746,9 @@ public virtual void FrColumnsTest() { String filename = DESTINATION_FOLDER + "frColumnsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_frColumnsTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new FlexValue(1f)); - templateColumns.Add((TemplateValue)AutoValue.VALUE); - templateColumns.Add((TemplateValue)new FlexValue(3f)); + templateColumns.Add(new FlexValue(1f)); + templateColumns.Add(AutoValue.VALUE); + templateColumns.Add(new FlexValue(3f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -773,9 +773,9 @@ public virtual void FitContentColumnsTest() { String filename = DESTINATION_FOLDER + "fitContentColumnsTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_fitContentColumnsTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new FlexValue(1f)); - templateColumns.Add((TemplateValue)new FlexValue(3f)); - templateColumns.Add((TemplateValue)new FitContentValue(UnitValue.CreatePercentValue(5.0f))); + templateColumns.Add(new FlexValue(1f)); + templateColumns.Add(new FlexValue(3f)); + templateColumns.Add(new FitContentValue(UnitValue.CreatePercentValue(5.0f))); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -800,9 +800,9 @@ public virtual void ColumnSpanTest() { String filename = DESTINATION_FOLDER + "columnSpanTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_columnSpanTest.pdf"; IList templateColumns = new List(); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); - templateColumns.Add((TemplateValue)new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(new PointValue(100.0f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -825,9 +825,9 @@ public virtual void RowSpanTest() { String filename = DESTINATION_FOLDER + "rowSpanTest.pdf"; String cmpName = SOURCE_FOLDER + "cmp_rowSpanTest.pdf"; IList template = new List(); - template.Add((TemplateValue)new PointValue(100.0f)); - template.Add((TemplateValue)new PointValue(100.0f)); - template.Add((TemplateValue)new PointValue(100.0f)); + template.Add(new PointValue(100.0f)); + template.Add(new PointValue(100.0f)); + template.Add(new PointValue(100.0f)); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); @@ -845,5 +845,34 @@ public virtual void RowSpanTest() { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_" )); } + + [NUnit.Framework.Test] + public virtual void AutoRepeatPaddingsBordersMarginsTest() { + String filename = DESTINATION_FOLDER + "autoRepeatPaddingsBordersMarginsTest.pdf"; + String cmpName = SOURCE_FOLDER + "cmp_autoRepeatPaddingsBordersMarginsTest.pdf"; + IList columnsTemplate = new List(); + columnsTemplate.Add(new AutoRepeatValue(true, JavaUtil.ArraysAsList((GridValue)new PointValue(200)))); + using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { + GridContainer grid = new GridContainer(); + grid.SetWidth(420); + grid.SetBorder(new SolidBorder(20)); + grid.SetPadding(20); + grid.SetMargin(20); + grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, columnsTemplate); + grid.SetProperty(Property.COLUMN_GAP, 20.0f); + grid.Add(new Paragraph("One").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Two").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Tree").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Four").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Five").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Six").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Seven").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Eight").SetBackgroundColor(ColorConstants.CYAN)); + grid.Add(new Paragraph("Nine").SetBackgroundColor(ColorConstants.CYAN)); + document.Add(grid); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_" + )); + } } } diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_autoRepeatPaddingsBordersMarginsTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_autoRepeatPaddingsBordersMarginsTest.pdf new file mode 100644 index 0000000000..8281db550b Binary files /dev/null and b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_autoRepeatPaddingsBordersMarginsTest.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_continuousColumContainerSetWidth.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_continuousColumContainerSetWidth.pdf index b87b729172..b27b6cf80b 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_continuousColumContainerSetWidth.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_continuousColumContainerSetWidth.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_maxWidth.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_maxWidth.pdf index 01b2d860a7..92f1d52162 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_maxWidth.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_maxWidth.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_minWidthBiggerThenPage.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_minWidthBiggerThenPage.pdf index 816c5e492e..7ef0186dd9 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_minWidthBiggerThenPage.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_minWidthBiggerThenPage.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthBorderTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthBorderTest.pdf index fd4de740a0..be5ed346f9 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthBorderTest.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthBorderTest.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthHeightMarginTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthHeightMarginTest.pdf index d1d5e4e3e5..ec4bc52979 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthHeightMarginTest.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthHeightMarginTest.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMarginTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMarginTest.pdf index b03be7435f..eec2313cbd 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMarginTest.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMarginTest.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMultiPage.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMultiPage.pdf index 459ce0644c..626bb5d896 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMultiPage.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthMultiPage.pdf differ diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthPaddingTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthPaddingTest.pdf index c456fefd2b..21482ecd88 100644 Binary files a/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthPaddingTest.pdf and b/itext.tests/itext.layout.tests/resources/itext/layout/MulticolContainerTest/cmp_widthPaddingTest.pdf differ diff --git a/itext.tests/itext.pdftest.tests/itext/test/VeraPdfLoggerValidationTest.cs b/itext.tests/itext.pdftest.tests/itext/test/VeraPdfLoggerValidationTest.cs index 4386af2ecc..d220112f95 100644 --- a/itext.tests/itext.pdftest.tests/itext/test/VeraPdfLoggerValidationTest.cs +++ b/itext.tests/itext.pdftest.tests/itext/test/VeraPdfLoggerValidationTest.cs @@ -25,7 +25,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Test.Utils; namespace iText.Test { - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) + // Android-Conversion-Skip-File (TODO DEVSIX-7377 introduce pdf\a validation on Android) [NUnit.Framework.Category("UnitTest")] public class VeraPdfLoggerValidationTest : ExtendedITextTest { //\cond DO_NOT_DOCUMENT @@ -51,7 +51,6 @@ public virtual void CheckValidatorLogsNoOutputTest() { NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(DESTINATION_FOLDER + target)); } - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) [NUnit.Framework.Test] public virtual void CheckValidatorLogsWithWarningTest() { String source = "pdfA2b_checkValidatorLogsTest_with_warnings.pdf"; @@ -64,7 +63,6 @@ public virtual void CheckValidatorLogsWithWarningTest() { + target)); } - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) [NUnit.Framework.Test] public virtual void CheckValidatorLogsCleanupTest() { String fileNameWithWarnings = "pdfA2b_checkValidatorLogsTest_with_warnings.pdf"; @@ -76,13 +74,11 @@ public virtual void CheckValidatorLogsCleanupTest() { + "WARNING: The Top DICT does not begin with ROS operator"; NUnit.Framework.Assert.AreEqual(expectedWarningsForFileWithWarnings, new VeraPdfValidator().Validate(DESTINATION_FOLDER + fileNameWithWarnings)); - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) //We check that the logs are empty after the first check NUnit.Framework.Assert.IsNull(new VeraPdfValidator().Validate(DESTINATION_FOLDER + fileNameWithoutWarnings )); } - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) [NUnit.Framework.Test] public virtual void CheckValidatorLogsForFileContainingErrorsTest() { String source = "pdfA2b_checkValidatorLogsTest_with_errors.pdf"; @@ -90,9 +86,7 @@ public virtual void CheckValidatorLogsForFileContainingErrorsTest() { FileUtil.Copy(SOURCE_FOLDER + source, DESTINATION_FOLDER + target); String expectedResponseForErrors = "VeraPDF verification failed. See verification results: file:"; String result = new VeraPdfValidator().Validate(DESTINATION_FOLDER + target); - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)); NUnit.Framework.Assert.IsTrue(result.StartsWith(expectedResponseForErrors)); } - // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android) } } diff --git a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridItemShorthandResolverTest.cs b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridItemShorthandResolverTest.cs new file mode 100644 index 0000000000..4852543e1f --- /dev/null +++ b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridItemShorthandResolverTest.cs @@ -0,0 +1,113 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.Commons.Utils; +using iText.StyledXmlParser.Css; +using iText.StyledXmlParser.Css.Resolve.Shorthand; +using iText.Test; +using iText.Test.Attributes; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + [NUnit.Framework.Category("UnitTest")] + public class GridItemShorthandResolverTest : ExtendedITextTest { + [NUnit.Framework.Test] + public virtual void InitialOrInheritOrUnsetValuesTest() { + IShorthandResolver resolver = new GridRowShorthandResolver(); + String initialShorthand = CommonCssConstants.INITIAL; + IList resolvedShorthand = resolver.ResolveShorthand(initialShorthand); + NUnit.Framework.Assert.AreEqual(0, resolvedShorthand.Count); + String inheritShorthand = CommonCssConstants.INHERIT; + resolvedShorthand = resolver.ResolveShorthand(inheritShorthand); + NUnit.Framework.Assert.AreEqual(0, resolvedShorthand.Count); + String unsetShorthand = CommonCssConstants.UNSET; + resolvedShorthand = resolver.ResolveShorthand(unsetShorthand); + NUnit.Framework.Assert.AreEqual(0, resolvedShorthand.Count); + } + + [NUnit.Framework.Test] + [LogMessage(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY + , Count = 4)] + public virtual void EmptyShorthandTest() { + IShorthandResolver resolver = new GridColumnShorthandResolver(); + String emptyShorthand = ""; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (emptyShorthand)); + String shorthandWithSpaces = " "; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (shorthandWithSpaces)); + String shorthandWithTabs = "\t"; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (shorthandWithTabs)); + String shorthandWithNewLines = "\n"; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (shorthandWithNewLines)); + } + + [NUnit.Framework.Test] + public virtual void BasicRowValuesTest() { + IShorthandResolver resolver = new GridRowShorthandResolver(); + String shorthand = "span 2 / 4"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_ROW_START, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_ROW_END, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual("span 2", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("4", resolvedShorthand[1].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void BasicColumnValuesTest() { + IShorthandResolver resolver = new GridColumnShorthandResolver(); + String shorthand = "3 / span 6"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_COLUMN_START, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_COLUMN_END, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual("3", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("span 6", resolvedShorthand[1].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void SingleValueTest() { + IShorthandResolver resolver = new GridColumnShorthandResolver(); + String shorthand = "3"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_COLUMN_START, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_COLUMN_END, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual("3", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("3", resolvedShorthand[1].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void SingleValueSpanTest() { + IShorthandResolver resolver = new GridColumnShorthandResolver(); + String shorthand = "span 3"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(1, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_COLUMN_START, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual("span 3", resolvedShorthand[0].GetExpression()); + } + } +} diff --git a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridShorthandResolverTest.cs b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridShorthandResolverTest.cs new file mode 100644 index 0000000000..59d0420ae5 --- /dev/null +++ b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridShorthandResolverTest.cs @@ -0,0 +1,107 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.StyledXmlParser.Css; +using iText.StyledXmlParser.Css.Resolve.Shorthand; +using iText.Test; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + [NUnit.Framework.Category("UnitTest")] + public class GridShorthandResolverTest : ExtendedITextTest { + /// Creates grid shorthand resolver. + public GridShorthandResolverTest() { + } + + [NUnit.Framework.Test] + public virtual void TemplateAreasTest() { + IShorthandResolver resolver = new GridShorthandResolver(); + String shorthand = "[header-top] 'a a a' [header-bottom] [main-top] 'b b b' 1fr [main-bottom] / auto 1fr auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[2].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("[header-top] [header-bottom] [main-top] 1fr [main-bottom]", resolvedShorthand + [0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto 1fr auto", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b'", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void ColumnFlowTest() { + IShorthandResolver resolver = new GridShorthandResolver(); + String shorthand = "20% 100px 1fr / auto-flow dense 50px"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_AUTO_FLOW, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_AUTO_COLUMNS, resolvedShorthand[2].GetProperty()); + NUnit.Framework.Assert.AreEqual("20% 100px 1fr", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("column dense", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("50px", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void RowFlowTest() { + IShorthandResolver resolver = new GridShorthandResolver(); + String shorthand = "auto-flow dense auto / 1fr auto minmax(100px, 1fr)"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_AUTO_FLOW, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_AUTO_ROWS, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[2].GetProperty + ()); + NUnit.Framework.Assert.AreEqual("dense", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("1fr auto minmax(100px,1fr)", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void NoRowTemplateTest() { + IShorthandResolver resolver = new GridShorthandResolver(); + String shorthand = "auto-flow dense / 1fr auto minmax(100px, 1fr)"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_AUTO_FLOW, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual("dense", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("1fr auto minmax(100px,1fr)", resolvedShorthand[1].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void NoColumnTemplateTest() { + IShorthandResolver resolver = new GridShorthandResolver(); + String shorthand = "1fr auto minmax(100px, 1fr) / auto-flow dense"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_AUTO_FLOW, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual("1fr auto minmax(100px,1fr)", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("column dense", resolvedShorthand[1].GetExpression()); + } + } +} diff --git a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridTemplateShorthandResolverTest.cs b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridTemplateShorthandResolverTest.cs new file mode 100644 index 0000000000..1dad686f8d --- /dev/null +++ b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/impl/GridTemplateShorthandResolverTest.cs @@ -0,0 +1,200 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.Commons.Utils; +using iText.StyledXmlParser.Css; +using iText.StyledXmlParser.Css.Resolve.Shorthand; +using iText.Test; +using iText.Test.Attributes; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + [NUnit.Framework.Category("UnitTest")] + public class GridTemplateShorthandResolverTest : ExtendedITextTest { + [NUnit.Framework.Test] + public virtual void InitialOrInheritOrUnsetValuesTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String initialShorthand = CommonCssConstants.INITIAL; + IList resolvedShorthand = resolver.ResolveShorthand(initialShorthand); + NUnit.Framework.Assert.AreEqual(0, resolvedShorthand.Count); + String inheritShorthand = CommonCssConstants.INHERIT; + resolvedShorthand = resolver.ResolveShorthand(inheritShorthand); + NUnit.Framework.Assert.AreEqual(0, resolvedShorthand.Count); + String unsetShorthand = CommonCssConstants.UNSET; + resolvedShorthand = resolver.ResolveShorthand(unsetShorthand); + NUnit.Framework.Assert.AreEqual(0, resolvedShorthand.Count); + } + + [NUnit.Framework.Test] + [LogMessage(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY + , Count = 4)] + public virtual void EmptyShorthandTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String emptyShorthand = ""; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (emptyShorthand)); + String shorthandWithSpaces = " "; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (shorthandWithSpaces)); + String shorthandWithTabs = "\t"; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (shorthandWithTabs)); + String shorthandWithNewLines = "\n"; + NUnit.Framework.Assert.AreEqual(JavaCollectionsUtil.EmptyList(), resolver.ResolveShorthand + (shorthandWithNewLines)); + } + + [NUnit.Framework.Test] + public virtual void BasicTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = "auto 1fr / auto 1fr auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual("auto 1fr", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto 1fr auto", resolvedShorthand[1].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void LineNamesTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = "[linename] 100px / [columnname1] 30% [columnname2] 70%"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual("[linename] 100px", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("[columnname1] 30% [columnname2] 70%", resolvedShorthand[1].GetExpression( + )); + } + + [NUnit.Framework.Test] + public virtual void AreaTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = "'a a a' 'b b b'"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(1, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[0].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b'", resolvedShorthand[0].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void AreaWithRowsTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = " 'a a a' 20% 'b b b' auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[1].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("20% auto", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b'", resolvedShorthand[1].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void AreaWithRowsAndColumnsTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = " 'a a a' 20% 'b b b' auto / auto 1fr auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[2].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("20% auto", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto 1fr auto", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b'", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void AreaWithMissingRowAtTheEndTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = " 'a a a' 20% 'b b b' 1fr 'c c c' / auto 1fr auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[2].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("20% 1fr auto", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto 1fr auto", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b' 'c c c'", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void AreaWithMissingRowAtTheStartTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = " 'a a a' 'b b b' 1fr 'c c c' 80% / auto 1fr auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[2].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("auto 1fr 80%", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto 1fr auto", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b' 'c c c'", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void ComplexAreaTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = "[header-top] 'a a a' [header-bottom] [main-top] 'b b b' 1fr [main-bottom] / auto 1fr auto"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[2].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("[header-top] [header-bottom] [main-top] 1fr [main-bottom]", resolvedShorthand + [0].GetExpression()); + NUnit.Framework.Assert.AreEqual("auto 1fr auto", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("'a a a' 'b b b'", resolvedShorthand[2].GetExpression()); + } + + [NUnit.Framework.Test] + public virtual void ComplexAreaWithoutLineNamesTest() { + IShorthandResolver resolver = new GridTemplateShorthandResolver(); + String shorthand = "'head head' 30px 'nav main' 1fr 'nav foot' 30px / 120px 1fr"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(3, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_ROWS, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_COLUMNS, resolvedShorthand[1].GetProperty + ()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.GRID_TEMPLATE_AREAS, resolvedShorthand[2].GetProperty() + ); + NUnit.Framework.Assert.AreEqual("30px 1fr 30px", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual("120px 1fr", resolvedShorthand[1].GetExpression()); + NUnit.Framework.Assert.AreEqual("'head head' 'nav main' 'nav foot'", resolvedShorthand[2].GetExpression( + )); + } + } +} diff --git a/itext/itext.layout/itext/layout/renderer/GridCell.cs b/itext/itext.layout/itext/layout/renderer/GridCell.cs index 24176171fc..995b1336de 100644 --- a/itext/itext.layout/itext/layout/renderer/GridCell.cs +++ b/itext/itext.layout/itext/layout/renderer/GridCell.cs @@ -178,8 +178,13 @@ private int[] InitAxisPlacement(int? start, int? end, int? span) { result[1] = intEnd - intStart; } else { - result[0] = intEnd; - result[1] = intStart - intEnd; + if (intStart == intEnd) { + result[0] = intStart; + } + else { + result[0] = intEnd; + result[1] = intStart - intEnd; + } } } else { diff --git a/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs b/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs index b4b8ab5c4c..55f1c52834 100644 --- a/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs +++ b/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs @@ -23,7 +23,6 @@ You should have received a copy of the GNU Affero General Public License using System; using System.Collections.Generic; using iText.Kernel.Geom; -using iText.Layout.Borders; using iText.Layout.Element; using iText.Layout.Layout; using iText.Layout.Properties; @@ -36,6 +35,8 @@ public class GridContainerRenderer : BlockRenderer { private float containerHeight = 0.0f; + private float containerWidth = 0.0f; + /// Creates a Grid renderer from its corresponding layout object. /// /// the @@ -59,13 +60,12 @@ public override LayoutResult Layout(LayoutContext layoutContext) { //this.setProperty(Property.TREAT_AS_CONTINUOUS_CONTAINER, Boolean.TRUE); Rectangle actualBBox = layoutContext.GetArea().GetBBox().Clone(); float? blockWidth = RetrieveWidth(actualBBox.GetWidth()); - if (blockWidth != null) { - actualBBox.SetWidth((float)blockWidth); - } ContinuousContainer.SetupContinuousContainerIfNeeded(this); ApplyPaddings(actualBBox, false); ApplyBorderBox(actualBBox, false); ApplyMargins(actualBBox, false); + ApplyWidth(actualBBox, blockWidth, OverflowPropertyValue.VISIBLE); + containerWidth = actualBBox.GetWidth(); float? blockHeight = RetrieveHeight(); if (blockHeight != null && (float)blockHeight < actualBBox.GetHeight()) { actualBBox.SetY(actualBBox.GetY() + actualBBox.GetHeight() - (float)blockHeight); @@ -75,7 +75,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) { .GetHeight())); GridContainerRenderer.GridLayoutResult layoutResult = LayoutGrid(layoutContext, actualBBox, grid); if (layoutResult.GetOverflowRenderers().IsEmpty()) { - this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, true); + this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, true); return new LayoutResult(LayoutResult.FULL, this.occupiedArea, null, null); } else { @@ -84,9 +84,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) { return new LayoutResult(LayoutResult.NOTHING, null, null, this, cause); } else { - this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, grid, false); - return new LayoutResult(LayoutResult.PARTIAL, this.occupiedArea, CreateSplitRenderer(layoutResult.GetSplitRenderers - ()), CreateOverflowRenderer(layoutResult.GetOverflowRenderers())); + this.occupiedArea = CalculateContainerOccupiedArea(layoutContext, false); + return new LayoutResult(LayoutResult.PARTIAL, this.occupiedArea, GridMulticolUtil.CreateSplitRenderer(layoutResult + .GetSplitRenderers(), this), CreateOverflowRenderer(layoutResult.GetOverflowRenderers())); } } } @@ -123,18 +123,6 @@ public override void AddChild(IRenderer renderer) { return false; } - private AbstractRenderer CreateSplitRenderer(IList children) { - AbstractRenderer splitRenderer = (AbstractRenderer)GetNextRenderer(); - splitRenderer.parent = parent; - splitRenderer.modelElement = modelElement; - splitRenderer.occupiedArea = occupiedArea; - splitRenderer.isLastRendererForModelElement = false; - splitRenderer.SetChildRenderers(children); - splitRenderer.AddAllProperties(GetOwnProperties()); - ContinuousContainer.SetupContinuousContainerIfNeeded(splitRenderer); - return splitRenderer; - } - private AbstractRenderer CreateOverflowRenderer(IList children) { iText.Layout.Renderer.GridContainerRenderer overflowRenderer = (iText.Layout.Renderer.GridContainerRenderer )GetNextRenderer(); @@ -246,66 +234,26 @@ private static LayoutContext GetCellLayoutContext(LayoutContext layoutContext, R } // Calculate grid container occupied area based on its width/height properties and cell layout areas - private LayoutArea CalculateContainerOccupiedArea(LayoutContext layoutContext, Grid grid, bool isFull) { + private LayoutArea CalculateContainerOccupiedArea(LayoutContext layoutContext, bool isFull) { LayoutArea area = layoutContext.GetArea().Clone(); - float totalHeight = UpdateOccupiedHeight(containerHeight, isFull); - if (totalHeight < area.GetBBox().GetHeight() || isFull) { - area.GetBBox().SetHeight(totalHeight); - Rectangle initialBBox = layoutContext.GetArea().GetBBox(); - area.GetBBox().SetY(initialBBox.GetY() + initialBBox.GetHeight() - area.GetBBox().GetHeight()); - RecalculateHeightAndWidthAfterLayout(area.GetBBox(), isFull); - } - return area; - } - - // Recalculate height/width after grid sizing and re-apply height/width properties - private void RecalculateHeightAndWidthAfterLayout(Rectangle bBox, bool isFull) { - float? height = RetrieveHeight(); - if (height != null) { - height = UpdateOccupiedHeight((float)height, isFull); - float heightDelta = bBox.GetHeight() - (float)height; - bBox.MoveUp(heightDelta); - bBox.SetHeight((float)height); - } - float? blockWidth = RetrieveWidth(bBox.GetWidth()); - if (blockWidth != null) { - bBox.SetWidth((float)blockWidth); - } - } - - private float UpdateOccupiedHeight(float initialHeight, bool isFull) { - if (isFull) { - initialHeight += SafelyRetrieveFloatProperty(Property.PADDING_BOTTOM); - initialHeight += SafelyRetrieveFloatProperty(Property.MARGIN_BOTTOM); - if (!this.HasOwnProperty(Property.BORDER) || this.GetProperty(Property.BORDER) == null) { - initialHeight += SafelyRetrieveFloatProperty(Property.BORDER_BOTTOM); + Rectangle areaBBox = area.GetBBox(); + float totalContainerHeight = GridMulticolUtil.UpdateOccupiedHeight(containerHeight, isFull, isFirstLayout, + this); + if (totalContainerHeight < areaBBox.GetHeight() || isFull) { + float? height = RetrieveHeight(); + if (height == null) { + areaBBox.SetHeight(totalContainerHeight); + } + else { + height = GridMulticolUtil.UpdateOccupiedHeight((float)height, isFull, isFirstLayout, this); + areaBBox.SetHeight((float)height); } } - initialHeight += SafelyRetrieveFloatProperty(Property.PADDING_TOP); - initialHeight += SafelyRetrieveFloatProperty(Property.MARGIN_TOP); - if (!this.HasOwnProperty(Property.BORDER) || this.GetProperty(Property.BORDER) == null) { - initialHeight += SafelyRetrieveFloatProperty(Property.BORDER_TOP); - } - // isFirstLayout is necessary to handle the case when grid container laid out on more - // than 2 pages, and on the last page layout result is full, but there is no bottom border - float TOP_AND_BOTTOM = isFull && isFirstLayout ? 2 : 1; - //If container laid out on more than 3 pages, then it is a page where there are no bottom and top borders - if (!isFull && !isFirstLayout) { - TOP_AND_BOTTOM = 0; - } - initialHeight += SafelyRetrieveFloatProperty(Property.BORDER) * TOP_AND_BOTTOM; - return initialHeight; - } - - private float SafelyRetrieveFloatProperty(int property) { - Object value = this.GetProperty(property); - if (value is UnitValue) { - return ((UnitValue)value).GetValue(); - } - if (value is Border) { - return ((Border)value).GetWidth(); - } - return 0F; + Rectangle initialBBox = layoutContext.GetArea().GetBBox(); + areaBBox.SetY(initialBBox.GetY() + initialBBox.GetHeight() - areaBBox.GetHeight()); + float totalContainerWidth = GridMulticolUtil.UpdateOccupiedWidth(containerWidth, this); + areaBBox.SetWidth(totalContainerWidth); + return area; } // Grid layout algorithm is based on a https://drafts.csswg.org/css-grid/#layout-algorithm diff --git a/itext/itext.layout/itext/layout/renderer/GridMulticolUtil.cs b/itext/itext.layout/itext/layout/renderer/GridMulticolUtil.cs new file mode 100644 index 0000000000..4766533db9 --- /dev/null +++ b/itext/itext.layout/itext/layout/renderer/GridMulticolUtil.cs @@ -0,0 +1,116 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.Layout.Borders; +using iText.Layout.Properties; + +namespace iText.Layout.Renderer { +//\cond DO_NOT_DOCUMENT + /// The class stores common logic for multicol and grid layout. + internal sealed class GridMulticolUtil { + private GridMulticolUtil() { + } + +//\cond DO_NOT_DOCUMENT + // do nothing + /// Creates a split renderer. + /// children of the split renderer + /// parent renderer + /// + /// a new + /// + /// instance + /// + internal static AbstractRenderer CreateSplitRenderer(IList children, AbstractRenderer renderer) { + AbstractRenderer splitRenderer = (AbstractRenderer)renderer.GetNextRenderer(); + splitRenderer.parent = renderer.parent; + splitRenderer.modelElement = renderer.modelElement; + splitRenderer.occupiedArea = renderer.occupiedArea; + splitRenderer.isLastRendererForModelElement = false; + splitRenderer.SetChildRenderers(children); + splitRenderer.AddAllProperties(renderer.GetOwnProperties()); + ContinuousContainer.SetupContinuousContainerIfNeeded(splitRenderer); + return splitRenderer; + } +//\endcond + +//\cond DO_NOT_DOCUMENT + internal static float UpdateOccupiedWidth(float initialWidth, AbstractRenderer renderer) { + float result = initialWidth; + result += SafelyRetrieveFloatProperty(Property.PADDING_LEFT, renderer); + result += SafelyRetrieveFloatProperty(Property.PADDING_RIGHT, renderer); + result += SafelyRetrieveFloatProperty(Property.MARGIN_LEFT, renderer); + result += SafelyRetrieveFloatProperty(Property.MARGIN_RIGHT, renderer); + if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty(Property.BORDER) == null) { + result += SafelyRetrieveFloatProperty(Property.BORDER_LEFT, renderer); + } + if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty(Property.BORDER) == null) { + result += SafelyRetrieveFloatProperty(Property.BORDER_RIGHT, renderer); + } + result += SafelyRetrieveFloatProperty(Property.BORDER, renderer) * 2; + return result; + } +//\endcond + +//\cond DO_NOT_DOCUMENT + internal static float UpdateOccupiedHeight(float initialHeight, bool isFull, bool isFirstLayout, AbstractRenderer + renderer) { + float result = initialHeight; + if (isFull) { + result += SafelyRetrieveFloatProperty(Property.PADDING_BOTTOM, renderer); + result += SafelyRetrieveFloatProperty(Property.MARGIN_BOTTOM, renderer); + if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty(Property.BORDER) == null) { + result += SafelyRetrieveFloatProperty(Property.BORDER_BOTTOM, renderer); + } + } + result += SafelyRetrieveFloatProperty(Property.PADDING_TOP, renderer); + result += SafelyRetrieveFloatProperty(Property.MARGIN_TOP, renderer); + if (!renderer.HasOwnProperty(Property.BORDER) || renderer.GetProperty(Property.BORDER) == null) { + result += SafelyRetrieveFloatProperty(Property.BORDER_TOP, renderer); + } + // isFirstLayout is necessary to handle the case when multicol container layouted in more + // than 2 pages, and on the last page layout result is full, but there is no bottom border + float TOP_AND_BOTTOM = isFull && isFirstLayout ? 2 : 1; + // Multicol container layouted in more than 3 pages, and there is a page where there are no bottom and top borders + if (!isFull && !isFirstLayout) { + TOP_AND_BOTTOM = 0; + } + result += SafelyRetrieveFloatProperty(Property.BORDER, renderer) * TOP_AND_BOTTOM; + return result; + } +//\endcond + + private static float SafelyRetrieveFloatProperty(int property, AbstractRenderer renderer) { + Object value = renderer.GetProperty(property); + if (value is UnitValue) { + return ((UnitValue)value).GetValue(); + } + if (value is Border) { + return ((Border)value).GetWidth(); + } + return 0F; + } + } +//\endcond +} diff --git a/itext/itext.layout/itext/layout/renderer/GridSizer.cs b/itext/itext.layout/itext/layout/renderer/GridSizer.cs index eb239b5104..16b56eedbd 100644 --- a/itext/itext.layout/itext/layout/renderer/GridSizer.cs +++ b/itext/itext.layout/itext/layout/renderer/GridSizer.cs @@ -143,7 +143,7 @@ private void ResolveGridRows() { private float CalculateGridOccupiedHeight(IList originalSizes) { // Calculate explicit height to ensure that even empty rows which covered by template would be considered float minHeight = 0.0f; - for (int i = 0; i < (templateRows == null ? 0 : templateRows.Count); ++i) { + for (int i = 0; i < (templateRows == null ? 0 : Math.Min(templateRows.Count, originalSizes.Count)); ++i) { minHeight += (float)originalSizes[i]; } float maxHeight = Sum(originalSizes); diff --git a/itext/itext.layout/itext/layout/renderer/GridTemplateResolver.cs b/itext/itext.layout/itext/layout/renderer/GridTemplateResolver.cs index 77b5cff431..c8fab486ce 100644 --- a/itext/itext.layout/itext/layout/renderer/GridTemplateResolver.cs +++ b/itext/itext.layout/itext/layout/renderer/GridTemplateResolver.cs @@ -51,7 +51,7 @@ internal GridTemplateResolver(float space, float gap) { /// Determines if auto-fit repeat was encountered during processing. /// true if auto-fit repeat was encountered, false otherwise internal virtual bool IsCollapseNullLines() { - return autoRepeatResolver != null; + return autoRepeatResolver != null && autoRepeatResolver.repeat.IsAutoFit(); } //\endcond diff --git a/itext/itext.layout/itext/layout/renderer/MulticolRenderer.cs b/itext/itext.layout/itext/layout/renderer/MulticolRenderer.cs index acdca332b2..25b5fded51 100644 --- a/itext/itext.layout/itext/layout/renderer/MulticolRenderer.cs +++ b/itext/itext.layout/itext/layout/renderer/MulticolRenderer.cs @@ -49,6 +49,8 @@ public class MulticolRenderer : AbstractRenderer { private float columnGap; + private float containerWidth; + private bool isFirstLayout = true; /// Creates a DivRenderer from its corresponding layout object. @@ -74,12 +76,13 @@ public override LayoutResult Layout(LayoutContext layoutContext) { SetOverflowForAllChildren(this); Rectangle actualBBox = layoutContext.GetArea().GetBBox().Clone(); float originalWidth = actualBBox.GetWidth(); - ApplyWidth(actualBBox, originalWidth); ContinuousContainer.SetupContinuousContainerIfNeeded(this); ApplyPaddings(actualBBox, false); ApplyBorderBox(actualBBox, false); ApplyMargins(actualBBox, false); - CalculateColumnCountAndWidth(actualBBox.GetWidth()); + ApplyWidth(actualBBox, originalWidth); + containerWidth = actualBBox.GetWidth(); + CalculateColumnCountAndWidth(containerWidth); heightFromProperties = DetermineHeight(actualBBox); if (this.elementRenderer == null) { // initialize elementRenderer on first layout when first child represents renderer of element which @@ -156,6 +159,14 @@ public override void DrawBorder(DrawContext drawContext) { ); } + /// Layouts multicol in the passed area. + /// the layout context + /// the area to layout multicol on + /// + /// the + /// + /// instance + /// protected internal virtual MulticolRenderer.MulticolLayoutResult LayoutInColumns(LayoutContext layoutContext , Rectangle actualBBox) { LayoutResult inifiniteHeighOneColumnLayoutResult = elementRenderer.Layout(new LayoutContext(new LayoutArea @@ -176,16 +187,10 @@ protected internal virtual MulticolRenderer.MulticolLayoutResult LayoutInColumns /// /// instance /// + [System.ObsoleteAttribute(@"use GridMulticolUtil.CreateSplitRenderer(System.Collections.Generic.IList{E}, AbstractRenderer)" + )] protected internal virtual AbstractRenderer CreateSplitRenderer(IList children) { - AbstractRenderer splitRenderer = (AbstractRenderer)GetNextRenderer(); - splitRenderer.parent = parent; - splitRenderer.modelElement = modelElement; - splitRenderer.occupiedArea = occupiedArea; - splitRenderer.isLastRendererForModelElement = false; - splitRenderer.SetChildRenderers(children); - splitRenderer.AddAllProperties(GetOwnProperties()); - ContinuousContainer.SetupContinuousContainerIfNeeded(splitRenderer); - return splitRenderer; + return GridMulticolUtil.CreateSplitRenderer(children, this); } /// Creates an overflow renderer. @@ -258,28 +263,6 @@ private void ApplyWidth(Rectangle parentBbox, float originalWidth) { return height; } - private void RecalculateHeightWidthAfterLayouting(Rectangle parentBBox, bool isFull) { - float? height = DetermineHeight(parentBBox); - if (height != null) { - height = UpdateOccupiedHeight((float)height, isFull); - float heightDelta = parentBBox.GetHeight() - (float)height; - parentBBox.MoveUp(heightDelta); - parentBBox.SetHeight((float)height); - } - ApplyWidth(parentBBox, parentBBox.GetWidth()); - } - - private float SafelyRetrieveFloatProperty(int property) { - Object value = this.GetProperty(property); - if (value is UnitValue) { - return ((UnitValue)value).GetValue(); - } - if (value is Border) { - return ((Border)value).GetWidth(); - } - return 0F; - } - private MulticolRenderer.MulticolLayoutResult BalanceContentAndLayoutColumns(LayoutContext prelayoutContext , Rectangle actualBbox) { float additionalHeightPerIteration; @@ -361,36 +344,22 @@ private void ClearOverFlowRendererIfNeeded(MulticolRenderer.MulticolLayoutResult private LayoutArea CalculateContainerOccupiedArea(LayoutContext layoutContext, bool isFull) { LayoutArea area = layoutContext.GetArea().Clone(); - float totalHeight = UpdateOccupiedHeight(approximateHeight, isFull); - area.GetBBox().SetHeight(totalHeight); - Rectangle initialBBox = layoutContext.GetArea().GetBBox(); - area.GetBBox().SetY(initialBBox.GetY() + initialBBox.GetHeight() - area.GetBBox().GetHeight()); - RecalculateHeightWidthAfterLayouting(area.GetBBox(), isFull); - return area; - } - - private float UpdateOccupiedHeight(float initialHeight, bool isFull) { - if (isFull) { - initialHeight += SafelyRetrieveFloatProperty(Property.PADDING_BOTTOM); - initialHeight += SafelyRetrieveFloatProperty(Property.MARGIN_BOTTOM); - if (!this.HasOwnProperty(Property.BORDER) || this.GetProperty(Property.BORDER) == null) { - initialHeight += SafelyRetrieveFloatProperty(Property.BORDER_BOTTOM); + Rectangle areaBBox = area.GetBBox(); + float totalContainerHeight = GridMulticolUtil.UpdateOccupiedHeight(approximateHeight, isFull, isFirstLayout + , this); + if (totalContainerHeight < areaBBox.GetHeight() || isFull) { + areaBBox.SetHeight(totalContainerHeight); + float? height = DetermineHeight(areaBBox); + if (height != null) { + height = GridMulticolUtil.UpdateOccupiedHeight((float)height, isFull, isFirstLayout, this); + areaBBox.SetHeight((float)height); } } - initialHeight += SafelyRetrieveFloatProperty(Property.PADDING_TOP); - initialHeight += SafelyRetrieveFloatProperty(Property.MARGIN_TOP); - if (!this.HasOwnProperty(Property.BORDER) || this.GetProperty(Property.BORDER) == null) { - initialHeight += SafelyRetrieveFloatProperty(Property.BORDER_TOP); - } - // isFirstLayout is necessary to handle the case when multicol container layouted in more - // than 2 pages, and on the last page layout result is full, but there is no bottom border - float TOP_AND_BOTTOM = isFull && isFirstLayout ? 2 : 1; - // Multicol container layouted in more than 3 pages, and there is a page where there are no bottom and top borders - if (!isFull && !isFirstLayout) { - TOP_AND_BOTTOM = 0; - } - initialHeight += SafelyRetrieveFloatProperty(Property.BORDER) * TOP_AND_BOTTOM; - return initialHeight; + Rectangle initialBBox = layoutContext.GetArea().GetBBox(); + areaBBox.SetY(initialBBox.GetY() + initialBBox.GetHeight() - areaBBox.GetHeight()); + float totalContainerWidth = GridMulticolUtil.UpdateOccupiedWidth(containerWidth, this); + areaBBox.SetWidth(totalContainerWidth); + return area; } private BlockRenderer GetElementsRenderer() { diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs index bbe19e34fe..9b69be2420 100644 --- a/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs @@ -223,6 +223,9 @@ static CommonCssConstants() { /// The Constant DISPLAY. public const String DISPLAY = "display"; + /// The Constant DENSE. + public const String DENSE = "dense"; + /// The Constant EMPTY_CELLS. public const String EMPTY_CELLS = "empty-cells"; @@ -313,6 +316,51 @@ static CommonCssConstants() { /// The Constant GAP. public const String GAP = "gap"; + /// The Constant GRID. + public const String GRID = "grid"; + + /// The Constant GRID_COLUMN. + public const String GRID_COLUMN = "grid-column"; + + /// The Constant GRID_ROW. + public const String GRID_ROW = "grid-row"; + + /// The Constant GRID_TEMPLATE. + public const String GRID_TEMPLATE = "grid-template"; + + /// The Constant GRID_COLUMN_END. + public const String GRID_COLUMN_END = "grid-column-end"; + + /// The Constant GRID_COLUMN_START. + public const String GRID_COLUMN_START = "grid-column-start"; + + /// The Constant GRID_ROW_END. + public const String GRID_ROW_END = "grid-row-end"; + + /// The Constant GRID_ROW_START. + public const String GRID_ROW_START = "grid-row-start"; + + /// The Constant GRID_TEMPLATE_AREAS. + public const String GRID_TEMPLATE_AREAS = "grid-template-areas"; + + /// The Constant GRID_TEMPLATE_COLUMNS. + public const String GRID_TEMPLATE_COLUMNS = "grid-template-columns"; + + /// The Constant GRID_TEMPLATE_ROWS. + public const String GRID_TEMPLATE_ROWS = "grid-template-rows"; + + /// The Constant GRID_AUTO_ROWS. + public const String GRID_AUTO_ROWS = "grid-auto-rows"; + + /// The Constant GRID_AUTO_COLUMNS. + public const String GRID_AUTO_COLUMNS = "grid-auto-columns"; + + /// The Constant GRID_AUTO_FLOW. + public const String GRID_AUTO_FLOW = "grid-auto-flow"; + + /// The Constant AUTO_FLOW. + public const String AUTO_FLOW = "auto-flow"; + /// The Constant HANGING_PUNCTUATION. public const String HANGING_PUNCTUATION = "hanging-punctuation"; diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs index 64497aa1f4..7477334e5d 100644 --- a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs @@ -56,6 +56,10 @@ static ShorthandResolverFactory() { shorthandResolvers.Put(CommonCssConstants.PLACE_ITEMS, new PlaceItemsShorthandResolver()); shorthandResolvers.Put(CommonCssConstants.COLUMNS, new ColumnsShorthandResolver()); shorthandResolvers.Put(CommonCssConstants.COLUMN_RULE, new ColumnRuleShortHandResolver()); + shorthandResolvers.Put(CommonCssConstants.GRID_ROW, new GridRowShorthandResolver()); + shorthandResolvers.Put(CommonCssConstants.GRID_COLUMN, new GridColumnShorthandResolver()); + shorthandResolvers.Put(CommonCssConstants.GRID_TEMPLATE, new GridTemplateShorthandResolver()); + shorthandResolvers.Put(CommonCssConstants.GRID, new GridShorthandResolver()); } /// Gets a shorthand resolver. diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridColumnShorthandResolver.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridColumnShorthandResolver.cs new file mode 100644 index 0000000000..15799a7a7a --- /dev/null +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridColumnShorthandResolver.cs @@ -0,0 +1,36 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using iText.StyledXmlParser.Css; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + /// + /// + /// implementation for grid-column shorthand. + /// + public class GridColumnShorthandResolver : GridItemShorthandResolver { + /// Creates a shorthand resolver for grid-column property + public GridColumnShorthandResolver() + : base(CommonCssConstants.GRID_COLUMN) { + } + } +} diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridItemShorthandResolver.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridItemShorthandResolver.cs new file mode 100644 index 0000000000..56c02a4c91 --- /dev/null +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridItemShorthandResolver.cs @@ -0,0 +1,73 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.Logging; +using iText.Commons; +using iText.Commons.Utils; +using iText.StyledXmlParser.Css; +using iText.StyledXmlParser.Css.Resolve.Shorthand; +using iText.StyledXmlParser.Css.Util; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + /// + /// + /// implementation for grid items column/row start and end positions. + /// + public abstract class GridItemShorthandResolver : IShorthandResolver { + private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(iText.StyledXmlParser.Css.Resolve.Shorthand.Impl.GridItemShorthandResolver + )); + + private readonly String propertyTemplate; + + /// Creates a new shorthand resolver for provided shorthand template + /// shorthand from which template will be created. + protected internal GridItemShorthandResolver(String shorthand) { + this.propertyTemplate = shorthand + "-{0}"; + } + + public virtual IList ResolveShorthand(String shorthandExpression) { + shorthandExpression = shorthandExpression.Trim(); + if (String.IsNullOrEmpty(shorthandExpression)) { + LOGGER.LogWarning(MessageFormatUtil.Format(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY + , propertyTemplate.JSubstring(0, propertyTemplate.Length - 4))); + return new List(); + } + if (CssTypesValidationUtils.IsInitialOrInheritOrUnset(shorthandExpression) || CommonCssConstants.AUTO.Equals + (shorthandExpression)) { + return new List(); + } + String[] values = iText.Commons.Utils.StringUtil.Split(shorthandExpression, "/"); + if (values.Length == 1) { + if (shorthandExpression.StartsWith("span")) { + return JavaCollectionsUtil.SingletonList(new CssDeclaration(MessageFormatUtil.Format(propertyTemplate, "start" + ), values[0])); + } + return JavaUtil.ArraysAsList(new CssDeclaration(MessageFormatUtil.Format(propertyTemplate, "start"), values + [0]), new CssDeclaration(MessageFormatUtil.Format(propertyTemplate, "end"), values[0])); + } + return JavaUtil.ArraysAsList(new CssDeclaration(MessageFormatUtil.Format(propertyTemplate, "start"), values + [0]), new CssDeclaration(MessageFormatUtil.Format(propertyTemplate, "end"), values[1])); + } + } +} diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridRowShorthandResolver.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridRowShorthandResolver.cs new file mode 100644 index 0000000000..fba86e22af --- /dev/null +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridRowShorthandResolver.cs @@ -0,0 +1,36 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using iText.StyledXmlParser.Css; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + /// + /// + /// implementation for grid-row shorthand. + /// + public class GridRowShorthandResolver : GridItemShorthandResolver { + /// Creates a shorthand resolver for grid-row property + public GridRowShorthandResolver() + : base(CommonCssConstants.GRID_ROW) { + } + } +} diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridShorthandResolver.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridShorthandResolver.cs new file mode 100644 index 0000000000..8d36048868 --- /dev/null +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridShorthandResolver.cs @@ -0,0 +1,73 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using iText.StyledXmlParser.Css; +using iText.StyledXmlParser.Css.Resolve.Shorthand; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + /// + /// + /// implementation for grid shorthand. + /// + public class GridShorthandResolver : IShorthandResolver { + /// + public virtual IList ResolveShorthand(String shorthandExpression) { + if (!shorthandExpression.Contains(CommonCssConstants.AUTO_FLOW)) { + return new GridTemplateShorthandResolver().ResolveShorthand(shorthandExpression); + } + String[] values = iText.Commons.Utils.StringUtil.Split(shorthandExpression.Trim(), "/"); + IList result = new List(); + if (values[0].Contains(CommonCssConstants.AUTO_FLOW)) { + if (values[0].Contains(CommonCssConstants.DENSE)) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_AUTO_FLOW, CommonCssConstants.DENSE)); + } + String rowsTemplate = values[0].Substring(Math.Max(values[0].IndexOf(CommonCssConstants.AUTO_FLOW, StringComparison.Ordinal + ) + CommonCssConstants.AUTO_FLOW.Length, values[0].IndexOf(CommonCssConstants.DENSE, StringComparison.Ordinal + ) + CommonCssConstants.DENSE.Length)); + if (!String.IsNullOrEmpty(rowsTemplate.Trim())) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_AUTO_ROWS, rowsTemplate)); + } + if (values.Length == 2) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_TEMPLATE_COLUMNS, values[1])); + } + } + else { + if (values.Length == 2) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_TEMPLATE_ROWS, values[0])); + if (values[1].Contains(CommonCssConstants.DENSE)) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_AUTO_FLOW, CommonCssConstants.COLUMN + " " + CommonCssConstants + .DENSE)); + } + String columnsTemplate = values[1].Substring(Math.Max(values[1].IndexOf(CommonCssConstants.AUTO_FLOW, StringComparison.Ordinal + ) + CommonCssConstants.AUTO_FLOW.Length, values[1].IndexOf(CommonCssConstants.DENSE, StringComparison.Ordinal + ) + CommonCssConstants.DENSE.Length)); + if (!String.IsNullOrEmpty(columnsTemplate.Trim())) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_AUTO_COLUMNS, columnsTemplate)); + } + } + } + return result; + } + } +} diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridTemplateShorthandResolver.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridTemplateShorthandResolver.cs new file mode 100644 index 0000000000..2480dbd91f --- /dev/null +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GridTemplateShorthandResolver.cs @@ -0,0 +1,105 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.Extensions.Logging; +using iText.Commons; +using iText.Commons.Utils; +using iText.StyledXmlParser.Css; +using iText.StyledXmlParser.Css.Parse; +using iText.StyledXmlParser.Css.Resolve.Shorthand; +using iText.StyledXmlParser.Css.Util; + +namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + /// + /// + /// implementation for grid-template shorthand. + /// + public class GridTemplateShorthandResolver : IShorthandResolver { + /// Creates grid template shorthand resolver. + public GridTemplateShorthandResolver() { + } + + private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(iText.StyledXmlParser.Css.Resolve.Shorthand.Impl.GridTemplateShorthandResolver + )); + + /// + public virtual IList ResolveShorthand(String shorthandExpression) { + shorthandExpression = shorthandExpression.Trim(); + if (String.IsNullOrEmpty(shorthandExpression)) { + LOGGER.LogWarning(MessageFormatUtil.Format(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY + , CommonCssConstants.GRID_TEMPLATE)); + return new List(); + } + if (CssTypesValidationUtils.IsInitialOrInheritOrUnset(shorthandExpression) || CommonCssConstants.AUTO.Equals + (shorthandExpression) || CommonCssConstants.NONE.Equals(shorthandExpression)) { + return new List(); + } + StringBuilder rowsTemplateBuilder = new StringBuilder(); + StringBuilder areasBuilder = new StringBuilder(); + String columnsTemplate = ""; + String[] values = iText.Commons.Utils.StringUtil.Split(shorthandExpression, "/"); + if (values.Length == 2) { + columnsTemplate = values[1]; + } + CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(values[0]); + CssDeclarationValueTokenizer.Token token; + bool templateRowsEncountered = false; + bool previousTokenIsArea = false; + for (int i = 0; ((token = tokenizer.GetNextValidToken()) != null); ++i) { + if (token.IsString() && !token.GetValue().StartsWith("[")) { + if (previousTokenIsArea) { + rowsTemplateBuilder.Append(CommonCssConstants.AUTO).Append(" "); + } + areasBuilder.Append("'").Append(token.GetValue()).Append("'").Append(" "); + previousTokenIsArea = true; + } + else { + rowsTemplateBuilder.Append(token.GetValue()).Append(" "); + templateRowsEncountered = true; + previousTokenIsArea = false; + } + } + if (previousTokenIsArea) { + rowsTemplateBuilder.Append(CommonCssConstants.AUTO).Append(" "); + } + if (!templateRowsEncountered) { + rowsTemplateBuilder.Length = 0; + } + String rowsTemplate = rowsTemplateBuilder.ToString(); + String areas = areasBuilder.ToString(); + IList result = new List(3); + if (!String.IsNullOrEmpty(rowsTemplate)) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_TEMPLATE_ROWS, rowsTemplate)); + } + if (!String.IsNullOrEmpty(columnsTemplate)) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_TEMPLATE_COLUMNS, columnsTemplate)); + } + if (!String.IsNullOrEmpty(areas)) { + result.Add(new CssDeclaration(CommonCssConstants.GRID_TEMPLATE_AREAS, areas)); + } + return result; + } + } +} diff --git a/port-hash b/port-hash index 69ab66ba16..37b22e7623 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -bba9f55da2ea35bf2b2f5bc3da9e49c2414a7285 +ca150c317a7bf138f31ac93c5e2e8542aa7ba789