[pens] remove ReverseContourPointPen copy; import it from ufoLib (v2.1.0)

... or from robofab (I haven't tested the latter though)
This commit is contained in:
Cosimo Lupo 2017-05-24 19:05:14 +01:00
parent 27842267cd
commit 153404077d
No known key found for this signature in database
GPG Key ID: B61AAAD0B53A6419
2 changed files with 6 additions and 88 deletions

View File

@ -5,9 +5,11 @@ from fontTools.pens.basePen import AbstractPen, decomposeSuperBezierSegment
try:
from ufoLib.pointPen import AbstractPointPen, BasePointToSegmentPen
from ufoLib.pointPen import PointToSegmentPen, SegmentToPointPen
from ufoLib.pointPen import ReverseContourPointPen
except ImportError:
from robofab.pens.pointPen import AbstractPointPen, BasePointToSegmentPen
from robofab.pens.adapterPens import PointToSegmentPen, SegmentToPointPen
from robofab.pens.reverseContourPointPen import ReverseContourPointPen
class Cu2QuPen(AbstractPen):
@ -227,90 +229,6 @@ class Cu2QuPointPen(BasePointToSegmentPen):
self.pen.addComponent(baseGlyphName, transformation)
class ReverseContourPointPen(AbstractPointPen):
"""This is a PointPen that passes outline data to another PointPen, but
reversing the winding direction of all contours. Components are simply
passed through unchanged.
Closed contours are reversed in such a way that the first point remains
the first point.
(Copied from robofab.pens.reverseContourPointPen)
TODO(anthrotype) Move this to future "penBox" package?
"""
def __init__(self, outputPointPen):
self.pen = outputPointPen
# a place to store the points for the current sub path
self.currentContour = None
def _flushContour(self):
pen = self.pen
contour = self.currentContour
if not contour:
pen.beginPath()
pen.endPath()
return
closed = contour[0][1] != "move"
if not closed:
lastSegmentType = "move"
else:
# Remove the first point and insert it at the end. When
# the list of points gets reversed, this point will then
# again be at the start. In other words, the following
# will hold:
# for N in range(len(originalContour)):
# originalContour[N] == reversedContour[-N]
contour.append(contour.pop(0))
# Find the first on-curve point.
firstOnCurve = None
for i in range(len(contour)):
if contour[i][1] is not None:
firstOnCurve = i
break
if firstOnCurve is None:
# There are no on-curve points, be basically have to
# do nothing but contour.reverse().
lastSegmentType = None
else:
lastSegmentType = contour[firstOnCurve][1]
contour.reverse()
if not closed:
# Open paths must start with a move, so we simply dump
# all off-curve points leading up to the first on-curve.
while contour[0][1] is None:
contour.pop(0)
pen.beginPath()
for pt, nextSegmentType, smooth, name in contour:
if nextSegmentType is not None:
segmentType = lastSegmentType
lastSegmentType = nextSegmentType
else:
segmentType = None
pen.addPoint(pt, segmentType=segmentType, smooth=smooth, name=name)
pen.endPath()
def beginPath(self):
assert self.currentContour is None
self.currentContour = []
def endPath(self):
assert self.currentContour is not None
self._flushContour()
self.currentContour = None
def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
self.currentContour.append((pt, segmentType, smooth, name))
def addComponent(self, glyphName, transform):
assert self.currentContour is None
self.pen.addComponent(glyphName, transform)
class ReverseContourPen(SegmentToPointPen):
""" Same as 'ReverseContourPointPen' but using the SegmentPen protocol. """

View File

@ -17,8 +17,8 @@ class BaseDummyPen(object):
"""Return the pen commands as a string of python code."""
return _repr_pen_commands(self.commands)
def addComponent(self, glyphName, transformation):
self.commands.append(('addComponent', (glyphName, transformation), {}))
def addComponent(self, glyphName, transformation, **kwargs):
self.commands.append(('addComponent', (glyphName, transformation), kwargs))
class DummyPen(BaseDummyPen):
@ -46,8 +46,8 @@ class DummyPen(BaseDummyPen):
class DummyPointPen(BaseDummyPen):
"""A PointPen that records the commands it's called with."""
def beginPath(self):
self.commands.append(('beginPath', tuple(), {}))
def beginPath(self, **kwargs):
self.commands.append(('beginPath', tuple(), kwargs))
def endPath(self):
self.commands.append(('endPath', tuple(), {}))