From 2ef862ec06cd4966034581fb3edd380ba9265d19 Mon Sep 17 00:00:00 2001 From: Vitali Prudnikovich Date: Wed, 3 Jul 2024 10:26:48 +0000 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFFix=20NPE=20when=20dealing=20with=20ma?= =?UTF-8?q?rgins=20collapsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DEVSIX-8419 Autoported commit. Original commit hash: [b35c28b99] --- .../itext/layout/element/GridContainerTest.cs | 15 +++++++++++++++ .../cmp_marginsCollapsingIssueTest.pdf | Bin 0 -> 1192 bytes .../margincollapse/MarginsCollapseHandler.cs | 4 +++- port-hash | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 itext.tests/itext.layout.tests/resources/itext/layout/GridContainerTest/cmp_marginsCollapsingIssueTest.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 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 0000000000000000000000000000000000000000..7ad5af91937bf0e8cb5f36f418afc1f6c83d75aa GIT binary patch literal 1192 zcmc&!&ubGw6fQ_StQXPZ#mhhlZK%o4?C$IjX@hCfw6(ut5)^5Bn9R<`m2@}kZc1A4 zW;_T&5DzMzdJ#Q@`Y(7BlpYl9p$Dm+{2K(FS<^;a@ai0PXWo48&G)|dW>V#1DTA_x zlsf#n_ff(C0>6G&nw*qNZZl$mTxybt6&dwyCNDCt5#0d@8M#~-1&nM+ofi||lo}j) zyAx%pnh4e8)R}XMYLX@{(y4`Hcc<3Z`q%o?*_Y?D_l!cKknHxf-RlcjPuiuUQG}8Aa z=GlYu`AqQDhP(^D7cnmifykvIFEQIC(|%_a@+Gz~Fg0aeE|Y*`fD%J0EcDv}WueHL zdy5|ey4cI{A=d(T<5Yy&R*Ug44VKFZI)a4CJqF?xxHysPdqpnZc=4(N6%Fc&ju6Jk zoPg>Wgkx!W$+!OvCZD~6jZljagCf<2j^ULdGAa~VN12adnFj6gDf!Kr!F-%p(j*bW<9Lk77iDD8R8wR!cwqw}{Bb{N#M!Emb zU|pW~93O})QIRXY&ube`tL`=f{P~blaZ6`JM`!--Xeo?H5XFVoO;bvxW>!klFR0d9 ARsaA1 literal 0 HcmV?d00001 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