Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page break inside improvement #16

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
This is on page 2
</div>

<div style="height: 700px; background-color: red;">
<div style="height: 400px; background-color: red;">
This is on page 3.
</div>

Expand All @@ -18,8 +18,11 @@
<div style="height: 500px; background-color: yellow;">
This is also on page 4
</div>
<div style="height: 100px; background-color: brown; page-break-inside: avoid;">
This is also on page 4.
</div>

<div style="height: 400px; background-color: aqua; page-break-inside: avoid;">
<div style="height: 700px; background-color: aqua; page-break-inside: avoid;">
This is on page 5
</div>
</div>
Expand All @@ -29,8 +32,7 @@
This is on page 6
</div>

<div style="background-color:yellowgreen;width:90px;height: 1000px;">
</div>
<div style="background-color: yellowgreen; width: 90px; height: 1000px;"></div>
</div>

</body>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<body>
<div style="height: 700px; background-color: indianred;">
This is on page 1
</div>
<div style="background-color: orange; page-break-inside: avoid;">
<div style="background-color: yellowgreen; width: 90px; height: 1000px;"></div>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion Source/Demos/HtmlRenderer.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions Source/HtmlRenderer/Core/Dom/CssBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ public virtual void Dispose()
/// <param name="g">Device context to use</param>
protected virtual async Task PerformLayoutImpAsync(RGraphics g)
{
var prevSibling = DomUtils.GetPreviousSibling(this);
if (Display != CssConstants.None)
{
RectanglesReset();
Expand Down Expand Up @@ -652,7 +653,6 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g)

if (Display != CssConstants.TableCell)
{
var prevSibling = DomUtils.GetPreviousSibling(this);
double left;
double top;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -739,7 +741,6 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g)
}
else
{
var prevSibling = DomUtils.GetPreviousSibling(this);
if (prevSibling != null)
{
if (Location == RPoint.Empty)
Expand Down
Loading