@@ -95,10 +95,17 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
95
95
Rectangle layoutBox = layoutContext .getArea ().getBBox ().clone ();
96
96
boolean wasParentsHeightClipped = layoutContext .getArea ().isClippedHeight ();
97
97
List <Rectangle > floatRendererAreas = layoutContext .getFloatRendererAreas ();
98
+
99
+ OverflowPropertyValue oldXOverflow = null ;
100
+ boolean wasXOverflowChanged = false ;
101
+
98
102
if (floatRendererAreas != null ) {
103
+ float layoutWidth = layoutBox .getWidth ();
99
104
FloatingHelper .adjustLineAreaAccordingToFloats (floatRendererAreas , layoutBox );
100
- if (0 != floatRendererAreas .size ()) {
101
- setProperty (Property .OVERFLOW_X , OverflowPropertyValue .FIT ); // TODO
105
+ if (layoutWidth > layoutBox .getWidth ()) {
106
+ oldXOverflow = this .<OverflowPropertyValue >getProperty (Property .OVERFLOW_X );
107
+ wasXOverflowChanged = true ;
108
+ setProperty (Property .OVERFLOW_X , OverflowPropertyValue .FIT );
102
109
}
103
110
}
104
111
@@ -132,7 +139,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
132
139
133
140
boolean floatsPlaced = false ;
134
141
List <IRenderer > overflowFloats = new ArrayList <>();
135
- int lastTabIndex = 0 ;
142
+ int lastTabIndex = 0 ;
136
143
137
144
while (childPos < childRenderers .size ()) {
138
145
IRenderer childRenderer = childRenderers .get (childPos );
@@ -198,14 +205,13 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
198
205
// TODO may be process floating spans as inline blocks always?
199
206
200
207
if (childPos > 0 ) {
208
+ oldXOverflow = this .<OverflowPropertyValue >getProperty (Property .OVERFLOW_X );
209
+ wasXOverflowChanged = true ;
201
210
setProperty (Property .OVERFLOW_X , OverflowPropertyValue .FIT );
202
211
}
203
212
if (overflowFloats .isEmpty () && (!anythingPlaced || floatingBoxFullWidth <= bbox .getWidth ())) {
204
213
childResult = childRenderer .layout (new LayoutContext (new LayoutArea (layoutContext .getArea ().getPageNumber (), layoutContext .getArea ().getBBox ().clone (), wasParentsHeightClipped ), null , floatRendererAreas ));
205
214
}
206
- if (childPos > 0 ) {
207
- deleteOwnProperty (Property .OVERFLOW_X );
208
- }
209
215
// Get back child width so that it's not lost
210
216
if (childWidthWasReplaced ) {
211
217
if (childRendererHasOwnWidthProperty ) {
@@ -222,7 +228,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
222
228
minChildWidth = ((MinMaxWidthLayoutResult ) childResult ).getNotNullMinMaxWidth (bbox .getWidth ()).getMinWidth ();
223
229
}
224
230
// TODO if percents width was used, max width might be huge
225
- maxChildWidth = ((MinMaxWidthLayoutResult )childResult ).getNotNullMinMaxWidth (bbox .getWidth ()).getMaxWidth ();
231
+ maxChildWidth = ((MinMaxWidthLayoutResult ) childResult ).getNotNullMinMaxWidth (bbox .getWidth ()).getMaxWidth ();
226
232
}
227
233
widthHandler .updateMinChildWidth (minChildWidth );
228
234
widthHandler .updateMaxChildWidth (maxChildWidth );
@@ -235,8 +241,8 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
235
241
LineRenderer [] split = splitNotFittingFloat (childPos , childResult );
236
242
IRenderer splitRenderer = childResult .getSplitRenderer ();
237
243
if (splitRenderer instanceof TextRenderer ) {
238
- ((TextRenderer )splitRenderer ).trimFirst ();
239
- ((TextRenderer )splitRenderer ).trimLast ();
244
+ ((TextRenderer ) splitRenderer ).trimFirst ();
245
+ ((TextRenderer ) splitRenderer ).trimLast ();
240
246
}
241
247
// ensure no other thing (like text wrapping the float) will occupy the line
242
248
splitRenderer .getOccupiedArea ().getBBox ().setWidth (layoutContext .getArea ().getBBox ().getWidth ());
@@ -246,8 +252,8 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
246
252
floatsPlaced = true ;
247
253
248
254
if (childRenderer instanceof TextRenderer ) {
249
- ((TextRenderer )childRenderer ).trimFirst ();
250
- ((TextRenderer )childRenderer ).trimLast ();
255
+ ((TextRenderer ) childRenderer ).trimFirst ();
256
+ ((TextRenderer ) childRenderer ).trimLast ();
251
257
}
252
258
253
259
adjustLineOnFloatPlaced (layoutBox , childPos , kidFloatPropertyVal , childRenderer .getOccupiedArea ().getBBox ());
@@ -269,7 +275,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
269
275
boolean isInlineBlockChild = isInlineBlockChild (childRenderer );
270
276
if (!childWidthWasReplaced ) {
271
277
if (isInlineBlockChild && childRenderer instanceof AbstractRenderer ) {
272
- childBlockMinMaxWidth = ((AbstractRenderer )childRenderer ).getMinMaxWidth (MinMaxWidthUtils .getMax ());
278
+ childBlockMinMaxWidth = ((AbstractRenderer ) childRenderer ).getMinMaxWidth (MinMaxWidthUtils .getMax ());
273
279
float childMaxWidth = childBlockMinMaxWidth .getMaxWidth () + MIN_MAX_WIDTH_CORRECTION_EPS ;
274
280
// Decrease the calculated width by margins, paddings and borders so that even for 100% width the content definitely fits
275
281
// TODO DEVSIX-1174 fix depending on box-sizing
@@ -290,12 +296,11 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
290
296
}
291
297
if (childResult == null ) {
292
298
if (childPos > 0 ) {
299
+ oldXOverflow = this .<OverflowPropertyValue >getProperty (Property .OVERFLOW_X );
300
+ wasXOverflowChanged = true ;
293
301
setProperty (Property .OVERFLOW_X , OverflowPropertyValue .FIT );
294
302
}
295
303
childResult = childRenderer .layout (new LayoutContext (new LayoutArea (layoutContext .getArea ().getPageNumber (), bbox , wasParentsHeightClipped )));
296
- if (childPos > 0 ) {
297
- deleteOwnProperty (Property .OVERFLOW_X );
298
- }
299
304
}
300
305
301
306
// Get back child width so that it's not lost
@@ -326,12 +331,12 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
326
331
childDescent = ((ILeafElementRenderer ) childRenderer ).getDescent ();
327
332
} else if (isInlineBlockChild && childResult .getStatus () != LayoutResult .NOTHING ) {
328
333
if (childRenderer instanceof AbstractRenderer ) {
329
- Float yLine = ((AbstractRenderer )childRenderer ).getLastYLineRecursively ();
334
+ Float yLine = ((AbstractRenderer ) childRenderer ).getLastYLineRecursively ();
330
335
if (yLine == null ) {
331
336
childAscent = childRenderer .getOccupiedArea ().getBBox ().getHeight ();
332
337
} else {
333
- childAscent = childRenderer .getOccupiedArea ().getBBox ().getTop () - (float )yLine ;
334
- childDescent = -((float )yLine - childRenderer .getOccupiedArea ().getBBox ().getBottom ());
338
+ childAscent = childRenderer .getOccupiedArea ().getBBox ().getTop () - (float ) yLine ;
339
+ childDescent = -((float ) yLine - childRenderer .getOccupiedArea ().getBBox ().getBottom ());
335
340
}
336
341
} else {
337
342
childAscent = childRenderer .getOccupiedArea ().getBBox ().getHeight ();
@@ -546,9 +551,9 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
546
551
children .add (newRenderer );
547
552
548
553
// Insert non-text renderers
549
- if (insertAfter .containsKey ((TextRenderer )renderer )) {
550
- children .addAll (insertAfter .get ((TextRenderer )renderer ));
551
- insertAfter .remove ((TextRenderer )renderer );
554
+ if (insertAfter .containsKey ((TextRenderer ) renderer )) {
555
+ children .addAll (insertAfter .get ((TextRenderer ) renderer ));
556
+ insertAfter .remove ((TextRenderer ) renderer );
552
557
}
553
558
554
559
newRenderer .line = new GlyphLine (newRenderer .line );
@@ -620,15 +625,13 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
620
625
result .setMinMaxWidth (minMaxWidth );
621
626
}
622
627
623
- if (floatRendererAreas != null ) {
624
- if (0 != floatRendererAreas .size ()) {
625
- deleteOwnProperty (Property .OVERFLOW_X ); // TODO
626
- if (null != result .getSplitRenderer ()) {
627
- result .getSplitRenderer ().deleteOwnProperty (Property .OVERFLOW_X );
628
- }
629
- if (null != result .getOverflowRenderer ()) {
630
- result .getOverflowRenderer ().deleteOwnProperty (Property .OVERFLOW_X );
631
- }
628
+ if (wasXOverflowChanged ) {
629
+ setProperty (Property .OVERFLOW_X , oldXOverflow );
630
+ if (null != result .getSplitRenderer ()) {
631
+ result .getSplitRenderer ().setProperty (Property .OVERFLOW_X , oldXOverflow );
632
+ }
633
+ if (null != result .getOverflowRenderer ()) {
634
+ result .getOverflowRenderer ().setProperty (Property .OVERFLOW_X , oldXOverflow );
632
635
}
633
636
}
634
637
return result ;
@@ -788,7 +791,7 @@ protected LineRenderer adjustChildrenYLine() {
788
791
renderer .move (0 , actualYLine - renderer .getOccupiedArea ().getBBox ().getBottom () + descent );
789
792
} else {
790
793
Float yLine = isInlineBlockChild (renderer ) && renderer instanceof AbstractRenderer ? ((AbstractRenderer ) renderer ).getLastYLineRecursively () : null ;
791
- renderer .move (0 , actualYLine - (yLine == null ? renderer .getOccupiedArea ().getBBox ().getBottom () : (float )yLine ));
794
+ renderer .move (0 , actualYLine - (yLine == null ? renderer .getOccupiedArea ().getBBox ().getBottom () : (float ) yLine ));
792
795
}
793
796
}
794
797
return this ;
@@ -840,7 +843,7 @@ float getTopLeadingIndent(Leading leading) {
840
843
case Leading .FIXED :
841
844
return (Math .max (leading .getValue (), maxBlockAscent - maxBlockDescent ) - occupiedArea .getBBox ().getHeight ()) / 2 ;
842
845
case Leading .MULTIPLIED :
843
- float fontSize = (float )this .getPropertyAsFloat (Property .FONT_SIZE , 0f );
846
+ float fontSize = (float ) this .getPropertyAsFloat (Property .FONT_SIZE , 0f );
844
847
// In HTML, depending on whether <!DOCTYPE html> is present or not, and if present then depending on the version,
845
848
// the behavior id different. In one case, bottom leading indent is added for images, in the other it is not added.
846
849
// This is why !containsImage() is present below. Depending on the presence of this !containsImage() condition, the behavior changes
@@ -858,7 +861,7 @@ float getBottomLeadingIndent(Leading leading) {
858
861
case Leading .FIXED :
859
862
return (Math .max (leading .getValue (), maxBlockAscent - maxBlockDescent ) - occupiedArea .getBBox ().getHeight ()) / 2 ;
860
863
case Leading .MULTIPLIED :
861
- float fontSize = (float )this .getPropertyAsFloat (Property .FONT_SIZE , 0f );
864
+ float fontSize = (float ) this .getPropertyAsFloat (Property .FONT_SIZE , 0f );
862
865
// In HTML, depending on whether <!DOCTYPE html> is present or not, and if present then depending on the version,
863
866
// the behavior id different. In one case, bottom leading indent is added for images, in the other it is not added.
864
867
// This is why !containsImage() is present below. Depending on the presence of this !containsImage() condition, the behavior changes
0 commit comments