From 8ade2913926f99a8fc4daf8b5dc95f018780ce21 Mon Sep 17 00:00:00 2001 From: Vitali Prudnikovich Date: Tue, 9 Jul 2024 10:47:41 +0000 Subject: [PATCH 1/2] Fix LayoutExceptionMessageConstant.INVALID_CELL_INDEXES exception DEVSIX-8427 Autoported commit. Original commit hash: [14594176c] --- .../itext/layout/element/GridContainerTest.cs | 54 +++++++++++++++--- .../cmp_coverExistingItemTest.pdf | Bin 0 -> 1521 bytes .../cmp_overlapWithExistingItemTest.pdf | Bin 0 -> 1505 bytes .../LayoutExceptionMessageConstant.cs | 2 - .../itext/layout/renderer/Grid.cs | 19 ++++-- .../layout/renderer/GridContainerRenderer.cs | 18 +++--- .../itext/layout/renderer/GridItemRenderer.cs | 21 ++++--- port-hash | 2 +- 8 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_coverExistingItemTest.pdf create mode 100644 itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_overlapWithExistingItemTest.pdf 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 4ad4172402..1432c8314c 100644 --- a/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs @@ -28,7 +28,6 @@ You should have received a copy of the GNU Affero General Public License using iText.Kernel.Utils; using iText.Layout; using iText.Layout.Borders; -using iText.Layout.Exceptions; using iText.Layout.Properties; using iText.Layout.Properties.Grid; using iText.Test; @@ -344,12 +343,48 @@ public virtual void FixedColumnRowGoesFirstTest() { } [NUnit.Framework.Test] - public virtual void OverlapWithExistingColumnTest() { - String filename = DESTINATION_FOLDER + "overlapWithExistingColumnTest.pdf"; + public virtual void OverlapWithExistingItemTest() { + String filename = DESTINATION_FOLDER + "overlapWithExistingItemTest.pdf"; + String cmpName = SOURCE_FOLDER + "cmp_overlapWithExistingItemTest.pdf"; IList templateColumns = new List(); - templateColumns.Add(new PointValue(100.0f)); - templateColumns.Add(new PointValue(100.0f)); - templateColumns.Add(new PointValue(100.0f)); + templateColumns.Add(MinContentValue.VALUE); + templateColumns.Add(MinContentValue.VALUE); + templateColumns.Add(MinContentValue.VALUE); + using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { + GridContainer grid = new GridContainer(); + SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); + grid.SetProperty(Property.GRID_TEMPLATE_COLUMNS, templateColumns); + Paragraph paragraph1 = new Paragraph("Two"); + paragraph1.SetProperty(Property.GRID_COLUMN_START, 1); + paragraph1.SetProperty(Property.GRID_COLUMN_END, 3); + paragraph1.SetProperty(Property.GRID_ROW_START, 1); + paragraph1.SetProperty(Property.GRID_ROW_END, 3); + paragraph1.SetBorder(border); + grid.Add(paragraph1); + grid.Add(new Paragraph("Three").SetBorder(border)); + grid.Add(new Paragraph("Four").SetBorder(border)); + grid.Add(new Paragraph("Five").SetBorder(border)); + Paragraph paragraph2 = new Paragraph("One (long content)"); + paragraph2.SetProperty(Property.GRID_COLUMN_START, 1); + paragraph2.SetProperty(Property.GRID_COLUMN_END, 2); + paragraph2.SetProperty(Property.GRID_ROW_START, 1); + paragraph2.SetProperty(Property.GRID_ROW_END, 2); + paragraph2.SetBorder(border); + grid.Add(paragraph2); + document.Add(grid); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_" + )); + } + + [NUnit.Framework.Test] + public virtual void CoverExistingItemTest() { + String filename = DESTINATION_FOLDER + "coverExistingItemTest.pdf"; + String cmpName = SOURCE_FOLDER + "cmp_coverExistingItemTest.pdf"; + IList templateColumns = new List(); + templateColumns.Add(MinContentValue.VALUE); + templateColumns.Add(MinContentValue.VALUE); + templateColumns.Add(MinContentValue.VALUE); using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { GridContainer grid = new GridContainer(); SolidBorder border = new SolidBorder(ColorConstants.BLUE, 1); @@ -364,16 +399,17 @@ public virtual void OverlapWithExistingColumnTest() { grid.Add(new Paragraph("Three").SetBorder(border)); grid.Add(new Paragraph("Four").SetBorder(border)); grid.Add(new Paragraph("Five").SetBorder(border)); - Paragraph paragraph2 = new Paragraph("One"); + Paragraph paragraph2 = new Paragraph("One (long content)"); paragraph2.SetProperty(Property.GRID_COLUMN_START, 1); paragraph2.SetProperty(Property.GRID_COLUMN_END, 3); paragraph2.SetProperty(Property.GRID_ROW_START, 1); paragraph2.SetProperty(Property.GRID_ROW_END, 3); paragraph2.SetBorder(border); grid.Add(paragraph2); - Exception e = NUnit.Framework.Assert.Catch(typeof(ArgumentException), () => document.Add(grid)); - NUnit.Framework.Assert.AreEqual(LayoutExceptionMessageConstant.INVALID_CELL_INDEXES, e.Message); + document.Add(grid); } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_" + )); } [NUnit.Framework.Test] diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_coverExistingItemTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_coverExistingItemTest.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1487e68af26ae07663447caf9488a9a5ce6adaf4 GIT binary patch literal 1521 zcmc&!YfKbZ6mB7|I;9P1N|9KSOXDgOmU-{aDBbc{UXho}R*bN=^SBE`ml--Uiz^!2 zA_c8!z(*e>Ad*^JwZ%X|P3yBp`@-^rt)UNu>JN*i;g4dAsGZrOw3761&ySgV&zy7a zIp6o)v6i@UY;H)wn;5cp7I_)l>W;4t zj}Dw9zOj}~*YPhOd*`i})(j!Pe_y%(!xd#$;&i6*aPH)n-P>AIEnD$VTcg?Y!)bco z@n;s^X#LLPh{(m~*_yJ)8x}75?b`l}L`n*1iQhP!)cxG0_^X2#kw-3_=qbEK`oAci z4Eb%)s!6HR`lYTfy^ai zc>!;0hb5Gfx@rMPxfR!Ted6d@Ze;xjCnC_Y*v|-jjBWmh-q*orFe6=g{{L~?;eyVL9bZi>=IJa%7<+$aAePcbF8_#@R zd-AT{;t=aQ>M_A8miMce2yhY>{@cS`Rkvf^87bXzj5yU z>7E}tZ~qv2eDD+RzLqVK7urvbwm09saqn$k`yz5Q7(aEp>(sj7XW5$+dX~0l~7cJpbBL)!R5I5A6fGR-ERF9Eu zzHneSzc~# zX0S|7gC<639`x5iT@pAnTQ)A4Bv+zklAIxH(t~|zfY(iw%%XVs8HRVZt_lBrz?6W& z2ac|kM6KLp)9w8`Bi!9=N>GJ91OpDlm~qB{ou)||_`rQ1LmGum1M&kOYd7TZkk4*6 zH1Uv+CLD8o7(O?bar`4rS2@WKRrBwY?*ip%P~-*D2SvzpB+rnv50W_U6IeS39Rx4( zB8k%!WFU`0A1w+Z3t56BX-*JDg0>T^gTq;lQauC?gHLN%(l%4k Ywtp)c(R5DL!$jj4Zbz)v?BX2cFRVibQ~&?~ literal 0 HcmV?d00001 diff --git a/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_overlapWithExistingItemTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_overlapWithExistingItemTest.pdf new file mode 100644 index 0000000000000000000000000000000000000000..1aecbe067bc6247859f27158dba63b8c9d69b7de GIT binary patch literal 1505 zcmc&!Yitx%7)4^C8QTU$V=1PYVwY|;+qtv5v%6E;P4__`>3h3M%C@QVxKpMqJ9TE3 zK5av!NI)JnPzl9^7HWZ10!6J>(u$3?G>xDIH4TwsiBw4uBm_|#yt5WoOX6Q|CNp=w z`R;emch0$^D{^NV$P_E4`(f(bI7ZK95_vFCsjkD# zM%r#yR2ecGu-XG3>`5;i0!y~k+{bp!uz$8roZaSLvw6?SL34@(a_AiKFM+o=Dx@X6l-`=U#i|%U|mY7EcYvk1VB=oc*zQrkZzT zgzRkTICMtUpLcEXeIMB)CXbaoJNEc8&+{jSM>hTR+|_}k8lR)(@a&nUfbZR>XDUXH z-QWMs?5euy?J@jY?#R!b&V;yzwys#Y_)RtaU>+CyZL1I$?OMD!r}*F-QT8BTU#zT* zJhgE2W5b^S|@*L*B~n-goSRU*EUmO2?wU!>6Zr zzCQD#7=6!KvE-?J{Y&%I)}yOphPE28jI;4@#|n16fZbkLb#2q9`})_Vef^5(QnT7! zdg|5vgRgaNzeyY)n0&HXxicAq{g$1dn~-%Wp<(TUtsm7-9vS_xsrt_FSKInKGbVnn zQQjMiX8Ka|r*7R{-hTay*oLXPIO306y}seggO8o7ZCQ`O06(W2nrS+l!+N`Yu zf@>b|5c!Z78K+e11L&2aDcoi@mJ>ycjB;>eD8&O6DJXML(cFSoYY!5)Xy5E;5MEi_ z@JI!3T{T2yDxux3!O=jN(26GbYYBQTnQ71#hx0ki2vU`hfYDVfNZ z`2S8Qk|jRKL0K<)VXb-`cS$nDZ7CpyGL#fJib}Ezy?B}4kyVt3Z-lafHY`iVj~W30 z25n2+Q7zXg5YLjOU^QOwa&j0e8OEwLq0CVc>dM8aj9;n@Cu>y9HRfa#sBuJOL;pso ziX20%4xmFN1}cd)V!#nl#E0)CK~~jR(u$Iydx+j}U5)++gh@f92TA0LyyDZ;^pyX- zB7`oyq*jIk25>8edYl`$g`!LpF5nMhHWC5W1|E1Aqs{aqF^d^(G%t@L5i|2*fJ9cB z7qeOZk*CUx=!dfQx5;tizBHDjEgVA$5RfcmvRZ6_69k5~@hr;;lwbi21$oxU0(1cj zBqStyt(3N_1GS-?ZiWaKO~P4g5Za5S(0 zlMQ*x$|7X;{~tj)krNOkTssmT!XrsY+t9Q`tcSQ2>8T4@+Mqew@NY+Bipt1pNN5tV Mj_Gu(3p26507*Xp&;S4c literal 0 HcmV?d00001 diff --git a/itext/itext.layout/itext/layout/exceptions/LayoutExceptionMessageConstant.cs b/itext/itext.layout/itext/layout/exceptions/LayoutExceptionMessageConstant.cs index 0085777eb1..18613acbfc 100644 --- a/itext/itext.layout/itext/layout/exceptions/LayoutExceptionMessageConstant.cs +++ b/itext/itext.layout/itext/layout/exceptions/LayoutExceptionMessageConstant.cs @@ -59,8 +59,6 @@ public sealed class LayoutExceptionMessageConstant { public const String INVALID_COLUMN_PROPERTIES = "Invalid column-count/column-width/column-gap properties, they're absent or have negative value"; - public const String INVALID_CELL_INDEXES = "Invalid grid-column/grid-row properties, cells overlapping"; - public const String INVALID_FONT_PROPERTY_VALUE = "Invalid FONT property value type."; public const String TAGGING_HINTKEY_SHOULD_HAVE_ACCES = "TaggingHintKey should have accessibility properties"; diff --git a/itext/itext.layout/itext/layout/renderer/Grid.cs b/itext/itext.layout/itext/layout/renderer/Grid.cs index 4b39123fa9..10a0f5cbda 100644 --- a/itext/itext.layout/itext/layout/renderer/Grid.cs +++ b/itext/itext.layout/itext/layout/renderer/Grid.cs @@ -24,7 +24,6 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using System.Linq; using iText.Commons.Utils; -using iText.Layout.Exceptions; using iText.Layout.Properties.Grid; namespace iText.Layout.Renderer { @@ -42,6 +41,8 @@ internal class Grid { //Using array list instead of array for .NET portability private readonly IList> uniqueCells = new List>(2); + private readonly IList itemsWithoutPlace = new List(); + //\cond DO_NOT_DOCUMENT /// Creates a new grid instance. /// initial number of row for the grid @@ -138,6 +139,7 @@ internal virtual ICollection GetUniqueGridCells(Grid.GridOrder iterati } } } + result.AddAll(itemsWithoutPlace); uniqueCells[(int)(iterationOrder)] = result; return result; } @@ -149,6 +151,7 @@ internal virtual ICollection GetUniqueGridCells(Grid.GridOrder iterati } } } + result.AddAll(itemsWithoutPlace); uniqueCells[(int)(iterationOrder)] = result; return result; } @@ -224,11 +227,18 @@ internal virtual int CollapseNullLines(Grid.GridOrder order, int minSize) { /// Add cell in the grid, checking that it would fit and initializing it bottom left corner (x, y). /// cell to and in the grid private void AddCell(GridCell cell) { + bool placeFound = false; for (int i = cell.GetRowStart(); i < cell.GetRowEnd(); ++i) { for (int j = cell.GetColumnStart(); j < cell.GetColumnEnd(); ++j) { - rows[i][j] = cell; + if (rows[i][j] == null) { + rows[i][j] = cell; + placeFound = true; + } } } + if (!placeFound) { + itemsWithoutPlace.Add(cell); + } } private int DetermineNullLinesStart(Grid.GridOrder order) { @@ -471,9 +481,10 @@ internal virtual void Fit(GridCell cell) { //Move grid view cursor pos = view.Next(); } - //If cell restricts both x and y position grow and can't be fitted on a grid, throw an excpetion + // If cell restricts both x and y position grow and can't be fitted on a grid, + // exit occupying fixed position if (view.IsFixed()) { - throw new ArgumentException(LayoutExceptionMessageConstant.INVALID_CELL_INDEXES); + break; } //If cell was not fitted while iterating grid, then there is not enough space to fit it, and grid //has to be resized diff --git a/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs b/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs index 55f1c52834..380412e436 100644 --- a/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs +++ b/itext/itext.layout/itext/layout/renderer/GridContainerRenderer.cs @@ -93,6 +93,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) { /// public override void AddChild(IRenderer renderer) { + // The grid's items are not affected by the 'float' and 'clear' properties. + // Still let clear them on renderer level not model element + renderer.SetProperty(Property.FLOAT, null); renderer.SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.VISIBLE); renderer.SetProperty(Property.OVERFLOW_Y, OverflowPropertyValue.VISIBLE); renderer.SetProperty(Property.COLLAPSING_MARGINS, DetermineCollapsingMargins(renderer)); @@ -171,20 +174,19 @@ private GridContainerRenderer.GridLayoutResult LayoutGrid(LayoutContext layoutCo private static int ProcessLayoutResult(GridContainerRenderer.GridLayoutResult layoutResult, GridCell cell, LayoutResult cellResult) { - IRenderer cellToRenderer = cell.GetValue(); + IRenderer overflowRenderer = cellResult.GetOverflowRenderer(); if (cellResult.GetStatus() == LayoutResult.NOTHING) { - cellToRenderer.SetProperty(Property.GRID_COLUMN_START, cell.GetColumnStart() + 1); - cellToRenderer.SetProperty(Property.GRID_COLUMN_END, cell.GetColumnEnd() + 1); - cellToRenderer.SetProperty(Property.GRID_ROW_START, cell.GetRowStart() + 1); - cellToRenderer.SetProperty(Property.GRID_ROW_END, cell.GetRowEnd() + 1); - layoutResult.GetOverflowRenderers().Add(cellToRenderer); + overflowRenderer.SetProperty(Property.GRID_COLUMN_START, cell.GetColumnStart() + 1); + overflowRenderer.SetProperty(Property.GRID_COLUMN_END, cell.GetColumnEnd() + 1); + overflowRenderer.SetProperty(Property.GRID_ROW_START, cell.GetRowStart() + 1); + overflowRenderer.SetProperty(Property.GRID_ROW_END, cell.GetRowEnd() + 1); + layoutResult.GetOverflowRenderers().Add(overflowRenderer); layoutResult.SetCauseOfNothing(cellResult.GetCauseOfNothing()); return cell.GetRowStart(); } // PARTIAL + FULL result handling - layoutResult.GetSplitRenderers().Add(cellToRenderer); + layoutResult.GetSplitRenderers().Add(cell.GetValue()); if (cellResult.GetStatus() == LayoutResult.PARTIAL) { - IRenderer overflowRenderer = cellResult.GetOverflowRenderer(); overflowRenderer.SetProperty(Property.GRID_COLUMN_START, cell.GetColumnStart() + 1); overflowRenderer.SetProperty(Property.GRID_COLUMN_END, cell.GetColumnEnd() + 1); int rowStart = cell.GetRowStart() + 1; diff --git a/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs b/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs index 24c6175693..3a56f7775c 100644 --- a/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs +++ b/itext/itext.layout/itext/layout/renderer/GridItemRenderer.cs @@ -70,7 +70,14 @@ public override T1 GetProperty(int key) { case Property.GRID_ROW_START: case Property.GRID_ROW_END: case Property.GRID_ROW_SPAN: { - return renderer.GetProperty(key); + T1 ownValue = this.GetOwnProperty(key); + if (ownValue != null) { + return ownValue; + } + else { + return renderer.GetProperty(key); + } + goto default; } default: { @@ -93,18 +100,18 @@ public override void SetProperty(int property, Object value) { break; } - case Property.FILL_AVAILABLE_AREA: + case Property.FILL_AVAILABLE_AREA: { + renderer.SetProperty(property, value); + break; + } + + case Property.COLLAPSING_MARGINS: case Property.GRID_COLUMN_START: case Property.GRID_COLUMN_END: case Property.GRID_COLUMN_SPAN: case Property.GRID_ROW_START: case Property.GRID_ROW_END: case Property.GRID_ROW_SPAN: { - renderer.SetProperty(property, value); - break; - } - - case Property.COLLAPSING_MARGINS: { base.SetProperty(property, value); break; } diff --git a/port-hash b/port-hash index 0c73e6bc49..72eaa47852 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -e054c7abf957145ef4dcd2d3a8628b7c8bf24b7a +14594176c3df587ff53e54994152bf09ca64d596 From c6432b397bf2425d0e642a242351fd2f94c699a2 Mon Sep 17 00:00:00 2001 From: Dmitry Chubrick Date: Tue, 9 Jul 2024 15:58:19 +0000 Subject: [PATCH 2/2] Support grid-gap, grid-column-gap and grid-row-gap and log unsupported properties DEVSIX-8376 Autoported commit. Original commit hash: [5a8f86d5e] --- .../shorthand/GapShorthandResolverTest.cs | 12 ++++++ .../CssDeclarationValidationMasterTest.cs | 18 +++++++++ .../pdf/canvas/parser/data/ImageRenderInfo.cs | 2 +- .../styledxmlparser/css/CommonCssConstants.cs | 9 +++++ .../shorthand/ShorthandResolverFactory.cs | 3 +- .../shorthand/impl/GapShorthandResolver.cs | 39 +++++++++++++++++-- .../css/validate/impl/CssDefaultValidator.cs | 10 +++-- port-hash | 2 +- 8 files changed, 84 insertions(+), 11 deletions(-) diff --git a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/GapShorthandResolverTest.cs b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/GapShorthandResolverTest.cs index 29fa43ce56..79c75e2ca2 100644 --- a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/GapShorthandResolverTest.cs +++ b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/GapShorthandResolverTest.cs @@ -131,6 +131,18 @@ public virtual void GapWithTwoValidValuesTest() { NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression()); } + [NUnit.Framework.Test] + public virtual void GridGapWithTwoValidValuesTest() { + IShorthandResolver resolver = new GapShorthandResolver(CommonCssConstants.GRID_GAP); + String shorthand = "10px 15px"; + IList resolvedShorthand = resolver.ResolveShorthand(shorthand); + NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.ROW_GAP, resolvedShorthand[0].GetProperty()); + NUnit.Framework.Assert.AreEqual("10px", resolvedShorthand[0].GetExpression()); + NUnit.Framework.Assert.AreEqual(CommonCssConstants.COLUMN_GAP, resolvedShorthand[1].GetProperty()); + NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression()); + } + [NUnit.Framework.Test] [LogMessage(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION)] public virtual void GapWithValidAndInvalidValuesTest() { diff --git a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/validate/CssDeclarationValidationMasterTest.cs b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/validate/CssDeclarationValidationMasterTest.cs index 1e8a5d7312..66af6da2ad 100644 --- a/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/validate/CssDeclarationValidationMasterTest.cs +++ b/itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/validate/CssDeclarationValidationMasterTest.cs @@ -426,6 +426,24 @@ public virtual void MulticolValidationTest() { .COLUMN_GAP, "10"))); } + [NUnit.Framework.Test] + public virtual void GridRowColumnGapTest() { + NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_ROW_GAP, "normal"))); + NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_COLUMN_GAP, "30px"))); + NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_ROW_GAP, "15%"))); + NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_ROW_GAP, "2em"))); + NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_COLUMN_GAP, "3rem"))); + NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_COLUMN_GAP, "-5em"))); + NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants + .GRID_ROW_GAP, "10"))); + } + [NUnit.Framework.Test] public virtual void ChangeValidatorTest() { try { diff --git a/itext/itext.kernel/itext/kernel/pdf/canvas/parser/data/ImageRenderInfo.cs b/itext/itext.kernel/itext/kernel/pdf/canvas/parser/data/ImageRenderInfo.cs index fb6fc08be2..c69e86f5ff 100644 --- a/itext/itext.kernel/itext/kernel/pdf/canvas/parser/data/ImageRenderInfo.cs +++ b/itext/itext.kernel/itext/kernel/pdf/canvas/parser/data/ImageRenderInfo.cs @@ -96,7 +96,7 @@ public ImageRenderInfo(Stack canvasTagHierarchy, CanvasGraphicsState /// /// with /// - /// ; + /// ; // Android-Conversion-Skip-Line (java.awt library isn't available on Android) /// /// /// diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs index 9b69be2420..9ae275d296 100644 --- a/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs @@ -331,12 +331,21 @@ static CommonCssConstants() { /// The Constant GRID_COLUMN_END. public const String GRID_COLUMN_END = "grid-column-end"; + /// The Constant GRID_COLUMN_GAP. + public const String GRID_COLUMN_GAP = "grid-column-gap"; + /// The Constant GRID_COLUMN_START. public const String GRID_COLUMN_START = "grid-column-start"; + /// The Constant GRID_GAP. + public const String GRID_GAP = "grid-gap"; + /// The Constant GRID_ROW_END. public const String GRID_ROW_END = "grid-row-end"; + /// The Constant GRID_ROW_GAP. + public const String GRID_ROW_GAP = "grid-row-gap"; + /// The Constant GRID_ROW_START. public const String GRID_ROW_START = "grid-row-start"; 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 7477334e5d..b63a108341 100644 --- a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs @@ -52,7 +52,8 @@ static ShorthandResolverFactory() { shorthandResolvers.Put(CommonCssConstants.TEXT_DECORATION, new TextDecorationShorthandResolver()); shorthandResolvers.Put(CommonCssConstants.FLEX, new FlexShorthandResolver()); shorthandResolvers.Put(CommonCssConstants.FLEX_FLOW, new FlexFlowShorthandResolver()); - shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver()); + shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver(CommonCssConstants.GAP)); + shorthandResolvers.Put(CommonCssConstants.GRID_GAP, new GapShorthandResolver(CommonCssConstants.GRID_GAP)); shorthandResolvers.Put(CommonCssConstants.PLACE_ITEMS, new PlaceItemsShorthandResolver()); shorthandResolvers.Put(CommonCssConstants.COLUMNS, new ColumnsShorthandResolver()); shorthandResolvers.Put(CommonCssConstants.COLUMN_RULE, new ColumnRuleShortHandResolver()); diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GapShorthandResolver.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GapShorthandResolver.cs index f78652b3ac..5cca4d3cc8 100644 --- a/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GapShorthandResolver.cs +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GapShorthandResolver.cs @@ -31,8 +31,39 @@ You should have received a copy of the GNU Affero General Public License using iText.StyledXmlParser.Css.Validate; namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl { + /// + /// Shorthand resolver for gap shorthand properties, can be used for + /// different gap properties like + /// gap + /// or + /// grid-gap. + /// public class GapShorthandResolver : IShorthandResolver { - private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(GapShorthandResolver)); + private readonly String gapShorthandProperty; + + /// + /// Instantiates default + /// + /// for + /// gap + /// shorthand. + /// + public GapShorthandResolver() + : this(CommonCssConstants.GAP) { + } + + /// + /// Instantiates default + /// + /// for passed gap shorthand. + /// + /// the name of the gap shorthand property + public GapShorthandResolver(String gapShorthandProperty) { + this.gapShorthandProperty = gapShorthandProperty; + } + + private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(iText.StyledXmlParser.Css.Resolve.Shorthand.Impl.GapShorthandResolver + )); /// public virtual IList ResolveShorthand(String shorthandExpression) { @@ -43,11 +74,11 @@ public virtual IList ResolveShorthand(String shorthandExpression } if (CssTypesValidationUtils.ContainsInitialOrInheritOrUnset(shorthandExpression)) { return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION - , CommonCssConstants.GAP, shorthandExpression); + , gapShorthandProperty, shorthandExpression); } if (String.IsNullOrEmpty(shorthandExpression)) { return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY - , CommonCssConstants.GAP, shorthandExpression); + , gapShorthandProperty, shorthandExpression); } String[] gapProps = iText.Commons.Utils.StringUtil.Split(shorthandExpression, " "); if (gapProps.Length == 1) { @@ -59,7 +90,7 @@ public virtual IList ResolveShorthand(String shorthandExpression } else { return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION - , CommonCssConstants.GAP, shorthandExpression); + , gapShorthandProperty, shorthandExpression); } } } diff --git a/itext/itext.styledxmlparser/itext/styledxmlparser/css/validate/impl/CssDefaultValidator.cs b/itext/itext.styledxmlparser/itext/styledxmlparser/css/validate/impl/CssDefaultValidator.cs index f84facb810..0ebe0619e0 100644 --- a/itext/itext.styledxmlparser/itext/styledxmlparser/css/validate/impl/CssDefaultValidator.cs +++ b/itext/itext.styledxmlparser/itext/styledxmlparser/css/validate/impl/CssDefaultValidator.cs @@ -85,14 +85,16 @@ public CssDefaultValidator() { defaultValidators.Put(CommonCssConstants.LINE_HEIGHT, new MultiTypeDeclarationValidator(new CssNumberValueValidator (false), new CssLengthValueValidator(false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator)); - defaultValidators.Put(CommonCssConstants.COLUMN_GAP, new MultiTypeDeclarationValidator(new CssLengthValueValidator - (false), new CssPercentageValueValidator(false), normalValidator)); + MultiTypeDeclarationValidator gapValidator = new MultiTypeDeclarationValidator(new CssLengthValueValidator + (false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator); + defaultValidators.Put(CommonCssConstants.COLUMN_GAP, gapValidator); + defaultValidators.Put(CommonCssConstants.GRID_COLUMN_GAP, gapValidator); defaultValidators.Put(CommonCssConstants.COLUMN_WIDTH, new MultiTypeDeclarationValidator(new CssLengthValueValidator (false), new CssPercentageValueValidator(false), new CssEnumValidator(CommonCssConstants.AUTO))); defaultValidators.Put(CommonCssConstants.COLUMN_COUNT, new MultiTypeDeclarationValidator(new CssIntegerNumberValueValidator (false, false), new CssEnumValidator(CommonCssConstants.AUTO))); - defaultValidators.Put(CommonCssConstants.ROW_GAP, new MultiTypeDeclarationValidator(new CssLengthValueValidator - (false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator)); + defaultValidators.Put(CommonCssConstants.ROW_GAP, gapValidator); + defaultValidators.Put(CommonCssConstants.GRID_ROW_GAP, gapValidator); defaultValidators.Put(CommonCssConstants.FLEX_GROW, new MultiTypeDeclarationValidator(new CssNumberValueValidator (false), inheritInitialUnsetValidator)); defaultValidators.Put(CommonCssConstants.FLEX_SHRINK, new MultiTypeDeclarationValidator(new CssNumberValueValidator diff --git a/port-hash b/port-hash index 72eaa47852..0bd73f67c3 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -14594176c3df587ff53e54994152bf09ca64d596 +5a8f86d5e1ee424e95f9bae23d0ae30f8a971989