Skip to content

Commit

Permalink
Fixed SVG parsing error with consecutive C or M coordinates.
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammingIncluded committed Feb 20, 2019
1 parent 9e96c4d commit 7c76b7a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions manimlib/mobject/svg/svg_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,19 @@ def handle_command(self, command, coord_string):
if len(new_points) <= 1:
return

# Huh? When does this come up?
# Draw relative line-to values.
points = self.points
new_points = new_points[1:]
command = "L"

# Treat everything as relative line-to until empty
for p in new_points:
# Treat as relative
p[0] += self.points[-1, 0]
p[1] += self.points[-1, 1]
self.add_line_to(p)
return

elif command in ["L", "H", "V"]: # lineto
if command == "H":
new_points[0, 1] = points[-1, 1]
Expand Down Expand Up @@ -382,13 +391,17 @@ def handle_command(self, command, coord_string):
elif command == "Z": # closepath
return

# Add first three points
self.add_cubic_bezier_curve_to(*new_points[0:3])

# Handle situations where there's multiple relative control points
if isLower and len(new_points) > 3:
if len(new_points) > 3:
# Add subsequent offset points relatively.
for i in range(3, len(new_points), 3):
new_points[i:i + 3] -= points[-1]
new_points[i:i + 3] += new_points[i - 1]

self.add_cubic_bezier_curve_to(*new_points)
if isLower:
new_points[i:i + 3] -= points[-1]
new_points[i:i + 3] += new_points[i - 1]
self.add_cubic_bezier_curve_to(*new_points[i:i+3])

def string_to_points(self, coord_string):
numbers = string_to_numbers(coord_string)
Expand Down

0 comments on commit 7c76b7a

Please sign in to comment.