Bug 707323: Fix page-breaks with restarting layout.
authorRobin Watts <[email protected]>
Wed, 15 Nov 2023 18:07:15 +0000 (18:07 +0000)
committerSebastian Rasmussen <[email protected]>
Fri, 24 Nov 2023 14:39:34 +0000 (15:39 +0100)
Page breaks were terminating the layout process in unexpected
ways.

Also fix page-break-after with tables.

source/html/html-layout.c

index 09121642dee77c2ab4614a01d70034e541accfa0..941623d33fbdab5841363a33e3c7c6dc0e456e18 100644 (file)
@@ -1111,7 +1111,11 @@ static void layout_table(fz_context *ctx, layout_data *ld, fz_html_box *box, fz_
        }
 
        /* TODO: remove 'vertical' margin adjustments across automatic page breaks */
-       if (layout_block_page_break(ctx, ld, &top->s.layout.b, box->style->page_break_before))
+       if (restart && restart->start != NULL)
+       {
+               /* We're still skipping, don't check for pagebreak before! */
+       }
+       else if (layout_block_page_break(ctx, ld, &top->s.layout.b, box->style->page_break_before))
                eop = 1;
 
        /* Position table in box flow, and add margins and padding */
@@ -1283,6 +1287,22 @@ static void layout_table(fz_context *ctx, layout_data *ld, fz_html_box *box, fz_
                fz_free(ctx, colw);
        fz_catch(ctx)
                fz_rethrow(ctx);
+
+       if (restart && restart->start != NULL)
+       {
+               /* We're still skipping, don't check for pagebreak after! */
+       }
+       else if (layout_block_page_break(ctx, ld, &top->s.layout.b, box->style->page_break_after))
+       {
+               if (restart && restart->end == NULL)
+               {
+                       if (restart->potential)
+                               restart->end = restart->potential;
+                       else
+                               restart->end = box;
+                       return;
+               }
+       }
 }
 
 /* === LAYOUT BLOCKS === */
@@ -1330,7 +1350,11 @@ static void layout_block(fz_context *ctx, layout_data *ld, fz_html_box *box, fz_
        }
 
        /* TODO: remove 'vertical' margin adjustments across automatic page breaks */
-       if (layout_block_page_break(ctx, ld, &top->s.layout.b, style->page_break_before))
+       if (restart && restart->start != NULL)
+       {
+               /* We're still skipping, don't check for pagebreak before! */
+       }
+       else if (layout_block_page_break(ctx, ld, &top->s.layout.b, style->page_break_before))
                eop = 1;
 
        /* Important to remember that box->{x,y,w,b} are the coordinates of the content. The
@@ -1431,7 +1455,21 @@ static void layout_block(fz_context *ctx, layout_data *ld, fz_html_box *box, fz_
                box->s.layout.b += fz_from_css_number_scale(style->line_height, em);
        }
 
-       (void) layout_block_page_break(ctx, ld, &box->s.layout.b, style->page_break_after);
+       if (restart && restart->start != NULL)
+       {
+               /* We're still skipping, don't check for pagebreak after! */
+       }
+       else if (layout_block_page_break(ctx, ld, &box->s.layout.b, style->page_break_after))
+       {
+               if (restart && restart->end == NULL)
+               {
+                       if (restart->potential)
+                               restart->end = restart->potential;
+                       else
+                               restart->end = box;
+                       return;
+               }
+       }
 }
 
 /* === LAYOUT === */