Skip to content

Commit

Permalink
Set page background origin to margin box when attachment is fixed
Browse files Browse the repository at this point in the history
Fix #1993.
  • Loading branch information
liZe committed Nov 9, 2023
1 parent bc0798b commit 3b6f826
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
36 changes: 36 additions & 0 deletions tests/draw/test_background.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,42 @@ def test_background_size_clip(assert_pixels):
<body>''')


@assert_no_logs
def test_page_background_fixed(assert_pixels):
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1993
assert_pixels('''
RBBB
BBBB
BBBB
BBBB
''', '''
<style>
@page { size: 4px; margin: 1px;
background: url(pattern.png) red;
background-attachment: fixed; }
</style>
<body>''')


@assert_no_logs
def test_page_background_fixed_bleed(assert_pixels):
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1993
assert_pixels('''
RRRRRR
RRBBBR
RBBBBR
RBBBBR
RBBBBR
RRRRRR
''', '''
<style>
@page { size: 4px; margin: 1px; bleed: 1px;
background: url(pattern.png) no-repeat red;
background-attachment: fixed; }
</style>
<body>''')


@assert_no_logs
def test_bleed_background_size_clip(assert_pixels):
# Regression test for https://github.com/Kozea/WeasyPrint/issues/1943
Expand Down
8 changes: 7 additions & 1 deletion weasyprint/layout/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ def layout_background_layer(box, page, resolution, image, size, clip, repeat,

if attachment == 'fixed':
# Initial containing block
positioning_area = box_rectangle(page, 'content-box')
if isinstance(box, boxes.PageBox):
# […] if background-attachment is fixed then the image is
# positioned relative to the page box including its margins […].
# https://drafts.csswg.org/css-page/#painting
positioning_area = (0, 0, box.margin_width(), box.margin_height())
else:
positioning_area = box_rectangle(page, 'content-box')
else:
positioning_area = box_rectangle(box, origin)

Expand Down

0 comments on commit 3b6f826

Please sign in to comment.