Skip to content

Commit 707e41a

Browse files
committed
Align child if freespace isn't negative. Find overflow part before margin processing. Minor fixes.
DEVSIX-992
1 parent 8bfe573 commit 707e41a

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,18 +1327,20 @@ protected void alignChildHorizontally(IRenderer childRenderer, Rectangle current
13271327
HorizontalAlignment horizontalAlignment = childRenderer.<HorizontalAlignment>getProperty(Property.HORIZONTAL_ALIGNMENT);
13281328
if (horizontalAlignment != null && horizontalAlignment != HorizontalAlignment.LEFT) {
13291329
float freeSpace = availableWidth - childRenderer.getOccupiedArea().getBBox().getWidth();
1330-
try {
1331-
switch (horizontalAlignment) {
1332-
case RIGHT:
1333-
childRenderer.move(freeSpace, 0);
1334-
break;
1335-
case CENTER:
1336-
childRenderer.move(freeSpace / 2, 0);
1337-
break;
1330+
if (freeSpace > 0) {
1331+
try {
1332+
switch (horizontalAlignment) {
1333+
case RIGHT:
1334+
childRenderer.move(freeSpace, 0);
1335+
break;
1336+
case CENTER:
1337+
childRenderer.move(freeSpace / 2, 0);
1338+
break;
1339+
}
1340+
} catch (NullPointerException npe) {
1341+
Logger logger = LoggerFactory.getLogger(AbstractRenderer.class);
1342+
logger.error(MessageFormatUtil.format(LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, "Some of the children might not end up aligned horizontally."));
13381343
}
1339-
} catch (Exception npe) {
1340-
Logger logger = LoggerFactory.getLogger(AbstractRenderer.class);
1341-
logger.error(MessageFormatUtil.format(LogMessageConstant.OCCUPIED_AREA_HAS_NOT_BEEN_INITIALIZED, "Some of the children might not end up aligned horizontally."));
13421344
}
13431345
}
13441346
}

layout/src/main/java/com/itextpdf/layout/renderer/BlockRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
383383
causeOfNothing = result.getCauseOfNothing();
384384
}
385385
}
386+
float overflowPartHeight = getOverflowPartHeight(overflowY, layoutBox);
386387
if (marginsCollapsingEnabled && !isCellRenderer) {
387388
marginsCollapseHandler.endMarginsCollapse(layoutBox);
388389
}
@@ -442,7 +443,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
442443
correctPositionedLayout(layoutBox);
443444
}
444445

445-
float overflowPartHeight = getOverflowPartHeight(overflowY, layoutBox);
446446
applyPaddings(occupiedArea.getBBox(), paddings, true);
447447
applyBorderBox(occupiedArea.getBBox(), borders, true);
448448
if (positionedRenderers.size() > 0) {

layout/src/main/java/com/itextpdf/layout/renderer/LineRenderer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,13 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
289289
setProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
290290
}
291291
if (childResult == null) {
292-
childResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox)));
293-
}
294-
if (childPos > 0) {
295-
deleteOwnProperty(Property.OVERFLOW_X);
292+
if (childPos > 0) {
293+
setProperty(Property.OVERFLOW_X, OverflowPropertyValue.FIT);
294+
}
295+
childResult = childRenderer.layout(new LayoutContext(new LayoutArea(layoutContext.getArea().getPageNumber(), bbox, wasParentsHeightClipped)));
296+
if (childPos > 0) {
297+
deleteOwnProperty(Property.OVERFLOW_X);
298+
}
296299
}
297300

298301
// Get back child width so that it's not lost

layout/src/main/java/com/itextpdf/layout/renderer/ParagraphRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
369369
previousDescent = processedRenderer.getMaxDescent();
370370
}
371371
}
372+
float overflowPartHeight = getOverflowPartHeight(overflowY, layoutBox);
372373

373374
if (marginsCollapsingEnabled) {
374375
if (childRenderers.size() > 0 && notAllKidsAreFloats) {
@@ -411,7 +412,6 @@ public LayoutResult layout(LayoutContext layoutContext) {
411412
correctPositionedLayout(layoutBox);
412413
}
413414

414-
float overflowPartHeight = getOverflowPartHeight(overflowY, layoutBox);
415415
applyPaddings(occupiedArea.getBBox(), paddings, true);
416416
applyBorderBox(occupiedArea.getBBox(), borders, true);
417417
applyMargins(occupiedArea.getBBox(), true);

layout/src/main/java/com/itextpdf/layout/renderer/TextRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public LayoutResult layout(LayoutContext layoutContext) {
220220
TextLayoutResult result = null;
221221

222222
OverflowPropertyValue overflowX = this.parent.<OverflowPropertyValue>getProperty(Property.OVERFLOW_X);
223-
OverflowPropertyValue overflowY = null == retrieveMaxHeight() && !layoutContext.getArea().isClippedHeight() ? null : this.parent.<OverflowPropertyValue>getProperty(Property.OVERFLOW_Y);
223+
OverflowPropertyValue overflowY = null == retrieveMaxHeight() && !layoutContext.getArea().isClippedHeight() ? OverflowPropertyValue.FIT : this.parent.<OverflowPropertyValue>getProperty(Property.OVERFLOW_Y);
224224

225225
// true in situations like "\nHello World" or "Hello\nWorld"
226226
boolean isSplitForcedByNewLine = false;

0 commit comments

Comments
 (0)