Skip to content

Commit

Permalink
Set "display" and "visible" as node properties
Browse files Browse the repository at this point in the history
  • Loading branch information
liZe committed Jan 22, 2024
1 parent bf58cb3 commit 4c0bd62
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions weasyprint/svg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def tail(self):
"""Text after the XML node."""
return self._etree_node.tail

@property
def display(self):
"""Whether node should be displayed."""
return self.get('display') != 'none'

@property
def visible(self):
"""Whether node is visible."""
return self.display and self.get('visibility') != 'hidden'

def __iter__(self):
"""Yield node children, handling cascade."""
for wrapper in self._wrapper:
Expand Down Expand Up @@ -432,10 +442,6 @@ def draw_node(self, node, font_size, fill_stroke=True):
if new_ctm.determinant:
self.stream.transform(*(old_ctm @ new_ctm.invert).values)

# Manage display and visibility
display = node.get('display') != 'none'
visible = display and (node.get('visibility') != 'hidden')

# Handle text anchor
text_anchor = node.get('text-anchor')
if node.tag == 'text' and text_anchor in ('middle', 'end'):
Expand All @@ -444,12 +450,12 @@ def draw_node(self, node, font_size, fill_stroke=True):
self.stream = group

# Draw node
if visible and node.tag in TAGS:
if node.visible and node.tag in TAGS:
with suppress(PointError):
TAGS[node.tag](self, node, font_size)

# Draw node children
if display and node.tag not in DEF_TYPES:
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'):
Expand Down

0 comments on commit 4c0bd62

Please sign in to comment.