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 92d5c7b777..4ad4172402 100644 --- a/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs +++ b/itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs @@ -874,5 +874,20 @@ public virtual void AutoRepeatPaddingsBordersMarginsTest() { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_" )); } + + [NUnit.Framework.Test] + public virtual void MarginsCollapsingIssueTest() { + String filename = DESTINATION_FOLDER + "marginsCollapsingIssueTest.pdf"; + String cmpName = SOURCE_FOLDER + "cmp_marginsCollapsingIssueTest.pdf"; + using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) { + Div grid = new GridContainer().SetBackgroundColor(ColorConstants.BLUE); + grid.Add(new Paragraph("some grid text")); + Div div = new Div().SetBackgroundColor(ColorConstants.RED).Add(new Paragraph("some div text")).Add(grid); + div.SetProperty(Property.COLLAPSING_MARGINS, true); + document.Add(div); + } + 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_marginsCollapsingIssueTest.pdf b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_marginsCollapsingIssueTest.pdf new file mode 100644 index 0000000000..7ad5af9193 Binary files /dev/null and b/itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_marginsCollapsingIssueTest.pdf differ diff --git a/itext/itext.layout/itext/layout/margincollapse/MarginsCollapseHandler.cs b/itext/itext.layout/itext/layout/margincollapse/MarginsCollapseHandler.cs index da772cfc5f..eda99de969 100644 --- a/itext/itext.layout/itext/layout/margincollapse/MarginsCollapseHandler.cs +++ b/itext/itext.layout/itext/layout/margincollapse/MarginsCollapseHandler.cs @@ -455,7 +455,9 @@ private static bool LastChildMarginAdjoinedToParent(IRenderer parent) { } private static bool IsBlockElement(IRenderer renderer) { - return renderer is BlockRenderer || renderer is TableRenderer; + // GridContainerRenderer is inherited from BlockRenderer but only not to copy/paste some overloads. + // It doesn't use BlockRenderer#layout internally. + return (renderer is BlockRenderer || renderer is TableRenderer) && !(renderer is GridContainerRenderer); } private static bool HasHeightProp(IRenderer renderer) { diff --git a/port-hash b/port-hash index 37b22e7623..96a6f0cb8d 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -ca150c317a7bf138f31ac93c5e2e8542aa7ba789 +b35c28b993564c2a7eb0be14fe05d3e5a323f125