mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-09-11 20:47:56 +03:00
Override use tag children instead of drawing their references
This change fixes cases when use tags are not supposed to be really drawn, for example when used to clip paths.
This commit is contained in:
parent
0ff8692741
commit
d0ad5c1f28
@ -284,6 +284,13 @@ class Node:
|
||||
str(rotate.pop(0) if rotate else original_rotate[-1])
|
||||
for i in range(len(self.text)))
|
||||
|
||||
def override_iter(self, iterator):
|
||||
"""Override node’s children iterator."""
|
||||
# As special methods are bound to classes and not instances, we have to
|
||||
# create and assign a new type.
|
||||
self.__class__ = type(
|
||||
'Node', (Node,), {'__iter__': lambda _: iterator})
|
||||
|
||||
|
||||
class SVG:
|
||||
"""An SVG document."""
|
||||
@ -737,11 +744,7 @@ class SVG:
|
||||
if key not in element.attrib:
|
||||
element.attrib[key] = value
|
||||
if next(iter(element), None) is None:
|
||||
# Override element’s __iter__ with parent’s __iter__. As special
|
||||
# methods are bound to classes and not instances, we have to create
|
||||
# and assign a new type.
|
||||
element.__class__ = type(
|
||||
'Node', (Node,), {'__iter__': lambda self: parent.__iter__()})
|
||||
element.override_iter(parent.__iter__())
|
||||
|
||||
def calculate_bounding_box(self, node, font_size, stroke=True):
|
||||
"""Calculate the bounding box of a node."""
|
||||
|
@ -60,10 +60,8 @@ def use(svg, node, font_size):
|
||||
if key not in tree.attrib:
|
||||
tree.attrib[key] = value
|
||||
|
||||
svg.stream.push_state()
|
||||
node.override_iter(iter((tree,)))
|
||||
svg.stream.transform(e=x, f=y)
|
||||
svg.draw_node(tree, font_size)
|
||||
svg.stream.pop_state()
|
||||
|
||||
|
||||
def draw_gradient_or_pattern(svg, node, name, font_size, opacity, stroke):
|
||||
|
Loading…
Reference in New Issue
Block a user