Skip to content

Commit 2ef862e

Browse files
vitali-priText-CI
authored andcommitted
Fix NPE when dealing with margins collapsing
DEVSIX-8419 Autoported commit. Original commit hash: [b35c28b99]
1 parent bdedaad commit 2ef862e

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

itext.tests/itext.layout.tests/itext/layout/element/GridContainerTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,5 +874,20 @@ public virtual void AutoRepeatPaddingsBordersMarginsTest() {
874874
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
875875
));
876876
}
877+
878+
[NUnit.Framework.Test]
879+
public virtual void MarginsCollapsingIssueTest() {
880+
String filename = DESTINATION_FOLDER + "marginsCollapsingIssueTest.pdf";
881+
String cmpName = SOURCE_FOLDER + "cmp_marginsCollapsingIssueTest.pdf";
882+
using (Document document = new Document(new PdfDocument(new PdfWriter(filename)))) {
883+
Div grid = new GridContainer().SetBackgroundColor(ColorConstants.BLUE);
884+
grid.Add(new Paragraph("some grid text"));
885+
Div div = new Div().SetBackgroundColor(ColorConstants.RED).Add(new Paragraph("some div text")).Add(grid);
886+
div.SetProperty(Property.COLLAPSING_MARGINS, true);
887+
document.Add(div);
888+
}
889+
NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(filename, cmpName, DESTINATION_FOLDER, "diff_"
890+
));
891+
}
877892
}
878893
}

itext/itext.layout/itext/layout/margincollapse/MarginsCollapseHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ private static bool LastChildMarginAdjoinedToParent(IRenderer parent) {
455455
}
456456

457457
private static bool IsBlockElement(IRenderer renderer) {
458-
return renderer is BlockRenderer || renderer is TableRenderer;
458+
// GridContainerRenderer is inherited from BlockRenderer but only not to copy/paste some overloads.
459+
// It doesn't use BlockRenderer#layout internally.
460+
return (renderer is BlockRenderer || renderer is TableRenderer) && !(renderer is GridContainerRenderer);
459461
}
460462

461463
private static bool HasHeightProp(IRenderer renderer) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ca150c317a7bf138f31ac93c5e2e8542aa7ba789
1+
b35c28b993564c2a7eb0be14fe05d3e5a323f125

0 commit comments

Comments
 (0)