Skip to content

Commit

Permalink
Merge pull request #2303 from Kozea/fix-2302
Browse files Browse the repository at this point in the history
Set alpha even when current color channels didn’t change
  • Loading branch information
liZe authored Nov 12, 2024
2 parents d0fcb3c + 465afd0 commit 9d028fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/draw/test_opacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,12 @@ def test_opacity_percent_clamp_up(assert_same_renderings):
opacity_source % '<div></div><div style="opacity: -0.2"></div>',
opacity_source % '<div></div><div style="opacity: -20%"></div>',
)


@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 % 'a<span style="color: rgb(0, 0, 0, 0.5)">b</span>',
opacity_source % 'a<span style="opacity: 0.5">b</span>',
)
3 changes: 2 additions & 1 deletion weasyprint/pdf/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 9d028fb

Please sign in to comment.