Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: space out no-repeat patterns more #1541

Merged
merged 1 commit into from
Jan 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: space out no-repeat patterns more
This ensures the edges of a repeating pattern don't show up on the edge of the painting area in some PDF viewers. Closes #1539.
  • Loading branch information
aschmitz authored Jan 17, 2022
commit 35386ab27549748cebbc5400507ebafc1c6dd895
13 changes: 5 additions & 8 deletions weasyprint/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ def draw_background_image(stream, layer, image_rendering):

if repeat_x == 'no-repeat':
# We want at least the whole image_width drawn on sub_surface, but we
# want to be sure it will not be repeated on the painting_width.
repeat_width = max(image_width, painting_width)
# want to be sure it will not be repeated on the painting_width. We
# double the painting width to ensure viewers don't incorrectly bleed
# the edge of the pattern into the painting area. (See #1539.)
repeat_width = max(image_width, 2 * painting_width)
elif repeat_x in ('repeat', 'round'):
# We repeat the image each image_width.
repeat_width = image_width
Expand All @@ -399,7 +401,7 @@ def draw_background_image(stream, layer, image_rendering):

# Comments above apply here too.
if repeat_y == 'no-repeat':
repeat_height = max(image_height, painting_height)
repeat_height = max(image_height, 2 * painting_height)
elif repeat_y in ('repeat', 'round'):
repeat_height = image_height
else:
Expand All @@ -412,11 +414,6 @@ def draw_background_image(stream, layer, image_rendering):
else:
repeat_height = image_height

if repeat_x == repeat_y == 'no-repeat':
# PDF patterns always repeat, use a big number to hide repetition
repeat_width = 2 * stream.page_rectangle[2]
repeat_height = 2 * stream.page_rectangle[3]

matrix = Matrix(e=position_x + positioning_x, f=position_y + positioning_y)
matrix @= stream.ctm
pattern = stream.add_pattern(
Expand Down