From 7b4bbab1d14e88157a3d5a8400daf228feabcc25 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Mon, 22 Jan 2024 23:10:10 +0100 Subject: [PATCH] Ensure that bounding box is set to invisible but displayed text tags Related to #2030. --- weasyprint/svg/__init__.py | 9 +++++++-- weasyprint/svg/text.py | 5 +---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/weasyprint/svg/__init__.py b/weasyprint/svg/__init__.py index bf592863c..16e287020 100644 --- a/weasyprint/svg/__init__.py +++ b/weasyprint/svg/__init__.py @@ -9,7 +9,8 @@ from ..urls import get_url_attribute from .bounding_box import ( - bounding_box, extend_bounding_box, is_valid_bounding_box) + EMPTY_BOUNDING_BOX, bounding_box, extend_bounding_box, + is_valid_bounding_box) from .css import parse_declarations, parse_stylesheets from .defs import ( apply_filters, clip_path, draw_gradient_or_pattern, paint_mask, use) @@ -449,6 +450,10 @@ def draw_node(self, node, font_size, fill_stroke=True): original_streams.append(self.stream) self.stream = group + # Set text bounding box + if node.display and TAGS.get(node.tag) == text: + node.text_bounding_box = EMPTY_BOUNDING_BOX + # Draw node if node.visible and node.tag in TAGS: with suppress(PointError): @@ -458,7 +463,7 @@ def draw_node(self, node, font_size, fill_stroke=True): if node.display and node.tag not in DEF_TYPES: for child in node: self.draw_node(child, font_size, fill_stroke) - if node.tag in ('text', 'tspan') and child.visible: + if TAGS.get(node.tag) == text and child.visible: if not is_valid_bounding_box(child.text_bounding_box): continue x1, y1 = child.text_bounding_box[:2] diff --git a/weasyprint/svg/text.py b/weasyprint/svg/text.py index d5adcb732..e7b4c6831 100644 --- a/weasyprint/svg/text.py +++ b/weasyprint/svg/text.py @@ -3,7 +3,7 @@ from math import cos, inf, radians, sin from ..matrix import Matrix -from .bounding_box import EMPTY_BOUNDING_BOX, extend_bounding_box +from .bounding_box import extend_bounding_box from .utils import normalize, size @@ -113,9 +113,6 @@ def text(svg, node, font_size): 'text-after-edge', 'after_edge', 'bottom', 'text-bottom'): y_align = -descent - # Set bounding box - node.text_bounding_box = EMPTY_BOUNDING_BOX - # Return early when there’s no text if not node.text: x = x[0] if x else svg.cursor_position[0]