コード例 #1
0
    def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs):
        """Add a point to the current sub path."""
        if segmentType in ['curve', 'qcurve']:
            # it's an offcurve, let's buffer them until we get another oncurve
            # and we know what to do with them
            self._offCurveBuffer.append((pt, segmentType, smooth, name, kwargs))
            return

        elif segmentType == "move":
            # start of an open contour
            self.otherPointPen.addPoint(pt, segmentType, smooth, name)  # how to add kwargs?
            self._lastPt = pt
            self._offCurveBuffer = []

        elif segmentType == "line":
            if self._lastPt is None:
                self.otherPointPen.addPoint(pt, segmentType, smooth, name)  # how to add kwargs?
                self._lastPt = pt
            elif distance(pt, self._lastPt) >= self.threshold:
                # we're oncurve and far enough from the last oncurve
                if self._offCurveBuffer:
                    # empty any buffered offcurves
                    for buf_pt, buf_segmentType, buf_smooth, buf_name, buf_kwargs in self._offCurveBuffer:
                        self.otherPointPen.addPoint(buf_pt, buf_segmentType, buf_smooth, buf_name)  # how to add kwargs?
                    self._offCurveBuffer = []
                # finally add the oncurve.
                self.otherPointPen.addPoint(pt, segmentType, smooth, name)  # how to add kwargs?
                self._lastPt = pt
            else:
                # we're too short, so we're not going to make it.
                # we need to clear out the offcurve buffer.
                self._offCurveBuffer = []
コード例 #2
0
ファイル: flattenPen.py プロジェクト: moyogo/fontpens
 def _lineTo(self, pt):
     if self.filterDoubles:
         if pt == self.currentPt:
             return
     if not self.segmentLines:
         self.otherPen.lineTo(pt)
         self.currentPt = pt
         return
     d = distance(self.currentPt, pt)
     maxSteps = int(round(d / self.approximateSegmentLength))
     if maxSteps < 1:
         self.otherPen.lineTo(pt)
         self.currentPt = pt
         return
     step = 1.0 / maxSteps
     factors = range(0, maxSteps + 1)
     for i in factors[1:]:
         self.otherPen.lineTo(interpolatePoint(self.currentPt, pt, i * step))
     self.currentPt = pt
コード例 #3
0
 def _lineTo(self, pt):
     if self.filterDoubles:
         if pt == self.currentPt:
             return
     if not self.segmentLines:
         self.otherPen.lineTo(pt)
         self.currentPt = pt
         return
     d = distance(self.currentPt, pt)
     maxSteps = int(round(d / self.approximateSegmentLength))
     if maxSteps < 1:
         self.otherPen.lineTo(pt)
         self.currentPt = pt
         return
     step = 1.0 / maxSteps
     factors = range(0, maxSteps + 1)
     for i in factors[1:]:
         self.otherPen.lineTo(interpolatePoint(self.currentPt, pt,
                                               i * step))
     self.currentPt = pt
コード例 #4
0
 def qCurveTo(self, *points):
     if self.threshold <= distance(points[-1], self._lastPt):
         self.otherPen.qCurveTo(*points)
         self._lastPt = points[-1]
コード例 #5
0
 def curveTo(self, pt1, pt2, pt3):
     if self.threshold <= distance(pt3, self._lastPt):
         self.otherPen.curveTo(pt1, pt2, pt3)
         self._lastPt = pt3
コード例 #6
0
 def lineTo(self, pt, smooth=False):
     if self.threshold <= distance(pt, self._lastPt):
         self.otherPen.lineTo(pt)
         self._lastPt = pt