Skip to content

Commit 600a2ca

Browse files
yulian-gaponenkoitext-teamcity
authored andcommitted
Fix layoutbox adjustment when flowing around floating elements
Autoported commit. Original commit hash: [c544ffc7a]
1 parent 7178596 commit 600a2ca

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

itext/itext.layout/itext/layout/renderer/FloatingHelper.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,24 @@ internal static float AdjustLayoutBoxAccordingToFloats(IList<Rectangle> floatRen
7878
return topShift;
7979
}
8080
lastLeftAndRightBoxes = FindLastLeftAndRightBoxes(layoutBox, boxesAtYLevel);
81-
left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].GetRight() : layoutBox.GetLeft();
82-
right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].GetLeft() : layoutBox.GetRight();
81+
left = lastLeftAndRightBoxes[0] != null ? lastLeftAndRightBoxes[0].GetRight() : float.MinValue;
82+
right = lastLeftAndRightBoxes[1] != null ? lastLeftAndRightBoxes[1].GetLeft() : float.MaxValue;
83+
if (left > right || left > layoutBox.GetRight() || right < layoutBox.GetLeft()) {
84+
left = layoutBox.GetLeft();
85+
right = left;
86+
}
87+
else {
88+
if (right > layoutBox.GetRight()) {
89+
right = layoutBox.GetRight();
90+
}
91+
if (left < layoutBox.GetLeft()) {
92+
left = layoutBox.GetLeft();
93+
}
94+
}
8395
}
8496
while (boxWidth != null && boxWidth > right - left);
85-
if (layoutBox.GetLeft() < left) {
86-
layoutBox.SetX(left);
87-
}
88-
if (layoutBox.GetRight() > right && layoutBox.GetLeft() <= right) {
89-
layoutBox.SetWidth(right - layoutBox.GetLeft());
97+
if (layoutBox.GetWidth() > right - left) {
98+
layoutBox.SetX(left).SetWidth(right - left);
9099
}
91100
ApplyClearance(layoutBox, marginsCollapseHandler, topShift, false);
92101
return topShift;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8ef696bccf99c0189fdb4754d3deba134857910b
1+
c544ffc7af6136ff5fa27b49f79e64335e7b6020

0 commit comments

Comments
 (0)