Skip to content

Commit 188d538

Browse files
committed
Align child if freespace isn't negative. Find overflow part before margin processing. Minor fixes.
DEVSIX-992 Autoported commit. Original commit hash: [707e41a]
1 parent 783ec13 commit 188d538

File tree

6 files changed

+27
-22
lines changed

6 files changed

+27
-22
lines changed

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,23 +1275,25 @@ protected internal virtual void AlignChildHorizontally(IRenderer childRenderer,
12751275
);
12761276
if (horizontalAlignment != null && horizontalAlignment != HorizontalAlignment.LEFT) {
12771277
float freeSpace = availableWidth - childRenderer.GetOccupiedArea().GetBBox().GetWidth();
1278-
try {
1279-
switch (horizontalAlignment) {
1280-
case HorizontalAlignment.RIGHT: {
1281-
childRenderer.Move(freeSpace, 0);
1282-
break;
1283-
}
1278+
if (freeSpace > 0) {
1279+
try {
1280+
switch (horizontalAlignment) {
1281+
case HorizontalAlignment.RIGHT: {
1282+
childRenderer.Move(freeSpace, 0);
1283+
break;
1284+
}
12841285

1285-
case HorizontalAlignment.CENTER: {
1286-
childRenderer.Move(freeSpace / 2, 0);
1287-
break;
1286+
case HorizontalAlignment.CENTER: {
1287+
childRenderer.Move(freeSpace / 2, 0);
1288+
break;
1289+
}
12881290
}
12891291
}
1290-
}
1291-
catch (Exception) {
1292-
ILogger logger = LoggerFactory.GetLogger(typeof(iText.Layout.Renderer.AbstractRenderer));
1293-
logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED,
1294-
"Some of the children might not end up aligned horizontally."));
1292+
catch (ArgumentNullException) {
1293+
ILogger logger = LoggerFactory.GetLogger(typeof(iText.Layout.Renderer.AbstractRenderer));
1294+
logger.Error(MessageFormatUtil.Format(iText.IO.LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED,
1295+
"Some of the children might not end up aligned horizontally."));
1296+
}
12951297
}
12961298
}
12971299
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
357357
causeOfNothing = result.GetCauseOfNothing();
358358
}
359359
}
360+
float overflowPartHeight = GetOverflowPartHeight(overflowY, layoutBox);
360361
if (marginsCollapsingEnabled && !isCellRenderer) {
361362
marginsCollapseHandler.EndMarginsCollapse(layoutBox);
362363
}
@@ -413,7 +414,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
413414
if (isPositioned) {
414415
CorrectPositionedLayout(layoutBox);
415416
}
416-
float overflowPartHeight = GetOverflowPartHeight(overflowY, layoutBox);
417417
ApplyPaddings(occupiedArea.GetBBox(), paddings, true);
418418
ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
419419
if (positionedRenderers.Count > 0) {

itext/itext.layout/itext/layout/renderer/LineRenderer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,14 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
271271
SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
272272
}
273273
if (childResult == null) {
274+
if (childPos > 0) {
275+
SetProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
276+
}
274277
childResult = childRenderer.Layout(new LayoutContext(new LayoutArea(layoutContext.GetArea().GetPageNumber(
275-
), bbox)));
276-
}
277-
if (childPos > 0) {
278-
DeleteOwnProperty(Property.OVERFLOW_X);
278+
), bbox, wasParentsHeightClipped)));
279+
if (childPos > 0) {
280+
DeleteOwnProperty(Property.OVERFLOW_X);
281+
}
279282
}
280283
// Get back child width so that it's not lost
281284
if (childWidthWasReplaced) {

itext/itext.layout/itext/layout/renderer/ParagraphRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
378378
previousDescent = processedRenderer.GetMaxDescent();
379379
}
380380
}
381+
float overflowPartHeight = GetOverflowPartHeight(overflowY, layoutBox);
381382
if (marginsCollapsingEnabled) {
382383
if (childRenderers.Count > 0 && notAllKidsAreFloats) {
383384
marginsCollapseHandler.EndChildMarginsHandling(layoutBox);
@@ -418,7 +419,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
418419
if (isPositioned) {
419420
CorrectPositionedLayout(layoutBox);
420421
}
421-
float overflowPartHeight = GetOverflowPartHeight(overflowY, layoutBox);
422422
ApplyPaddings(occupiedArea.GetBBox(), paddings, true);
423423
ApplyBorderBox(occupiedArea.GetBBox(), borders, true);
424424
ApplyMargins(occupiedArea.GetBBox(), true);

itext/itext.layout/itext/layout/renderer/TextRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
192192
TextLayoutResult result = null;
193193
OverflowPropertyValue? overflowX = this.parent.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_X);
194194
OverflowPropertyValue? overflowY = null == RetrieveMaxHeight() && !layoutContext.GetArea().IsClippedHeight
195-
() ? null : this.parent.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_Y);
195+
() ? OverflowPropertyValue.FIT : this.parent.GetProperty<OverflowPropertyValue?>(Property.OVERFLOW_Y);
196196
// true in situations like "\nHello World" or "Hello\nWorld"
197197
bool isSplitForcedByNewLine = false;
198198
// needed in situation like "\nHello World" or " Hello World", when split occurs on first character, but we want to leave it on previous line

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8bfe5735198d8407b57ba94f55c551e3c1d12253
1+
707e41a9d7acaca7287322b9d5f5df84df6dfc0e

0 commit comments

Comments
 (0)