From 7fe4b06638fd2f7835ad6a64b6cc0092f8e2f34c Mon Sep 17 00:00:00 2001 From: Xavid Pretzer Date: Fri, 21 Jun 2024 16:52:10 -0400 Subject: [PATCH] Use an image directly rather than via a pattern when the background is no-repeat. --- weasyprint/draw/__init__.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/weasyprint/draw/__init__.py b/weasyprint/draw/__init__.py index 783a9bbd..46154f46 100644 --- a/weasyprint/draw/__init__.py +++ b/weasyprint/draw/__init__.py @@ -262,6 +262,24 @@ def draw_background_image(stream, layer, image_rendering): repeat_x, repeat_y = layer.repeat image_width, image_height = layer.size + if repeat_x == 'no-repeat' and repeat_y == 'no-repeat': + # We don't use a pattern when we don't need to because some viewers + # (e.g., Preview on Mac) introduce unnecessary pixelation when vector + # images are used in patterns. + if not layer.unbounded: + stream.rectangle(painting_x, painting_y, painting_width, + painting_height) + stream.clip() + stream.end() + # Put the image in a group so that masking outside the image and + # masking within the image don't conflict. + group = stream.add_group(*stream.page_rectangle) + group.transform(e=position_x + positioning_x, + f=position_y + positioning_y) + layer.image.draw(group, image_width, image_height, image_rendering) + stream.draw_x_object(group.id) + return + 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. We