@@ -66,6 +66,7 @@ protected internal BlockRenderer(IElement modelElement)
6666 public override LayoutResult Layout ( LayoutContext layoutContext ) {
6767 OverrideHeightProperties ( ) ;
6868 bool wasHeightClipped = false ;
69+ bool wasParentsHeightClipped = layoutContext . GetArea ( ) . IsClippedHeight ( ) ;
6970 int pageNumber = layoutContext . GetArea ( ) . GetPageNumber ( ) ;
7071 bool isPositioned = IsPositioned ( ) ;
7172 Rectangle parentBBox = layoutContext . GetArea ( ) . GetBBox ( ) . Clone ( ) ;
@@ -103,19 +104,20 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
103104 float [ ] paddings = GetPaddings ( ) ;
104105 ApplyBordersPaddingsMargins ( parentBBox , borders , paddings ) ;
105106 OverflowPropertyValue ? overflowX = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_X ) ;
106- OverflowPropertyValue ? overflowY = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_Y ) ;
107+ float ? blockMaxHeight = RetrieveMaxHeight ( ) ;
108+ OverflowPropertyValue ? overflowY = ( null == blockMaxHeight || blockMaxHeight > parentBBox . GetHeight ( ) ) &&
109+ ! wasParentsHeightClipped ? OverflowPropertyValue . FIT : this . GetProperty < OverflowPropertyValue ? > ( Property
110+ . OVERFLOW_Y ) ;
107111 if ( blockWidth != null && ( blockWidth < parentBBox . GetWidth ( ) || isPositioned || rotation != null || ( null
108112 != overflowX && ! OverflowPropertyValue . FIT . Equals ( overflowX ) ) ) ) {
109113 // TODO DEVSIX-1174
110114 UnitValue widthVal = this . GetProperty < UnitValue > ( Property . WIDTH ) ;
111- if ( widthVal != null && widthVal . IsPercentValue ( ) && widthVal . GetValue ( ) == 100 && ( null == overflowX || OverflowPropertyValue
112- . FIT . Equals ( overflowX ) ) ) {
115+ if ( widthVal != null && widthVal . IsPercentValue ( ) && widthVal . GetValue ( ) == 100 ) {
113116 }
114117 else {
115118 parentBBox . SetWidth ( ( float ) blockWidth ) ;
116119 }
117120 }
118- float ? blockMaxHeight = RetrieveMaxHeight ( ) ;
119121 if ( ! IsFixedLayout ( ) && null != blockMaxHeight && ( blockMaxHeight < parentBBox . GetHeight ( ) || ( null != overflowY
120122 && ! OverflowPropertyValue . FIT . Equals ( overflowY ) ) ) && ! true . Equals ( GetPropertyAsBoolean ( Property . FORCED_PLACEMENT
121123 ) ) ) {
@@ -128,7 +130,6 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
128130 }
129131 parentBBox . MoveUp ( heightDelta ) . SetHeight ( ( float ) blockMaxHeight ) ;
130132 }
131- Rectangle contentBoxToFit = parentBBox . Clone ( ) ;
132133 IList < Rectangle > areas ;
133134 if ( isPositioned ) {
134135 areas = JavaCollectionsUtil . SingletonList ( parentBBox ) ;
@@ -153,7 +154,8 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
153154 childMarginsInfo = marginsCollapseHandler . StartChildMarginsHandling ( childRenderer , layoutBox ) ;
154155 }
155156 while ( ( result = childRenderer . SetParent ( this ) . Layout ( new LayoutContext ( new LayoutArea ( pageNumber , layoutBox
156- ) , childMarginsInfo , floatRendererAreas ) ) ) . GetStatus ( ) != LayoutResult . FULL ) {
157+ , wasHeightClipped || wasParentsHeightClipped ) , childMarginsInfo , floatRendererAreas ) ) ) . GetStatus ( ) !=
158+ LayoutResult . FULL ) {
157159 if ( marginsCollapsingEnabled ) {
158160 if ( result . GetStatus ( ) != LayoutResult . NOTHING ) {
159161 marginsCollapseHandler . EndChildMarginsHandling ( layoutBox ) ;
@@ -169,7 +171,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
169171 else {
170172 if ( result . GetOccupiedArea ( ) != null && result . GetStatus ( ) != LayoutResult . NOTHING ) {
171173 occupiedArea . SetBBox ( Rectangle . GetCommonRectangle ( occupiedArea . GetBBox ( ) , result . GetOccupiedArea ( ) . GetBBox
172- ( ) ) . SetWidth ( occupiedArea . GetBBox ( ) . GetWidth ( ) ) ) ;
174+ ( ) ) ) ;
175+ if ( occupiedArea . GetBBox ( ) . GetWidth ( ) > layoutBox . GetWidth ( ) ) {
176+ occupiedArea . GetBBox ( ) . SetWidth ( layoutBox . GetWidth ( ) ) ;
177+ }
173178 }
174179 }
175180 if ( FloatingHelper . IsRendererFloating ( this ) || isCellRenderer ) {
@@ -329,7 +334,10 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
329334 if ( ! FloatingHelper . IsRendererFloating ( childRenderer ) ) {
330335 // this check is needed only if margins collapsing is enabled
331336 occupiedArea . SetBBox ( Rectangle . GetCommonRectangle ( occupiedArea . GetBBox ( ) , result . GetOccupiedArea ( ) . GetBBox
332- ( ) ) . SetWidth ( occupiedArea . GetBBox ( ) . GetWidth ( ) ) ) ;
337+ ( ) ) ) ;
338+ if ( occupiedArea . GetBBox ( ) . GetWidth ( ) > layoutBox . GetWidth ( ) ) {
339+ occupiedArea . GetBBox ( ) . SetWidth ( layoutBox . GetWidth ( ) ) ;
340+ }
333341 }
334342 }
335343 if ( marginsCollapsingEnabled ) {
@@ -405,9 +413,18 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
405413 if ( isPositioned ) {
406414 CorrectPositionedLayout ( layoutBox ) ;
407415 }
408- float overflowPartHeight = GetOverflowPartHeight ( overflowY , contentBoxToFit ) ;
416+ float overflowPartHeight = GetOverflowPartHeight ( overflowY , layoutBox ) ;
409417 ApplyPaddings ( occupiedArea . GetBBox ( ) , paddings , true ) ;
410418 ApplyBorderBox ( occupiedArea . GetBBox ( ) , borders , true ) ;
419+ if ( positionedRenderers . Count > 0 ) {
420+ LayoutArea area = new LayoutArea ( occupiedArea . GetPageNumber ( ) , occupiedArea . GetBBox ( ) . Clone ( ) , wasHeightClipped
421+ || wasParentsHeightClipped ) ;
422+ ApplyBorderBox ( area . GetBBox ( ) , false ) ;
423+ foreach ( IRenderer childPositionedRenderer in positionedRenderers ) {
424+ childPositionedRenderer . SetParent ( this ) . Layout ( new LayoutContext ( area ) ) ;
425+ }
426+ ApplyBorderBox ( area . GetBBox ( ) , true ) ;
427+ }
411428 ApplyMargins ( occupiedArea . GetBBox ( ) , true ) ;
412429 ApplyAbsolutePositionIfNeeded ( layoutContext ) ;
413430 if ( rotation != null ) {
@@ -441,6 +458,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
441458 }
442459 }
443460 if ( wasHeightClipped ) {
461+ editedArea_1 . GetBBox ( ) . MoveUp ( overflowPartHeight ) . DecreaseHeight ( overflowPartHeight ) ;
444462 occupiedArea . GetBBox ( ) . MoveUp ( overflowPartHeight ) . DecreaseHeight ( overflowPartHeight ) ;
445463 }
446464 if ( null == overflowRenderer_1 ) {
@@ -779,7 +797,9 @@ protected internal override MinMaxWidth GetMinMaxWidth(float availableWidth) {
779797
780798 internal virtual MinMaxWidth CorrectMinMaxWidth ( MinMaxWidth minMaxWidth ) {
781799 float ? width = RetrieveWidth ( - 1 ) ;
782- if ( width != null && width >= 0 && width >= minMaxWidth . GetChildrenMinWidth ( ) ) {
800+ OverflowPropertyValue ? overflowX = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_X ) ;
801+ if ( width != null && width >= 0 && ( width >= minMaxWidth . GetChildrenMinWidth ( ) || ! OverflowPropertyValue . FIT
802+ . Equals ( overflowX ) ) ) {
783803 minMaxWidth . SetChildrenMaxWidth ( ( float ) width ) ;
784804 minMaxWidth . SetChildrenMinWidth ( ( float ) width ) ;
785805 }
0 commit comments