diff --git a/tests/draw/svg/test_opacity.py b/tests/draw/svg/test_opacity.py index 5aa5d353..b3f780de 100644 --- a/tests/draw/svg/test_opacity.py +++ b/tests/draw/svg/test_opacity.py @@ -129,3 +129,18 @@ def test_pattern_gradient_stroke_fill_opacity(assert_same_renderings): ''', tolerance=1, ) + + +@assert_no_logs +def test_translate_opacity(assert_same_renderings): + # Regression test for https://github.com/Kozea/WeasyPrint/issues/1976 + assert_same_renderings( + opacity_source % ''' + + ''', + opacity_source % ''' + + ''', + ) diff --git a/weasyprint/svg/__init__.py b/weasyprint/svg/__init__.py index ffb6720e..f9c8f0cb 100644 --- a/weasyprint/svg/__init__.py +++ b/weasyprint/svg/__init__.py @@ -394,19 +394,17 @@ class SVG: if filter_: apply_filters(self, node, filter_, font_size) + # Apply transform attribute + self.transform(node.get('transform'), font_size) + # Create substream for opacity opacity = float(node.get('opacity', 1)) if fill_stroke and 0 <= opacity < 1: original_stream = self.stream box = self.calculate_bounding_box(node, font_size) - if is_valid_bounding_box(box): - coords = (box[0], box[1], box[0] + box[2], box[1] + box[3]) - else: - coords = (0, 0, self.inner_width, self.inner_height) - self.stream = self.stream.add_group(*coords) - - # Apply transform attribute - self.transform(node.get('transform'), font_size) + if not is_valid_bounding_box(box): + box = (0, 0, self.inner_width, self.inner_height) + self.stream = self.stream.add_group(*box) # Clip clip_path = parse_url(node.get('clip-path')).fragment