Skip to content

Commit e132e92

Browse files
authored
Merge pull request #15 from alfattack/page-break-inside
Support page-break-inside: avoid
2 parents 67d4925 + f7de9db commit e132e92

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

Source/Demos/HtmlRenderer.Demo.Common/TestSamples/36.Breaking Pages Divs.htm renamed to Source/Demos/HtmlRenderer.Demo.Common/TestSamples/36.Breaking pages 3 - Divs.htm

File renamed without changes.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<html>
2+
<body>
3+
<div style="height: 826px; background-color: indianred; page-break-inside: avoid;">
4+
This is on page 1
5+
</div>
6+
7+
<div style="height: 900px; background-color: purple; page-break-inside: avoid;">
8+
This is on page 2
9+
</div>
10+
11+
<div style="height: 700px; background-color: red;">
12+
This is on page 3.
13+
</div>
14+
15+
<div style="page-break-inside: avoid; height: 1500px; background-color: blue; padding: 10px;">
16+
This is on page 4.
17+
18+
<div style="height: 500px; background-color: yellow;">
19+
This is also on page 4
20+
</div>
21+
22+
<div style="height: 400px; background-color: aqua; page-break-inside: avoid;">
23+
This is on page 5
24+
</div>
25+
</div>
26+
27+
<div style="background-color: orange; padding: 10px; page-break-inside: avoid;">
28+
<div>
29+
This is on page 6
30+
</div>
31+
32+
<div style="background-color:yellowgreen;width:90px;height: 1000px;">
33+
</div>
34+
</div>
35+
36+
</body>
37+
</html>

Source/Demos/HtmlRenderer.Demo.Console/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
foreach (var htmlSample in samples)
2525
{
2626
////Just doing one test here. Comment this for all of them.
27-
if (!htmlSample.FullName.Contains("37", StringComparison.OrdinalIgnoreCase)) continue;
27+
if (!htmlSample.FullName.Contains("38")) continue;
2828

2929
//await skia.GenerateSampleAsync(htmlSample);
3030
//await svgSkia.GenerateSampleAsync(htmlSample);

Source/HtmlRenderer/Core/Dom/CssBox.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,13 @@ protected virtual async Task PerformLayoutImpAsync(RGraphics g)
700700
{
701701
this.BreakPage(true);
702702
}
703+
else if (this.PageBreakInside == CssConstants.Avoid
704+
&& ActualHeight + Location.Y > HtmlContainer.PageSize.Height
705+
&& prevSibling != null)
706+
{
707+
// handle page break avoiding.
708+
this.BreakPage(true);
709+
}
703710

704711
//Start with the assumption this is zero height.
705712
ActualBottom = Location.Y;

0 commit comments

Comments
 (0)