Skip to content

Commit d5230e1

Browse files
committed
Take care of extra advancement when expanding to reach the bottom
1 parent 69c4848 commit d5230e1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

weasyprint/layout/grid.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ def _add_page_children(max_row=inf):
13811381
last_page_row = max(new_children_by_rows)
13821382
next_page_first_row = min(resume_at)
13831383
next_page_last_row = max(resume_at)
1384+
extra_advancement = 0
13841385
for y in range(last_page_row, next_page_first_row - 1, -1):
13851386
for x, child in new_children_by_rows[y]:
13861387
span = _get_span(child.style['grid_row_start'])
@@ -1394,13 +1395,23 @@ def _add_page_children(max_row=inf):
13941395
context.page_bottom - bottom_space - child.position_y -
13951396
child.margin_top - child.border_top_width - child.padding_top -
13961397
child.margin_bottom - child.border_bottom_width - child.padding_bottom)
1397-
if not broken_child:
1398-
# Child fully drawn, no need to keep advancement.
1399-
continue
1400-
advancements[x, y] = child.margin_height()
1401-
if (x, y) in old_advancements:
1402-
advancements[x, y] += old_advancements[x, y] - extra_skip_height
1398+
if broken_child:
1399+
# Child not fully drawn, keep advancement.
1400+
advancements[x, y] = child.margin_height()
1401+
if (x, y) in old_advancements:
1402+
advancements[x, y] += old_advancements[x, y] - extra_skip_height
1403+
else:
1404+
# Child fully drawn, save the extra height added to reach the bottom of
1405+
# the page to substract it from the advancements.
1406+
extra_advancement = max(extra_advancement, child.height - child_height)
1407+
1408+
# Substract the extra height added to reach the bottom of the page from all the
1409+
# advancements.
1410+
if extra_advancement:
1411+
for x, y in advancements:
1412+
advancements[x, y] -= extra_advancement
14031413

1414+
# Set box height and remove bottom decoration.
14041415
box.height = (
14051416
context.page_bottom - bottom_space - box.position_y -
14061417
box.margin_top - box.border_top_width - box.padding_top)

0 commit comments

Comments
 (0)