[TTGlyphPen] Move checks for closed contours
We probably don't want to raise errors in init, which allows a drawer to reset the pen state.
This commit is contained in:
parent
943d258bdb
commit
9f5c51897c
@ -21,7 +21,6 @@ class TTGlyphPen(BasePen):
|
|||||||
self.init()
|
self.init()
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
assert self._getCurrentPoint() is None, "Didn't close last contour. %s %s %s %s"
|
|
||||||
self.points = []
|
self.points = []
|
||||||
self.endPts = []
|
self.endPts = []
|
||||||
self.types = []
|
self.types = []
|
||||||
@ -31,12 +30,16 @@ class TTGlyphPen(BasePen):
|
|||||||
self.points.append([int(coord) for coord in pt])
|
self.points.append([int(coord) for coord in pt])
|
||||||
self.types.append(onCurve)
|
self.types.append(onCurve)
|
||||||
|
|
||||||
|
def _isClosed(self):
|
||||||
|
return (
|
||||||
|
(not self.points) or
|
||||||
|
(self.endPts and self.endPts[-1] == len(self.points) - 1))
|
||||||
|
|
||||||
def _lineTo(self, pt):
|
def _lineTo(self, pt):
|
||||||
self._addPoint(pt, 1)
|
self._addPoint(pt, 1)
|
||||||
|
|
||||||
def _moveTo(self, pt):
|
def _moveTo(self, pt):
|
||||||
assert (not self.points) or (self.endPts[-1] == len(self.points) - 1), (
|
assert self._isClosed(), '"move"-type point must begin a new contour.'
|
||||||
'"move"-type point must begin a new contour.')
|
|
||||||
self._addPoint(pt, 1)
|
self._addPoint(pt, 1)
|
||||||
|
|
||||||
def _qCurveToOne(self, pt1, pt2):
|
def _qCurveToOne(self, pt1, pt2):
|
||||||
@ -72,6 +75,7 @@ class TTGlyphPen(BasePen):
|
|||||||
|
|
||||||
def glyph(self):
|
def glyph(self):
|
||||||
glyph = Glyph()
|
glyph = Glyph()
|
||||||
|
assert self._isClosed(), "Didn't close last contour."
|
||||||
|
|
||||||
components = []
|
components = []
|
||||||
for glyphName, transformation in self.components:
|
for glyphName, transformation in self.components:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user