@@ -102,25 +102,33 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
102102 Border [ ] borders = GetBorders ( ) ;
103103 float [ ] paddings = GetPaddings ( ) ;
104104 ApplyBordersPaddingsMargins ( parentBBox , borders , paddings ) ;
105- if ( blockWidth != null && ( blockWidth < parentBBox . GetWidth ( ) || isPositioned || rotation != null ) ) {
105+ OverflowPropertyValue ? overflowX = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_X ) ;
106+ OverflowPropertyValue ? overflowY = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_Y ) ;
107+ if ( blockWidth != null && ( blockWidth < parentBBox . GetWidth ( ) || isPositioned || rotation != null || ( null
108+ != overflowX && ! OverflowPropertyValue . FIT . Equals ( overflowX ) ) ) ) {
106109 // TODO DEVSIX-1174
107110 UnitValue widthVal = this . GetProperty < UnitValue > ( Property . WIDTH ) ;
108- if ( widthVal != null && widthVal . IsPercentValue ( ) && widthVal . GetValue ( ) == 100 ) {
111+ if ( widthVal != null && widthVal . IsPercentValue ( ) && widthVal . GetValue ( ) == 100 && ( null == overflowX || OverflowPropertyValue
112+ . FIT . Equals ( overflowX ) ) ) {
109113 }
110114 else {
111115 parentBBox . SetWidth ( ( float ) blockWidth ) ;
112116 }
113117 }
114118 float ? blockMaxHeight = RetrieveMaxHeight ( ) ;
115- if ( ! IsFixedLayout ( ) && null != blockMaxHeight && blockMaxHeight < parentBBox . GetHeight ( ) && ! true . Equals (
116- GetPropertyAsBoolean ( Property . FORCED_PLACEMENT ) ) ) {
119+ if ( ! IsFixedLayout ( ) && null != blockMaxHeight && ( blockMaxHeight < parentBBox . GetHeight ( ) || ( null != overflowY
120+ && ! OverflowPropertyValue . FIT . Equals ( overflowY ) ) ) && ! true . Equals ( GetPropertyAsBoolean ( Property . FORCED_PLACEMENT
121+ ) ) ) {
122+ if ( blockMaxHeight < parentBBox . GetHeight ( ) ) {
123+ wasHeightClipped = true ;
124+ }
117125 float heightDelta = parentBBox . GetHeight ( ) - ( float ) blockMaxHeight ;
118126 if ( marginsCollapsingEnabled && ! isCellRenderer ) {
119127 marginsCollapseHandler . ProcessFixedHeightAdjustment ( heightDelta ) ;
120128 }
121129 parentBBox . MoveUp ( heightDelta ) . SetHeight ( ( float ) blockMaxHeight ) ;
122- wasHeightClipped = true ;
123130 }
131+ Rectangle contentBoxToFit = parentBBox . Clone ( ) ;
124132 IList < Rectangle > areas ;
125133 if ( isPositioned ) {
126134 areas = JavaCollectionsUtil . SingletonList ( parentBBox ) ;
@@ -161,7 +169,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
161169 else {
162170 if ( result . GetOccupiedArea ( ) != null && result . GetStatus ( ) != LayoutResult . NOTHING ) {
163171 occupiedArea . SetBBox ( Rectangle . GetCommonRectangle ( occupiedArea . GetBBox ( ) , result . GetOccupiedArea ( ) . GetBBox
164- ( ) ) ) ;
172+ ( ) ) . SetWidth ( occupiedArea . GetBBox ( ) . GetWidth ( ) ) ) ;
165173 }
166174 }
167175 if ( FloatingHelper . IsRendererFloating ( this ) || isCellRenderer ) {
@@ -321,7 +329,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
321329 if ( ! FloatingHelper . IsRendererFloating ( childRenderer ) ) {
322330 // this check is needed only if margins collapsing is enabled
323331 occupiedArea . SetBBox ( Rectangle . GetCommonRectangle ( occupiedArea . GetBBox ( ) , result . GetOccupiedArea ( ) . GetBBox
324- ( ) ) ) ;
332+ ( ) ) . SetWidth ( occupiedArea . GetBBox ( ) . GetWidth ( ) ) ) ;
325333 }
326334 }
327335 if ( marginsCollapsingEnabled ) {
@@ -359,8 +367,12 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
359367 ) blockMinHeight ) ;
360368 }
361369 else {
362- float blockBottom = Math . Max ( occupiedArea . GetBBox ( ) . GetBottom ( ) - ( ( float ) blockMinHeight - occupiedArea . GetBBox
363- ( ) . GetHeight ( ) ) , layoutBox . GetBottom ( ) ) ;
370+ float blockBottom = occupiedArea . GetBBox ( ) . GetBottom ( ) - ( ( float ) blockMinHeight - occupiedArea . GetBBox ( ) . GetHeight
371+ ( ) ) ;
372+ if ( ( null == overflowY || OverflowPropertyValue . FIT . Equals ( overflowY ) ) && blockBottom < layoutBox . GetBottom
373+ ( ) ) {
374+ blockBottom = layoutBox . GetBottom ( ) ;
375+ }
364376 occupiedArea . GetBBox ( ) . IncreaseHeight ( occupiedArea . GetBBox ( ) . GetBottom ( ) - blockBottom ) . SetY ( blockBottom ) ;
365377 blockMinHeight -= occupiedArea . GetBBox ( ) . GetHeight ( ) ;
366378 if ( ! IsFixedLayout ( ) && blockMinHeight > AbstractRenderer . EPS ) {
@@ -393,6 +405,7 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
393405 if ( isPositioned ) {
394406 CorrectPositionedLayout ( layoutBox ) ;
395407 }
408+ float overflowPartHeight = GetOverflowPartHeight ( overflowY , contentBoxToFit ) ;
396409 ApplyPaddings ( occupiedArea . GetBBox ( ) , paddings , true ) ;
397410 ApplyBorderBox ( occupiedArea . GetBBox ( ) , borders , true ) ;
398411 ApplyMargins ( occupiedArea . GetBBox ( ) , true ) ;
@@ -427,6 +440,9 @@ public override LayoutResult Layout(LayoutContext layoutContext) {
427440 }
428441 }
429442 }
443+ if ( wasHeightClipped ) {
444+ occupiedArea . GetBBox ( ) . MoveUp ( overflowPartHeight ) . DecreaseHeight ( overflowPartHeight ) ;
445+ }
430446 if ( null == overflowRenderer_1 ) {
431447 return new LayoutResult ( LayoutResult . FULL , editedArea_1 , null , null , causeOfNothing ) ;
432448 }
@@ -497,8 +513,27 @@ public override void Draw(DrawContext drawContext) {
497513 BeginRotationIfApplied ( drawContext . GetCanvas ( ) ) ;
498514 DrawBackground ( drawContext ) ;
499515 DrawBorder ( drawContext ) ;
516+ OverflowPropertyValue ? overflowX = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_X ) ;
517+ OverflowPropertyValue ? overflowY = this . GetProperty < OverflowPropertyValue ? > ( Property . OVERFLOW_Y ) ;
518+ bool processOverflow = OverflowPropertyValue . HIDDEN . Equals ( overflowX ) || OverflowPropertyValue . HIDDEN . Equals
519+ ( overflowY ) ;
520+ if ( processOverflow ) {
521+ drawContext . GetCanvas ( ) . SaveState ( ) ;
522+ Rectangle clippedArea = drawContext . GetDocument ( ) . GetPage ( occupiedArea . GetPageNumber ( ) ) . GetPageSize ( ) ;
523+ Rectangle area = GetBorderAreaBBox ( ) ;
524+ if ( OverflowPropertyValue . HIDDEN . Equals ( overflowX ) ) {
525+ clippedArea . SetX ( area . GetX ( ) ) . SetWidth ( area . GetWidth ( ) ) ;
526+ }
527+ if ( OverflowPropertyValue . HIDDEN . Equals ( overflowY ) ) {
528+ clippedArea . SetY ( area . GetY ( ) ) . SetHeight ( area . GetHeight ( ) ) ;
529+ }
530+ drawContext . GetCanvas ( ) . Rectangle ( clippedArea ) . Clip ( ) . NewPath ( ) ;
531+ }
500532 DrawChildren ( drawContext ) ;
501533 DrawPositionedChildren ( drawContext ) ;
534+ if ( processOverflow ) {
535+ drawContext . GetCanvas ( ) . RestoreState ( ) ;
536+ }
502537 EndRotationIfApplied ( drawContext . GetCanvas ( ) ) ;
503538 EndElementOpacityApplying ( drawContext ) ;
504539 if ( isRelativePosition ) {
@@ -690,6 +725,17 @@ protected internal virtual void CorrectPositionedLayout(Rectangle layoutBox) {
690725 }
691726 }
692727
728+ protected internal virtual float GetOverflowPartHeight ( OverflowPropertyValue ? overflowY , Rectangle parentBox
729+ ) {
730+ float difference = 0 ;
731+ if ( null != overflowY && OverflowPropertyValue . FIT != overflowY ) {
732+ if ( occupiedArea . GetBBox ( ) . GetBottom ( ) < parentBox . GetBottom ( ) ) {
733+ difference = parentBox . GetBottom ( ) - occupiedArea . GetBBox ( ) . GetBottom ( ) ;
734+ }
735+ }
736+ return difference ;
737+ }
738+
693739 protected internal virtual float ApplyBordersPaddingsMargins ( Rectangle parentBBox , Border [ ] borders , float
694740 [ ] paddings ) {
695741 float parentWidth = parentBBox . GetWidth ( ) ;
0 commit comments