[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"
|
drawMethod = "draw"
|
||||||
transformPen = TransformPen
|
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:
|
def _addPoint(self, pt: Tuple[float, float], onCurve: int) -> None:
|
||||||
self.points.append(pt)
|
self.points.append(pt)
|
||||||
self.types.append(onCurve)
|
self.types.append(onCurve)
|
||||||
@ -205,6 +214,7 @@ class TTGlyphPen(_TTGlyphBasePen, LoggingPen):
|
|||||||
self._popPoint()
|
self._popPoint()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.outputImpliedClosingLine:
|
||||||
# if first and last point on this path are the same, remove last
|
# if first and last point on this path are the same, remove last
|
||||||
startPt = 0
|
startPt = 0
|
||||||
if self.endPts:
|
if self.endPts:
|
||||||
|
@ -294,6 +294,27 @@ class TTGlyphPenTest(TTGlyphPenTestBase):
|
|||||||
uni0302_uni0300.recalcBounds(glyphSet)
|
uni0302_uni0300.recalcBounds(glyphSet)
|
||||||
self.assertGlyphBoundsEqual(uni0302_uni0300, (-278, 745, 148, 1025))
|
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):
|
class TTGlyphPointPenTest(TTGlyphPenTestBase):
|
||||||
penClass = TTGlyphPointPen
|
penClass = TTGlyphPointPen
|
||||||
@ -574,7 +595,6 @@ class TTGlyphPointPenTest(TTGlyphPenTestBase):
|
|||||||
assert pen1.types == pen2.types == [1, 1, 0, 1]
|
assert pen1.types == pen2.types == [1, 1, 0, 1]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class _TestGlyph(object):
|
class _TestGlyph(object):
|
||||||
def __init__(self, glyph):
|
def __init__(self, glyph):
|
||||||
self.coordinates = glyph.coordinates
|
self.coordinates = glyph.coordinates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user