Merge pull request #3145 from fonttools/ttglyphpen-ignore-empty
TTGlyphPen: do not error with empty contours, simply ignore them
This commit is contained in:
commit
02a063685f
@ -326,7 +326,9 @@ class TTGlyphPointPen(_TTGlyphBasePen, LogMixin, AbstractPointPen):
|
|||||||
if self._isClosed():
|
if self._isClosed():
|
||||||
raise PenError("Contour is already closed.")
|
raise PenError("Contour is already closed.")
|
||||||
if self._currentContourStartIndex == len(self.points):
|
if self._currentContourStartIndex == len(self.points):
|
||||||
raise PenError("Tried to end an empty contour.")
|
# ignore empty contours
|
||||||
|
self._currentContourStartIndex = None
|
||||||
|
return
|
||||||
|
|
||||||
contourStart = self.endPts[-1] + 1 if self.endPts else 0
|
contourStart = self.endPts[-1] + 1 if self.endPts else 0
|
||||||
self.endPts.append(len(self.points) - 1)
|
self.endPts.append(len(self.points) - 1)
|
||||||
|
@ -353,12 +353,6 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
|
|||||||
with pytest.raises(PenError):
|
with pytest.raises(PenError):
|
||||||
pen.glyph()
|
pen.glyph()
|
||||||
|
|
||||||
def test_glyph_errorOnEmptyContour(self):
|
|
||||||
pen = TTGlyphPointPen(None)
|
|
||||||
pen.beginPath()
|
|
||||||
with pytest.raises(PenError):
|
|
||||||
pen.endPath()
|
|
||||||
|
|
||||||
def test_glyph_decomposes(self):
|
def test_glyph_decomposes(self):
|
||||||
componentName = "a"
|
componentName = "a"
|
||||||
glyphSet = {}
|
glyphSet = {}
|
||||||
@ -595,6 +589,15 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
|
|||||||
assert pen1.points == pen2.points == [(0, 0), (10, 10), (20, 20), (20, 0)]
|
assert pen1.points == pen2.points == [(0, 0), (10, 10), (20, 20), (20, 0)]
|
||||||
assert pen1.types == pen2.types == [1, 1, 0, 1]
|
assert pen1.types == pen2.types == [1, 1, 0, 1]
|
||||||
|
|
||||||
|
def test_skip_empty_contours(self):
|
||||||
|
pen = TTGlyphPointPen(None)
|
||||||
|
pen.beginPath()
|
||||||
|
pen.endPath()
|
||||||
|
pen.beginPath()
|
||||||
|
pen.endPath()
|
||||||
|
glyph = pen.glyph()
|
||||||
|
assert glyph.numberOfContours == 0
|
||||||
|
|
||||||
|
|
||||||
class CubicGlyfTest:
|
class CubicGlyfTest:
|
||||||
def test_cubic_simple(self):
|
def test_cubic_simple(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user