@@ -624,6 +624,7 @@ public virtual void Dispose()
624624 /// <param name="g">Device context to use</param>
625625 protected virtual async Task PerformLayoutImpAsync ( RGraphics g )
626626 {
627+ var prevSibling = DomUtils . GetPreviousSibling ( this ) ;
627628 if ( Display != CssConstants . None )
628629 {
629630 RectanglesReset ( ) ;
@@ -652,7 +653,6 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g)
652653
653654 if ( Display != CssConstants . TableCell )
654655 {
655- var prevSibling = DomUtils . GetPreviousSibling ( this ) ;
656656 double left ;
657657 double top ;
658658
@@ -695,17 +695,19 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g)
695695 : 0 ) ;
696696
697697 Location = new RPoint ( left , top ) ;
698-
698+
699699 if ( this . PageBreakBefore == CssConstants . Always || prevSibling ? . PageBreakAfter == CssConstants . Always )
700700 {
701701 this . BreakPage ( true ) ;
702702 }
703- else if ( this . PageBreakInside == CssConstants . Avoid
704- && ActualHeight + Location . Y > HtmlContainer . PageSize . Height
705- && prevSibling != null )
703+ else if ( this . PageBreakInside == CssConstants . Avoid && prevSibling != null )
706704 {
707705 // handle page break avoiding.
708- this . BreakPage ( true ) ;
706+ var pageLocationY = Location . Y % HtmlContainer . PageSize . Height ;
707+ if ( ActualHeight + pageLocationY > HtmlContainer . PageSize . Height )
708+ {
709+ this . BreakPage ( true ) ;
710+ }
709711 }
710712
711713 //Start with the assumption this is zero height.
@@ -739,7 +741,6 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g)
739741 }
740742 else
741743 {
742- var prevSibling = DomUtils . GetPreviousSibling ( this ) ;
743744 if ( prevSibling != null )
744745 {
745746 if ( Location == RPoint . Empty )
0 commit comments