Skip to content

Commit c544ffc

Browse files
Fix layoutbox adjustment when flowing around floating elements
1 parent 8ef696b commit c544ffc

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

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

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,29 @@ static float adjustLayoutBoxAccordingToFloats(List<Rectangle> floatRendererAreas
7878
}
7979
List<Rectangle> boxesAtYLevel = getBoxesAtYLevel(floatRendererAreas, layoutBox.getTop() - topShift);
8080
if (boxesAtYLevel.isEmpty()) {
81-
applyClearance(layoutBox, marginsCollapseHandler, topShift ,false);
81+
applyClearance(layoutBox, marginsCollapseHandler, topShift, false);
8282
return topShift;
8383
}
8484

8585
lastLeftAndRightBoxes = findLastLeftAndRightBoxes(layoutBox, boxesAtYLevel);
86-
left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : layoutBox.getLeft();
87-
right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : layoutBox.getRight();
86+
left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].getRight() : Float.MIN_VALUE;
87+
right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].getLeft() : Float.MAX_VALUE;
8888

89+
if (left > right || left > layoutBox.getRight() || right < layoutBox.getLeft()) {
90+
left = layoutBox.getLeft();
91+
right = left;
92+
} else {
93+
if (right > layoutBox.getRight()) {
94+
right = layoutBox.getRight();
95+
}
96+
if (left < layoutBox.getLeft()) {
97+
left = layoutBox.getLeft();
98+
}
99+
}
89100
} while (boxWidth != null && boxWidth > right - left);
90101

91-
if (layoutBox.getLeft() < left) {
92-
layoutBox.setX(left);
93-
}
94-
if (layoutBox.getRight() > right && layoutBox.getLeft() <= right) {
95-
layoutBox.setWidth(right - layoutBox.getLeft());
102+
if (layoutBox.getWidth() > right - left) {
103+
layoutBox.setX(left).setWidth(right - left);
96104
}
97105

98106
applyClearance(layoutBox, marginsCollapseHandler, topShift, false);

0 commit comments

Comments
 (0)