Skip to content

Commit

Permalink
Fixed two issues of :class:~.SVGMobject (#2490)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
TonyCrane and behackl authored Jan 25, 2022
1 parent 29028fa commit 099e4ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions manim/mobject/svg/svg_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ def generate_points(self):
any submobjects within self.mobjects.
"""
doc = minidom_parse(self.file_path)
for svg in doc.getElementsByTagName("svg"):
mobjects = self._get_mobjects_from(svg, self.generate_style())
for node in doc.childNodes:
if not isinstance(node, MinidomElement) or node.tagName != "svg":
continue
mobjects = self._get_mobjects_from(node, self.generate_style())
if self.unpack_groups:
self.add(*mobjects)
else:
Expand Down Expand Up @@ -484,11 +486,13 @@ def _handle_transforms(self, element, mobject):
The Mobject to transform.
"""

if element.hasAttribute("x") and element.hasAttribute("y"):
x = self._attribute_to_float(element.getAttribute("x"))
# Flip y
y = -self._attribute_to_float(element.getAttribute("y"))
mobject.shift(x * RIGHT + y * UP)
x, y = (
self._attribute_to_float(element.getAttribute(key))
if element.hasAttribute(key)
else 0.0
for key in ("x", "y")
)
mobject.shift(x * RIGHT + y * DOWN)

transform_attr_value = element.getAttribute("transform")

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

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

Expand Down
Binary file not shown.

0 comments on commit 099e4ee

Please sign in to comment.