Skip to content

Commit 25e9b63

Browse files
yulian-gaponenkopavel-alay
authored andcommitted
Make margins collapse handling on cells a bit more consitent
DEVSIX-1195 Autoported commit. Original commit hash: [0979cc53a]
1 parent 8850edc commit 25e9b63

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,7 @@ public virtual void EndMarginsCollapse(Rectangle layoutBox) {
225225
else {
226226
ownCollapseAfter = new MarginsCollapse();
227227
}
228-
if (ownCollapseAfter != null) {
229-
ownCollapseAfter.JoinMargin(GetModelBottomMargin(renderer));
230-
}
228+
ownCollapseAfter.JoinMargin(GetModelBottomMargin(renderer));
231229
collapseInfo.SetOwnCollapseAfter(ownCollapseAfter);
232230
if (collapseInfo.IsSelfCollapsing()) {
233231
if (prevChildMarginInfo != null) {
@@ -270,8 +268,7 @@ public virtual void EndMarginsCollapse(Rectangle layoutBox) {
270268
}
271269

272270
private void UpdateCollapseBeforeIfPrevKidIsFirstAndSelfCollapsed(MarginsCollapse collapseAfter) {
273-
if (prevChildMarginInfo.IsSelfCollapsing() && prevChildMarginInfo.IsIgnoreOwnMarginTop() && collapseAfter
274-
!= null) {
271+
if (prevChildMarginInfo.IsSelfCollapsing() && prevChildMarginInfo.IsIgnoreOwnMarginTop()) {
275272
// prevChildMarginInfo.isIgnoreOwnMarginTop() is true only if it's the first kid and is adjoined to parent margin
276273
collapseInfo.GetCollapseBefore().JoinMargin(collapseAfter);
277274
}
@@ -534,7 +531,8 @@ private static bool RendererIsFloated(IRenderer renderer) {
534531

535532
private static float GetModelTopMargin(IRenderer renderer) {
536533
float? margin = renderer.GetModelElement().GetProperty<float?>(Property.MARGIN_TOP);
537-
return margin != null ? (float)margin : 0;
534+
// TODO Concerning "renderer instanceof CellRenderer" check: may be try to apply more general solution in future
535+
return margin != null && !(renderer is CellRenderer) ? (float)margin : 0;
538536
}
539537

540538
private static void IgnoreModelTopMargin(IRenderer renderer) {
@@ -547,7 +545,8 @@ private static void OverrideModelTopMargin(IRenderer renderer, float collapsedMa
547545

548546
private static float GetModelBottomMargin(IRenderer renderer) {
549547
float? margin = renderer.GetModelElement().GetProperty<float?>(Property.MARGIN_BOTTOM);
550-
return margin != null ? (float)margin : 0;
548+
// TODO Concerning "renderer instanceof CellRenderer" check: may be try to apply more general solution in future
549+
return margin != null && !(renderer is CellRenderer) ? (float)margin : 0;
551550
}
552551

553552
private static void IgnoreModelBottomMargin(IRenderer renderer) {

itext/itext.layout/itext/layout/renderer/BlockRenderer.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
9696
}
9797
bool isCellRenderer = this is CellRenderer;
9898
if (marginsCollapsingEnabled) {
99-
if (!isCellRenderer) {
100-
marginsCollapseHandler.StartMarginsCollapse(parentBBox);
101-
}
99+
marginsCollapseHandler.StartMarginsCollapse(parentBBox);
102100
}
103101
Border[] borders = GetBorders();
104102
float[] paddings = GetPaddings();
@@ -141,9 +139,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
141139
if (result.GetStatus() != LayoutResult.NOTHING) {
142140
marginsCollapseHandler.EndChildMarginsHandling(layoutBox);
143141
}
144-
if (!isCellRenderer) {
145-
marginsCollapseHandler.EndMarginsCollapse(layoutBox);
146-
}
142+
marginsCollapseHandler.EndMarginsCollapse(layoutBox);
147143
}
148144
if (true.Equals(GetPropertyAsBoolean(Property.FILL_AVAILABLE_AREA_ON_SPLIT)) || true.Equals(GetPropertyAsBoolean
149145
(Property.FILL_AVAILABLE_AREA))) {
@@ -338,7 +334,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
338334
}
339335
}
340336
float overflowPartHeight = GetOverflowPartHeight(overflowY, layoutBox);
341-
if (marginsCollapsingEnabled && !isCellRenderer) {
337+
if (marginsCollapsingEnabled) {
342338
marginsCollapseHandler.EndMarginsCollapse(layoutBox);
343339
}
344340
if (true.Equals(GetPropertyAsBoolean(Property.FILL_AVAILABLE_AREA))) {

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
010d71ac111f8f411aa0a603cc5b8ecd5970ae79
1+
0979cc53a791b61b0108af67dd2fd747decb65f7

0 commit comments

Comments
 (0)