Skip to content

Commit

Permalink
Merge pull request #684 from mdboom/initial-moveto
Browse files Browse the repository at this point in the history
Fix 'Path lacks initial MOVETO'
  • Loading branch information
mdboom committed Jan 23, 2012
2 parents 7f3bac3 + d41a7c0 commit ae4a308
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def convert_path(ctx, path, transform):
for points, code in path.iter_segments(transform):
if code == Path.MOVETO:
ctx.move_to(*points)
elif code == Path.CLOSEPOLY:
ctx.close_path()
elif code == Path.LINETO:
ctx.line_to(*points)
elif code == Path.CURVE3:
Expand All @@ -135,8 +137,6 @@ def convert_path(ctx, path, transform):
points[2], points[3])
elif code == Path.CURVE4:
ctx.curve_to(*points)
elif code == Path.CLOSEPOLY:
ctx.close_path()


def draw_path(self, gc, path, transform, rgbFace=None):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_emf.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ def convert_path(self, tpath):
for points, code in tpath.iter_segments():
if code == Path.MOVETO:
self.emf.MoveTo(*points)
elif code == Path.CLOSEPOLY:
self.emf.CloseFigure()
elif code == Path.LINETO:
self.emf.LineTo(*points)
elif code == Path.CURVE3:
points = quad2cubic(*(list(last_points[-2:]) + list(points)))
self.emf.PolyBezierTo(zip(points[2::2], points[3::2]))
elif code == Path.CURVE4:
self.emf.PolyBezierTo(zip(points[::2], points[1::2]))
elif code == Path.CLOSEPOLY:
self.emf.CloseFigure()
last_points = points
self.emf.EndPath()

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,8 @@ def pathOperations(path, transform, clip=None, simplify=None):
# This is allowed anywhere in the path
cmds.extend(points)
cmds.append(Op.moveto)
elif code == Path.CLOSEPOLY:
cmds.append(Op.closepath)
elif last_points is None:
# The other operations require a previous point
raise ValueError, 'Path lacks initial MOVETO'
Expand All @@ -1240,8 +1242,6 @@ def pathOperations(path, transform, clip=None, simplify=None):
elif code == Path.CURVE4:
cmds.extend(points)
cmds.append(Op.curveto)
elif code == Path.CLOSEPOLY:
cmds.append(Op.closepath)
last_points = points
return cmds

Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ def _convert_path(self, path, transform, clip=False, simplify=None):
simplify=simplify):
if code == Path.MOVETO:
ps.append("%g %g m" % tuple(points))
elif code == Path.CLOSEPOLY:
ps.append("cl")
elif last_points is None:
# The other operations require a previous point
raise ValueError('Path lacks initial MOVETO')
elif code == Path.LINETO:
ps.append("%g %g l" % tuple(points))
elif code == Path.CURVE3:
Expand All @@ -532,8 +537,6 @@ def _convert_path(self, path, transform, clip=False, simplify=None):
tuple(points[2:]))
elif code == Path.CURVE4:
ps.append("%g %g %g %g %g %g c" % tuple(points))
elif code == Path.CLOSEPOLY:
ps.append("cl")
last_points = points

ps = "\n".join(ps)
Expand Down

0 comments on commit ae4a308

Please sign in to comment.