@@ -78,21 +78,29 @@ static float adjustLayoutBoxAccordingToFloats(List<Rectangle> floatRendererAreas
78
78
}
79
79
List <Rectangle > boxesAtYLevel = getBoxesAtYLevel (floatRendererAreas , layoutBox .getTop () - topShift );
80
80
if (boxesAtYLevel .isEmpty ()) {
81
- applyClearance (layoutBox , marginsCollapseHandler , topShift , false );
81
+ applyClearance (layoutBox , marginsCollapseHandler , topShift , false );
82
82
return topShift ;
83
83
}
84
84
85
85
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 ;
88
88
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
+ }
89
100
} while (boxWidth != null && boxWidth > right - left );
90
101
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 );
96
104
}
97
105
98
106
applyClearance (layoutBox , marginsCollapseHandler , topShift , false );
0 commit comments