From 016bd81519e5697685c6bcab39d34a0b11f2a920 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Mon, 25 Mar 2024 11:18:24 +0100 Subject: [PATCH] Fix many different bugs with SVG markers --- tests/draw/svg/test_markers.py | 182 ++++++++++++++++++++++++++++++--- weasyprint/svg/__init__.py | 25 ++--- 2 files changed, 173 insertions(+), 34 deletions(-) diff --git a/tests/draw/svg/test_markers.py b/tests/draw/svg/test_markers.py index da176a1a9..0266b59d1 100644 --- a/tests/draw/svg/test_markers.py +++ b/tests/draw/svg/test_markers.py @@ -7,18 +7,18 @@ def test_markers(assert_pixels): assert_pixels(''' ___________ - ____RRR____ - ____RRR____ - ____RRR____ ___________ - ____RRR____ - ____RRR____ - ____RRR____ + _____RRR___ + _____RRR___ + _____RRR___ ___________ - ____RRR____ - ____RRR____ - ____RRR____ + _____RRR___ + _____RRR___ + _____RRR___ ___________ + _____RRR___ + _____RRR___ + _____RRR___ ''', ''' + + + + + + + + + + ''') + + +@assert_no_logs +def test_markers_userspace(assert_pixels): + assert_pixels(''' + ___________ + ___________ + _____R_____ + ___________ + ___________ + ___________ + _____R_____ + ___________ + ___________ + ___________ + _____R_____ + ___________ + ___________ + ''', ''' + + + + + + + + + + ''') + + +@assert_no_logs +def test_markers_stroke_width(assert_pixels): + assert_pixels(''' + ___________ + ___________ + _____RRR___ + _____RRR___ + _____RRR___ + ___________ + _____RRR___ + _____RRR___ + _____RRR___ + ___________ + _____RRR___ + _____RRR___ + _____RRR___ + ''', ''' + + + + + + + + + + ''') + + +@assert_no_logs +def test_markers_viewbox_stroke_width(assert_pixels): + assert_pixels(''' + ___________ + ____BRR____ + ____RRR____ + ____RRR____ + ___________ + ____BRR____ + ____RRR____ + ____RRR____ + ___________ + ____BRR____ + ____RRR____ + ____RRR____ + ___________ + ''', ''' + + + + + + + + + + + ''') diff --git a/weasyprint/svg/__init__.py b/weasyprint/svg/__init__.py index 031b3fe94..b1387e504 100644 --- a/weasyprint/svg/__init__.py +++ b/weasyprint/svg/__init__.py @@ -569,11 +569,11 @@ def draw_markers(self, node, font_size, fill_stroke): translate_x, translate_y = self.point( marker_node.get('refX'), marker_node.get('refY'), font_size) + marker_width, marker_height = self.point( + marker_node.get('markerWidth', 3), + marker_node.get('markerHeight', 3), + font_size) if 'viewBox' in marker_node.attrib: - marker_width, marker_height = self.point( - marker_node.get('markerWidth', 3), - marker_node.get('markerHeight', 3), - font_size) scale_x, scale_y, _, _ = preserve_ratio( self, marker_node, font_size, marker_width, marker_height) @@ -603,19 +603,8 @@ def draw_markers(self, node, font_size, fill_stroke): clip_x, clip_y, marker_width / scale_x, marker_height / scale_y) else: - marker_width, marker_height = self.point( - marker_node.get('markerWidth', 3), - marker_node.get('markerHeight', 3), - font_size) - box = self.calculate_bounding_box(marker_node, font_size) - if is_valid_bounding_box(box): - scale_x = scale_y = min( - marker_width / box[2], marker_height / box[3]) - translate_x /= scale_x - translate_y /= scale_y - else: - scale_x = scale_y = 1 - clip_box = None + scale_x = scale_y = 1 + clip_box = (0, 0, marker_width, marker_height) # Scale if marker_node.get('markerUnits') != 'userSpaceOnUse': @@ -641,7 +630,7 @@ def draw_markers(self, node, font_size, fill_stroke): self.stream.transform(e=-translate_x, f=-translate_y) overflow = marker_node.get('overflow', 'hidden') - if clip_box and overflow in ('hidden', 'scroll'): + if overflow in ('hidden', 'scroll'): self.stream.rectangle(*clip_box) self.stream.clip() self.stream.end()