Skip to content

Commit

Permalink
Copy replaced boxes during layout
Browse files Browse the repository at this point in the history
Fix #808, fix #387.
  • Loading branch information
liZe committed Mar 1, 2019
1 parent aeb8020 commit f79110c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions weasyprint/layout/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ def block_replaced_width(box, containing_block, device_size):

def block_replaced_box_layout(box, containing_block, device_size):
"""Lay out the block :class:`boxes.ReplacedBox` ``box``."""
box = box.copy()
if box.style['width'] == 'auto' and box.style['height'] == 'auto':
computed_margins = box.margin_left, box.margin_right
block_replaced_width.without_min_max(
Expand Down
1 change: 1 addition & 0 deletions weasyprint/layout/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ def atomic_box(context, box, position_x, skip_stack, containing_block,
device_size, absolute_boxes, fixed_boxes):
"""Compute the width and the height of the atomic ``box``."""
if isinstance(box, boxes.ReplacedBox):
box = box.copy()
if getattr(box, 'is_list_marker', False):
image_marker_layout(box)
else:
Expand Down
65 changes: 65 additions & 0 deletions weasyprint/tests/test_draw/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
]
table = [
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + r + B + B + B + _ + _,
_ + _ + B + B + B + B + _ + _,
_ + _ + B + B + B + B + _ + _,
_ + _ + B + B + B + B + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,

_ + _ + r + B + B + B + _ + _,
_ + _ + B + B + B + B + _ + _,
_ + _ + B + B + B + B + _ + _,
_ + _ + B + B + B + B + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
_ + _ + _ + _ + _ + _ + _ + _,
]


@assert_no_logs
Expand Down Expand Up @@ -198,6 +217,52 @@ def test_images_page_break():
<div style="page-break-before: right"><img src="pattern.png"></div>''')


@assert_no_logs
def test_image_repeat_inline():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/808
assert_pixels('image_page_repeat_inline', 8, 2 * 8, table, '''
<style>
@page { size: 8px; margin: 0; background: #fff }
table { border-collapse: collapse; margin: 2px }
th, td { border: none; padding: 0 }
th { height: 4px; line-height: 4px }
td { height: 2px }
img { vertical-align: top }
</style>
<table>
<thead>
<tr><th><img src="pattern.png"></th></tr>
</thead>
<tbody>
<tr><td></td></tr>
<tr><td></td></tr>
</tbody>
</table>''')


@assert_no_logs
def test_image_repeat_block():
# Test regression: https://github.com/Kozea/WeasyPrint/issues/808
assert_pixels('image_page_repeat_block', 8, 2 * 8, table, '''
<style>
@page { size: 8px; margin: 0; background: #fff }
table { border-collapse: collapse; margin: 2px }
th, td { border: none; padding: 0 }
th { height: 4px }
td { height: 2px }
img { display: block }
</style>
<table>
<thead>
<tr><th><img src="pattern.png"></th></tr>
</thead>
<tbody>
<tr><td></td></tr>
<tr><td></td></tr>
</tbody>
</table>''')


@assert_no_logs
def test_images_padding():
# Regression test: padding used to be ignored on images
Expand Down

0 comments on commit f79110c

Please sign in to comment.