@@ -57,6 +57,7 @@ This file is part of the iText (R) project.
57
57
import com .itextpdf .layout .layout .MinMaxWidthLayoutResult ;
58
58
import com .itextpdf .layout .layout .TextLayoutResult ;
59
59
import com .itextpdf .layout .minmaxwidth .MinMaxWidth ;
60
+ import com .itextpdf .layout .minmaxwidth .MinMaxWidthUtils ;
60
61
import com .itextpdf .layout .property .BaseDirection ;
61
62
import com .itextpdf .layout .property .FloatPropertyValue ;
62
63
import com .itextpdf .layout .property .Leading ;
@@ -259,20 +260,18 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
259
260
boolean isInlineBlockChild = isInlineBlockChild (childRenderer );
260
261
if (!childWidthWasReplaced ) {
261
262
if (isInlineBlockChild && childRenderer instanceof AbstractRenderer ) {
262
- childBlockMinMaxWidth = ((AbstractRenderer )childRenderer ).getMinMaxWidth (layoutContext . getArea (). getBBox (). getWidth ());
263
+ childBlockMinMaxWidth = ((AbstractRenderer )childRenderer ).getMinMaxWidth (MinMaxWidthUtils . getMax ());
263
264
float childMaxWidth = childBlockMinMaxWidth .getMaxWidth () + MIN_MAX_WIDTH_CORRECTION_EPS ;
264
265
// Decrease the calculated width by margins, paddings and borders so that even for 100% width the content definitely fits
265
266
// TODO DEVSIX-1174 fix depending on box-sizing
266
- if (childBlockMinMaxWidth != null ) {
267
- if (childMaxWidth > bbox .getWidth () && bbox .getWidth () != layoutContext .getArea ().getBBox ().getWidth ()) {
268
- childResult = new LineLayoutResult (LayoutResult .NOTHING , null , null , childRenderer , childRenderer );
269
- } else {
270
- if (bbox .getWidth () == layoutContext .getArea ().getBBox ().getWidth () && childBlockMinMaxWidth .getMinWidth () > layoutContext .getArea ().getBBox ().getWidth ()) {
271
- LoggerFactory .getLogger (LineRenderer .class ).warn (LogMessageConstant .INLINE_BLOCK_ELEMENT_WILL_BE_CLIPPED );
272
- childRenderer .setProperty (Property .FORCED_PLACEMENT , true );
273
- }
274
- bbox .setWidth (childMaxWidth );
267
+ if (childMaxWidth > bbox .getWidth () && bbox .getWidth () != layoutContext .getArea ().getBBox ().getWidth ()) {
268
+ childResult = new LineLayoutResult (LayoutResult .NOTHING , null , null , childRenderer , childRenderer );
269
+ } else {
270
+ if (bbox .getWidth () == layoutContext .getArea ().getBBox ().getWidth () && childBlockMinMaxWidth .getMinWidth () > layoutContext .getArea ().getBBox ().getWidth ()) {
271
+ LoggerFactory .getLogger (LineRenderer .class ).warn (LogMessageConstant .INLINE_BLOCK_ELEMENT_WILL_BE_CLIPPED );
272
+ childRenderer .setProperty (Property .FORCED_PLACEMENT , true );
275
273
}
274
+ bbox .setWidth (Math .min (childMaxWidth , layoutContext .getArea ().getBBox ().getWidth ()));
276
275
}
277
276
}
278
277
}
@@ -477,7 +476,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
477
476
478
477
// We shouldn't forget about images, float, inline-blocks that has to be inserted somewhere.
479
478
// TODO determine correct place to insert this content. Probably consider inline floats separately.
480
- Map <TextRenderer , IRenderer > insertAfter = new HashMap <>();
479
+ Map <TextRenderer , List < IRenderer > > insertAfter = new HashMap <>();
481
480
List <IRenderer > starterNonTextRenderers = new ArrayList <>();
482
481
TextRenderer lastTextRenderer = null ;
483
482
@@ -496,7 +495,10 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
496
495
}
497
496
lastTextRenderer = (TextRenderer ) child ;
498
497
} else if (lastTextRenderer != null ) {
499
- insertAfter .put (lastTextRenderer , child );
498
+ if (!insertAfter .containsKey (lastTextRenderer )) {
499
+ insertAfter .put (lastTextRenderer , new ArrayList <IRenderer >());
500
+ }
501
+ insertAfter .get (lastTextRenderer ).add (child );
500
502
} else {
501
503
starterNonTextRenderers .add (child );
502
504
}
@@ -527,7 +529,7 @@ public LineLayoutResult layout(LayoutContext layoutContext) {
527
529
528
530
// Insert non-text renderers
529
531
if (insertAfter .containsKey ((TextRenderer )renderer )) {
530
- children .add (insertAfter .get ((TextRenderer )renderer ));
532
+ children .addAll (insertAfter .get ((TextRenderer )renderer ));
531
533
insertAfter .remove ((TextRenderer )renderer );
532
534
}
533
535
0 commit comments