diff --git a/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/38. Breaking Pages 4 - Divs.htm b/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/37. Breaking Pages 4 - Divs.htm similarity index 71% rename from Source/Demos/HtmlRenderer.Demo.Common/TestSamples/38. Breaking Pages 4 - Divs.htm rename to Source/Demos/HtmlRenderer.Demo.Common/TestSamples/37. Breaking Pages 4 - Divs.htm index 8e30d2b16..8af74d192 100644 --- a/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/38. Breaking Pages 4 - Divs.htm +++ b/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/37. Breaking Pages 4 - Divs.htm @@ -8,7 +8,7 @@ This is on page 2 -
+
This is on page 3.
@@ -18,8 +18,11 @@
This is also on page 4
+
+ This is also on page 4. +
-
+
This is on page 5
@@ -29,8 +32,7 @@ This is on page 6
-
-
+
diff --git a/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/38. Breaking Pages 5 - Divs.htm b/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/38. Breaking Pages 5 - Divs.htm new file mode 100644 index 000000000..e85c680c0 --- /dev/null +++ b/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/38. Breaking Pages 5 - Divs.htm @@ -0,0 +1,10 @@ + + +
+ This is on page 1 +
+
+
+
+ + \ No newline at end of file diff --git a/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/37.Absolute position.htm b/Source/Demos/HtmlRenderer.Demo.Common/TestSamples/39. Absolute position.htm similarity index 100% rename from Source/Demos/HtmlRenderer.Demo.Common/TestSamples/37.Absolute position.htm rename to Source/Demos/HtmlRenderer.Demo.Common/TestSamples/39. Absolute position.htm diff --git a/Source/Demos/HtmlRenderer.Demo.Console/Program.cs b/Source/Demos/HtmlRenderer.Demo.Console/Program.cs index e1c1cf8b5..80e8c60b2 100644 --- a/Source/Demos/HtmlRenderer.Demo.Console/Program.cs +++ b/Source/Demos/HtmlRenderer.Demo.Console/Program.cs @@ -24,7 +24,7 @@ foreach (var htmlSample in samples) { ////Just doing one test here. Comment this for all of them. - if (!htmlSample.FullName.Contains("38")) continue; + if (!htmlSample.FullName.Contains("37")) continue; //await skia.GenerateSampleAsync(htmlSample); //await svgSkia.GenerateSampleAsync(htmlSample); diff --git a/Source/HtmlRenderer/Core/Dom/CssBox.cs b/Source/HtmlRenderer/Core/Dom/CssBox.cs index dcfd6ff38..a940aa713 100644 --- a/Source/HtmlRenderer/Core/Dom/CssBox.cs +++ b/Source/HtmlRenderer/Core/Dom/CssBox.cs @@ -624,6 +624,7 @@ public virtual void Dispose() /// Device context to use protected virtual async Task PerformLayoutImpAsync(RGraphics g) { + var prevSibling = DomUtils.GetPreviousSibling(this); if (Display != CssConstants.None) { RectanglesReset(); @@ -652,7 +653,6 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g) if (Display != CssConstants.TableCell) { - var prevSibling = DomUtils.GetPreviousSibling(this); double left; double top; @@ -695,17 +695,19 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g) : 0); Location = new RPoint(left, top); - + if (this.PageBreakBefore == CssConstants.Always || prevSibling?.PageBreakAfter == CssConstants.Always) { this.BreakPage(true); } - else if (this.PageBreakInside == CssConstants.Avoid - && ActualHeight + Location.Y > HtmlContainer.PageSize.Height - && prevSibling != null) + else if (this.PageBreakInside == CssConstants.Avoid && prevSibling != null) { // handle page break avoiding. - this.BreakPage(true); + var pageLocationY = Location.Y % HtmlContainer.PageSize.Height; + if (ActualHeight + pageLocationY > HtmlContainer.PageSize.Height) + { + this.BreakPage(true); + } } //Start with the assumption this is zero height. @@ -739,7 +741,6 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g) } else { - var prevSibling = DomUtils.GetPreviousSibling(this); if (prevSibling != null) { if (Location == RPoint.Empty)