Skip to content

Commit

Permalink
Ensure that bounding box is set to invisible but displayed text tags
Browse files Browse the repository at this point in the history
Related to #2030.
  • Loading branch information
liZe committed Jan 22, 2024
1 parent 4f109c0 commit 7b4bbab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 7 additions & 2 deletions weasyprint/svg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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]
Expand Down
5 changes: 1 addition & 4 deletions weasyprint/svg/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 7b4bbab

Please sign in to comment.