Skip to content

Commit

Permalink
Merge branch '62.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed May 27, 2024
2 parents e00e393 + 96286be commit 4d2f932
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/exe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install requirements
run: python -m pip install . pyinstaller
- name: Generate executable
run: python -m PyInstaller weasyprint/__main__.py -n weasyprint -F
run: python -m PyInstaller weasyprint/__main__.py -n weasyprint -F --hidden-import "fontTools.ttLib.tables.V_A_R_C_"
- name: Test executable
run: dist/weasyprint --info
- name: Store executable
Expand Down
9 changes: 9 additions & 0 deletions tests/css/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ def test_variable_chain_root_missing():
''')


def test_variable_chain_root_missing_inherited():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/2164
page, = render_pages('''
<style>
html { --var1: var(--var-missing); font: var(--var1) }
</style>a
''')


@assert_no_logs
def test_variable_shorthand_margin():
page, = render_pages('''
Expand Down
52 changes: 52 additions & 0 deletions tests/draw/test_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,58 @@ def test_absolute_split_11(assert_pixels):
''')


@assert_no_logs
def test_absolute_split_12(assert_pixels):
assert_pixels('''
BBBBBB__
BBBBBB__
________
________
________
________
________
________
BB______
BB______
BBRR____
BBRR____
BBRRRR__
BBRRRR__
BBRRRRRR
BBRRRRRR
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 8px;
}
body {
color: blue;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div {
break-inside: avoid;
}
section {
left: 2px;
position: absolute;
color: red;
}
</style>
aaa
<div>
a
<section>x<br>xx<br>xxx</section>
<br>
a<br>
a<br>
a
</div>
''')


@pytest.mark.xfail
@assert_no_logs
def test_absolute_next_page(assert_pixels):
Expand Down
1 change: 0 additions & 1 deletion tests/draw/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,6 @@ def test_float_split_9(assert_pixels):
<div>bbbbb bb</div>''')


@pytest.mark.xfail
@assert_no_logs
def test_float_split_10(assert_pixels):
assert_pixels('''
Expand Down
46 changes: 46 additions & 0 deletions tests/layout/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,3 +769,49 @@ def test_float_fail():
body, = html.children
paragraph, = body.children
line1, line2, line3 = paragraph.children


def test_float_table_aborted_row():
page1, page2 = render_pages('''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {size: 10px 7px}
body {font-family: weasyprint; font-size: 2px; line-height: 1}
div {float: right; orphans: 1}
td {break-inside: avoid}
</style>
<table><tbody>
<tr><td>abc</td></tr>
<tr><td>abc</td></tr>
<tr><td>def <div>f<br>g</div> ghi</td></tr>
</tbody></table>
''')

html, = page1.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
tbody, = table.children
for tr in tbody.children:
td, = tr.children
line, = td.children
textbox, = line.children
assert textbox.text == 'abc'

html, = page2.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
tbody, = table.children
tr, = tbody.children
td, = tr.children
line1, line2 = td.children
textbox, div = line1.children
assert textbox.text == 'def '
textbox, = line2.children
assert textbox.text == 'ghi'
line1, line2 = div.children
textbox, br = line1.children
assert textbox.text == 'f'
textbox, = line2.children
assert textbox.text == 'g'
2 changes: 1 addition & 1 deletion weasyprint/css/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ def __missing__(self, key):
try:
value = value.solve(solved_tokens, original_key)
except InvalidValues:
if key in INHERITED:
if key in INHERITED and parent_style is not None:
# Values in parent_style are already computed.
self[key] = value = parent_style[key]
else:
Expand Down
12 changes: 7 additions & 5 deletions weasyprint/layout/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ def _out_of_flow_layout(context, box, index, child, new_children,
last_in_flow_child = find_last_in_flow_child(new_children)
page_break = block_level_page_break(last_in_flow_child, child)
resume_at = {index: None}
out_of_flow_resume_at = None
stop = True
if new_children and avoid_page_break(page_break, context):
# Can’t break inside float, find an earlier page break.
Expand All @@ -283,7 +284,7 @@ def _out_of_flow_layout(context, box, index, child, new_children,
if result:
# Earlier page break found, drop whole child rendering.
new_children[:], resume_at = result
new_child = out_of_flow_resume_at = None
new_child = None

# Running element layout.
elif child.is_running():
Expand All @@ -301,6 +302,7 @@ def _break_line(context, box, line, new_children, lines_iterator,
if over_orphans < 0 and not page_is_empty:
# Reached the bottom of the page before we had
# enough lines for orphans, cancel the whole box.
remove_placeholders(context, line.children, absolute_boxes, fixed_boxes)
return True, False, resume_at
# How many lines we need on the next page to satisfy widows
# -1 for the current line.
Expand All @@ -312,6 +314,7 @@ def _break_line(context, box, line, new_children, lines_iterator,
break
if needed > over_orphans and not page_is_empty:
# Total number of lines < orphans + widows
remove_placeholders(context, line.children, absolute_boxes, fixed_boxes)
return True, False, resume_at
if needed and needed <= over_orphans:
# Remove lines to keep them for the next page
Expand Down Expand Up @@ -764,10 +767,9 @@ def block_container_layout(context, box, bottom_space, skip_stack,
if (box_is_fragmented and
avoid_page_break(box.style['break_inside'], context) and
not page_is_empty):
for footnote in all_footnotes:
context.unlayout_footnote(footnote)
return (
None, None, {'break': 'any', 'page': None}, [], False, max_lines)
remove_placeholders(
context, [*new_children, *box.children[skip:]], absolute_boxes, fixed_boxes)
return None, None, {'break': 'any', 'page': None}, [], False, max_lines

for key, value in broken_out_of_flow.items():
context.broken_out_of_flow[key] = value
Expand Down
1 change: 0 additions & 1 deletion weasyprint/layout/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def float_layout(context, box, containing_block, absolute_boxes, fixed_boxes,
box = find_float_position(context, box, containing_block)

context.excluded_shapes.append(box)

return box, resume_at


Expand Down
4 changes: 1 addition & 3 deletions weasyprint/layout/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ def group_layout(group, position_y, bottom_space, page_is_empty,
# other content on the page.
if not page_is_empty and context.overflows_page(
bottom_space, next_position_y):
for descendant in row.descendants():
if descendant.footnote is not None:
context.unlayout_footnote(descendant.footnote)
remove_placeholders(context, row.children, absolute_boxes, fixed_boxes)
if new_group_children:
previous_row = new_group_children[-1]
page_break = block_level_page_break(previous_row, row)
Expand Down

0 comments on commit 4d2f932

Please sign in to comment.