Skip to content

Commit 099e4ee

Browse files
TonyCranebehackl
andauthored
Fixed two issues of :class:~.SVGMobject (#2490)
* fix issue of nested svg * fix issue of the order of transforms * fix bug of node which is not an element * fix x y property in SVGMobject._handle_transforms * adapted control data Co-authored-by: Benjamin Hackl <[email protected]>
1 parent 29028fa commit 099e4ee

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

manim/mobject/svg/svg_mobject.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ def generate_points(self):
133133
any submobjects within self.mobjects.
134134
"""
135135
doc = minidom_parse(self.file_path)
136-
for svg in doc.getElementsByTagName("svg"):
137-
mobjects = self._get_mobjects_from(svg, self.generate_style())
136+
for node in doc.childNodes:
137+
if not isinstance(node, MinidomElement) or node.tagName != "svg":
138+
continue
139+
mobjects = self._get_mobjects_from(node, self.generate_style())
138140
if self.unpack_groups:
139141
self.add(*mobjects)
140142
else:
@@ -484,11 +486,13 @@ def _handle_transforms(self, element, mobject):
484486
The Mobject to transform.
485487
"""
486488

487-
if element.hasAttribute("x") and element.hasAttribute("y"):
488-
x = self._attribute_to_float(element.getAttribute("x"))
489-
# Flip y
490-
y = -self._attribute_to_float(element.getAttribute("y"))
491-
mobject.shift(x * RIGHT + y * UP)
489+
x, y = (
490+
self._attribute_to_float(element.getAttribute(key))
491+
if element.hasAttribute(key)
492+
else 0.0
493+
for key in ("x", "y")
494+
)
495+
mobject.shift(x * RIGHT + y * DOWN)
492496

493497
transform_attr_value = element.getAttribute("transform")
494498

@@ -502,7 +506,7 @@ def _handle_transforms(self, element, mobject):
502506
# [^)]* == anything but a closing parenthesis
503507
# '|'.join == OR-list of SVG transformations
504508
transform_regex = "|".join([x + r"[^)]*\)" for x in transform_names])
505-
transforms = re.findall(transform_regex, transform_attr_value)
509+
transforms = re.findall(transform_regex, transform_attr_value)[::-1]
506510

507511
number_regex = r"[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?"
508512

Binary file not shown.

0 commit comments

Comments
 (0)