[ttGlyphPen] Add outputImpliedClosingLine argument
Fixes https://github.com/fonttools/fonttools/issues/2913
This commit is contained in:
parent
ddbbef2257
commit
78e10d8b42
@ -164,6 +164,15 @@ class TTGlyphPen(_TTGlyphBasePen, LoggingPen):
|
||||
drawMethod = "draw"
|
||||
transformPen = TransformPen
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
glyphSet: Optional[Dict[str, Any]] = None,
|
||||
handleOverflowingTransforms: bool = True,
|
||||
outputImpliedClosingLine: bool = False,
|
||||
) -> None:
|
||||
super().__init__(glyphSet, handleOverflowingTransforms)
|
||||
self.outputImpliedClosingLine = outputImpliedClosingLine
|
||||
|
||||
def _addPoint(self, pt: Tuple[float, float], onCurve: int) -> None:
|
||||
self.points.append(pt)
|
||||
self.types.append(onCurve)
|
||||
@ -205,6 +214,7 @@ class TTGlyphPen(_TTGlyphBasePen, LoggingPen):
|
||||
self._popPoint()
|
||||
return
|
||||
|
||||
if not self.outputImpliedClosingLine:
|
||||
# if first and last point on this path are the same, remove last
|
||||
startPt = 0
|
||||
if self.endPts:
|
||||
|
@ -294,6 +294,27 @@ class TTGlyphPenTest(TTGlyphPenTestBase):
|
||||
uni0302_uni0300.recalcBounds(glyphSet)
|
||||
self.assertGlyphBoundsEqual(uni0302_uni0300, (-278, 745, 148, 1025))
|
||||
|
||||
def test_outputImpliedClosingLine(self):
|
||||
glyphSet = {}
|
||||
|
||||
pen = TTGlyphPen(glyphSet)
|
||||
pen.moveTo((0, 0))
|
||||
pen.lineTo((10, 0))
|
||||
pen.lineTo((0, 10))
|
||||
pen.lineTo((0, 0))
|
||||
pen.closePath()
|
||||
glyph = pen.glyph()
|
||||
assert len(glyph.coordinates) == 3
|
||||
|
||||
pen = TTGlyphPen(glyphSet, outputImpliedClosingLine=True)
|
||||
pen.moveTo((0, 0))
|
||||
pen.lineTo((10, 0))
|
||||
pen.lineTo((0, 10))
|
||||
pen.lineTo((0, 0))
|
||||
pen.closePath()
|
||||
glyph = pen.glyph()
|
||||
assert len(glyph.coordinates) == 4
|
||||
|
||||
|
||||
class TTGlyphPointPenTest(TTGlyphPenTestBase):
|
||||
penClass = TTGlyphPointPen
|
||||
@ -574,7 +595,6 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
|
||||
assert pen1.types == pen2.types == [1, 1, 0, 1]
|
||||
|
||||
|
||||
|
||||
class _TestGlyph(object):
|
||||
def __init__(self, glyph):
|
||||
self.coordinates = glyph.coordinates
|
||||
|
Loading…
x
Reference in New Issue
Block a user