[pens] Improve error message if pen.moveTo() is omitted. (#1757)

Improve error message if pen.moveTo() is omitted. See also robotools/fontParts#470
This commit is contained in:
Just van Rossum 2019-10-30 14:45:55 +01:00 committed by GitHub
parent 5790f7f9af
commit 07140c12bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -247,9 +247,11 @@ class SegmentToPointPen(AbstractPen):
self.contour.append((pt, "move"))
def lineTo(self, pt):
assert self.contour is not None, "contour missing required initial moveTo"
self.contour.append((pt, "line"))
def curveTo(self, *pts):
assert self.contour is not None, "contour missing required initial moveTo"
for pt in pts[:-1]:
self.contour.append((pt, None))
self.contour.append((pts[-1], "curve"))
@ -257,12 +259,15 @@ class SegmentToPointPen(AbstractPen):
def qCurveTo(self, *pts):
if pts[-1] is None:
self.contour = []
else:
assert self.contour is not None, "contour missing required initial moveTo"
for pt in pts[:-1]:
self.contour.append((pt, None))
if pts[-1] is not None:
self.contour.append((pts[-1], "qcurve"))
def closePath(self):
assert self.contour is not None, "contour missing required initial moveTo"
if len(self.contour) > 1 and self.contour[0][0] == self.contour[-1][0]:
self.contour[0] = self.contour[-1]
del self.contour[-1]
@ -276,6 +281,7 @@ class SegmentToPointPen(AbstractPen):
self.contour = None
def endPath(self):
assert self.contour is not None, "contour missing required initial moveTo"
self._flushContour()
self.contour = None