TTGlyphPen: do not error with empty contours, simply ignore them

Fixes https://github.com/googlefonts/fontmake/issues/1001
This commit is contained in:
Cosimo Lupo 2023-05-31 11:58:14 +01:00
parent 0bf84f9c7b
commit 3bbc19abb1
No known key found for this signature in database
GPG Key ID: DF65A8A5A119C9A8
2 changed files with 12 additions and 7 deletions

View File

@ -326,7 +326,9 @@ class TTGlyphPointPen(_TTGlyphBasePen, LogMixin, AbstractPointPen):
if self._isClosed():
raise PenError("Contour is already closed.")
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
self.endPts.append(len(self.points) - 1)

View File

@ -353,12 +353,6 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
with pytest.raises(PenError):
pen.glyph()
def test_glyph_errorOnEmptyContour(self):
pen = TTGlyphPointPen(None)
pen.beginPath()
with pytest.raises(PenError):
pen.endPath()
def test_glyph_decomposes(self):
componentName = "a"
glyphSet = {}
@ -595,6 +589,15 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
assert pen1.points == pen2.points == [(0, 0), (10, 10), (20, 20), (20, 0)]
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:
def test_cubic_simple(self):