Skip to content

Commit

Permalink
Fix and test broken absolutes in lines
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Mar 25, 2022
1 parent 089ffa4 commit fe1f3d9
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 6 deletions.
106 changes: 106 additions & 0 deletions tests/draw/test_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,109 @@ def test_absolute_rtl_4():
<div>bbb</div>
'''
assert_pixels('absolute_rtl_4', 16, 3, expected_pixels, html)


@assert_no_logs
def test_absolute_pages_counter():
expected_pixels = '''
______
_RR___
_RR___
_RR___
_RR___
_____B
______
_RR___
_RR___
_BB___
_BB___
_____B
'''
html = '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
background: white;
font-family: weasyprint;
margin: 1px;
size: 6px 6px;
@bottom-right-corner {
color: blue;
content: counter(pages);
font-size: 1px;
}
}
body {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
orphans: 1;
widows: 1;
}
div {
color: blue;
position: absolute;
}
</style>
a a a <div>a a</div>
'''
assert_pixels('absolute_pages_counter', 6, 12, expected_pixels, html)


@assert_no_logs
def test_absolute_pages_counter_orphans():
expected_pixels = '''
______
_RR___
_RR___
_RR___
_RR___
______
______
______
_____B
______
_RR___
_RR___
_BB___
_BB___
_GG___
_GG___
______
_____B
'''
html = '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
background: white;
font-family: weasyprint;
margin: 1px;
size: 6px 9px;
@bottom-right-corner {
color: blue;
content: counter(pages);
font-size: 1px;
}
}
body {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
orphans: 2;
widows: 2;
}
div {
color: blue;
position: absolute;
}
div ~ div {
color: lime;
}
</style>
a a a <div>a a a</div> a <div>a a a</div>
'''
assert_pixels(
'absolute_pages_counter_orphans', 6, 18, expected_pixels, html)
19 changes: 13 additions & 6 deletions weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,9 @@ def _out_of_flow_layout(context, box, index, child, new_children,
return stop, resume_at, out_of_flow_resume_at


def _break_line(box, new_children, lines_iterator, page_is_empty, index,
skip_stack, resume_at):
def _break_line(context, box, line, new_children, lines_iterator,
page_is_empty, index, skip_stack, resume_at, absolute_boxes,
fixed_boxes):
over_orphans = len(new_children) - box.style['orphans']
if over_orphans < 0 and not page_is_empty:
# Reached the bottom of the page before we had
Expand All @@ -277,8 +278,12 @@ def _break_line(box, new_children, lines_iterator, page_is_empty, index,
return True, False, resume_at
if needed and needed <= over_orphans:
# Remove lines to keep them for the next page
for child in new_children[-needed:]:
remove_placeholders(
context, child.children, absolute_boxes, fixed_boxes)
del new_children[-needed:]
# Page break here, resume before this line
remove_placeholders(context, line.children, absolute_boxes, fixed_boxes)
return False, True, {index: skip_stack}


Expand Down Expand Up @@ -318,8 +323,9 @@ def _linebox_layout(context, box, index, child, new_children, page_is_empty,
context.overflows_page(bottom_space, new_position_y + offset_y))
if overflow:
abort, stop, resume_at = _break_line(
box, new_children, lines_iterator, page_is_empty, index,
skip_stack, resume_at)
context, box, line, new_children, lines_iterator,
page_is_empty, index, skip_stack, resume_at, absolute_boxes,
fixed_boxes)
break

# TODO: this is incomplete.
Expand Down Expand Up @@ -351,8 +357,9 @@ def _linebox_layout(context, box, index, child, new_children, page_is_empty,
context.report_footnote(footnote)
if footnote.style['footnote_policy'] == 'line':
abort, stop, resume_at = _break_line(
box, new_children, lines_iterator, page_is_empty,
index, skip_stack, resume_at)
context, box, line, new_children, lines_iterator,
page_is_empty, index, skip_stack, resume_at,
absolute_boxes, fixed_boxes)
break_linebox = True
elif footnote.style['footnote_policy'] == 'block':
abort = break_linebox = True
Expand Down

0 comments on commit fe1f3d9

Please sign in to comment.