From 465afd07bca22ee859d4a2faec62cff32866eaa6 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 12 Nov 2024 11:36:38 +0100 Subject: [PATCH] =?UTF-8?q?Set=20alpha=20even=20when=20current=20color=20c?= =?UTF-8?q?hannels=20didn=E2=80=99t=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #2302. --- tests/draw/test_opacity.py | 9 +++++++++ weasyprint/pdf/stream.py | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/draw/test_opacity.py b/tests/draw/test_opacity.py index 3d56665ad..bab36ffdd 100644 --- a/tests/draw/test_opacity.py +++ b/tests/draw/test_opacity.py @@ -58,3 +58,12 @@ def test_opacity_percent_clamp_up(assert_same_renderings): opacity_source % '
', opacity_source % '
', ) + + +@assert_no_logs +def test_opacity_black(assert_same_renderings): + # Regression test for https://github.com/Kozea/WeasyPrint/issues/2302 + assert_same_renderings( + opacity_source % 'ab', + opacity_source % 'ab', + ) diff --git a/weasyprint/pdf/stream.py b/weasyprint/pdf/stream.py index ec3274a9d..8a0aa09a8 100644 --- a/weasyprint/pdf/stream.py +++ b/weasyprint/pdf/stream.py @@ -81,6 +81,8 @@ def end_text(self): def set_color(self, color, stroke=False): *channels, alpha = color + self.set_alpha(alpha, stroke) + if stroke: if (color.space, *channels) == self._current_color_stroke: return @@ -105,7 +107,6 @@ def set_color(self, color, stroke=False): else: LOGGER.warn('Unsupported color space %s, use sRGB instead', color.space) self.set_color_rgb(*channels, stroke) - self.set_alpha(alpha, stroke) def set_font_size(self, font, size): if (font, size) == self._current_font: