Fix collapsing of lineto into moveto (l into m) commands.

This commit is contained in:
Eduard Braun 2017-05-17 03:46:35 +02:00
parent f1827735a7
commit 17edba7551

View file

@ -2266,25 +2266,24 @@ def cleanPath(element, options):
prevData = []
newPath = []
for (cmd, data) in path:
# flush the previous command if it is not the same type as the current command
if prevCmd != '':
if cmd != prevCmd or cmd == 'm':
newPath.append((prevCmd, prevData))
prevCmd = ''
prevData = []
# if the previous and current commands are the same type,
# or the previous command is moveto and the current is lineto, collapse,
# but only if they are not move commands (since move can contain implicit lineto commands)
if (cmd == prevCmd or (cmd == 'l' and prevCmd == 'm')) and cmd != 'm':
prevData.extend(data)
# save last command and data
if prevCmd == '':
# initialize with current path cmd and data
prevCmd = cmd
prevData = data
else:
# collapse if
# - cmd is not moveto (explicit moveto commands are not drawn)
# - the previous and current commands are the same type,
# - the previous command is moveto and the current is lineto
# (subsequent moveto pairs are treated as implicit lineto commands)
if cmd != 'm' and (cmd == prevCmd or (cmd == 'l' and prevCmd == 'm')):
prevData.extend(data)
# else flush the previous command if it is not the same type as the current command
else:
newPath.append((prevCmd, prevData))
prevCmd = cmd
prevData = data
# flush last command and data
if prevCmd != '':
newPath.append((prevCmd, prevData))
path = newPath