@@ -30,6 +30,7 @@ This file is part of the iText (R) project.
3030import com .itextpdf .layout .layout .LayoutContext ;
3131import com .itextpdf .layout .layout .LayoutResult ;
3232import com .itextpdf .layout .properties .ContinuousContainer ;
33+ import com .itextpdf .layout .properties .OverflowPropertyValue ;
3334import com .itextpdf .layout .properties .Property ;
3435import com .itextpdf .layout .properties .UnitValue ;
3536
@@ -75,7 +76,7 @@ public final void setHeightCalculator(ColumnHeightCalculator heightCalculator) {
7576 @ Override
7677 public LayoutResult layout (LayoutContext layoutContext ) {
7778 this .setProperty (Property .TREAT_AS_CONTINUOUS_CONTAINER , Boolean .TRUE );
78-
79+ setOverflowForAllChildren ( this );
7980 Rectangle actualBBox = layoutContext .getArea ().getBBox ().clone ();
8081 float originalWidth = actualBBox .getWidth ();
8182 applyWidth (actualBBox , originalWidth );
@@ -170,6 +171,16 @@ protected AbstractRenderer createOverflowRenderer(IRenderer overflowedContentRen
170171 return overflowRenderer ;
171172 }
172173
174+ private void setOverflowForAllChildren (IRenderer renderer ) {
175+ if (renderer == null ) {
176+ return ;
177+ }
178+ renderer .setProperty (Property .OVERFLOW_X , OverflowPropertyValue .VISIBLE );
179+ for (IRenderer child : renderer .getChildRenderers ()) {
180+ setOverflowForAllChildren (child );
181+ }
182+ }
183+
173184 private void applyWidth (Rectangle parentBbox , float originalWidth ) {
174185 final Float blockWidth = retrieveWidth (originalWidth );
175186 if (blockWidth != null ) {
@@ -425,7 +436,14 @@ public Float getAdditionalHeightOfEachColumn(MulticolRenderer renderer, Multicol
425436 }
426437 LayoutResult overflowResult = result .getOverflowRenderer ().layout (
427438 new LayoutContext (new LayoutArea (1 , new Rectangle (renderer .columnWidth , INF ))));
428- height = overflowResult .getOccupiedArea ().getBBox ().getHeight () / maxRelayoutCount ;
439+ float overflowHeight = overflowResult .getOccupiedArea ().getBBox ().getHeight ();
440+ if (result .getSplitRenderers ().isEmpty ()) {
441+ // In case when first child of content bigger or wider than column and in first layout NOTHING is
442+ // returned. In that case content again layouted in infinity area without keeping in mind that some
443+ // approximateHeight already exist.
444+ overflowHeight -= renderer .approximateHeight ;
445+ }
446+ height = overflowHeight / maxRelayoutCount ;
429447 return height ;
430448 }
431449
0 commit comments