Skip to content

Commit

Permalink
Fix NPE when dealing with margins collapsing
Browse files Browse the repository at this point in the history
DEVSIX-8419

Autoported commit.
Original commit hash: [b35c28b99]
  • Loading branch information
vitali-pr authored and iText-CI committed Jul 3, 2024
1 parent bdedaad commit 2ef862e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
));
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ca150c317a7bf138f31ac93c5e2e8542aa7ba789
b35c28b993564c2a7eb0be14fe05d3e5a323f125

0 comments on commit 2ef862e

Please sign in to comment.