From: Just van Rossum <jvr@us...>  20030828 19:30:52

Update of /cvsroot/fonttools/fonttools/Lib/fontTools/pens In directory sc8prcvs1:/tmp/cvsserv4225 Modified Files: basePen.py Log Message:  added support for quadratic contours that have NO oncurve points.  more doco and comments. Index: basePen.py =================================================================== RCS file: /cvsroot/fonttools/fonttools/Lib/fontTools/pens/basePen.py,v retrieving revision 1.3 retrieving revision 1.4 diff C2 d r1.3 r1.4 *** basePen.py 24 Aug 2003 17:23:34 0000 1.3  basePen.py 28 Aug 2003 19:30:46 0000 1.4 *************** *** 38,42 **** def curveTo(self, *points): ! """Draw a curve with an *arbitrary* number of control points. Let n be the number of control points (which is the number of  38,47  def curveTo(self, *points): ! """Draw a cubic bezier with an arbitrary number of control points. ! ! The last point specified is oncurve, all others are offcurve ! (control) points. If the number of control points is > 2, the ! segment is split into multiple bezier segments. This works ! like this: Let n be the number of control points (which is the number of *************** *** 56,66 **** """Draw a whole string of quadratic curve segments. ! This implements TrueTypestyle curves, breaking up curves using ! implied points: between each two consequtive offcurve points, ! there is one 'implied' point exactly in the middle between them. ! 'points' is a sequence of at least two points. Just like with ! any segment drawing function, the first and the last point are ! treated as onCurve, the rest as offCurve. """ raise NotImplementedError  61,74  """Draw a whole string of quadratic curve segments. ! The last point specified is oncurve, all others are offcurve ! points. ! This method implements TrueTypestyle curves, breaking up curves ! using 'implied points': between each two consequtive offcurve points, ! there is one implied point exactly in the middle between them. ! ! The last argument (normally the oncurve point) may be None. ! This is to support contours that have NO oncurve points (a rarely ! seen feature of TrueType outlines). """ raise NotImplementedError *************** *** 71,75 **** def addComponent(self, glyphName, transformation): ! """Add a sub glyph.""" raise NotImplementedError  79,87  def addComponent(self, glyphName, transformation): ! """Add a sub glyph. The 'transformation' argument must be a 6tuple ! containing an affine transformation, or a Transform object from the ! fontTools.misc.transform module. More precisely: it should be a ! sequence containing 6 numbers. ! """ raise NotImplementedError *************** *** 187,190 ****  199,215  n = len(points)  1 # 'n' is the number of control points assert n >= 0 + if points[1] is None: + # Special case for TrueType quadratics: it is possible to + # define a contour with NO oncurve points. BasePen supports + # this by allowing the final argument (the expected oncurve + # point) to be None. We simulate the feature by making the implied + # oncurve point between the last and the first offcurve points + # explicit. + x, y = points[2] # last offcurve point + nx, ny = points[0] # first offcurve point + impliedStartPoint = (0.5 * (x + nx), 0.5 * (y + ny)) + self.__currentPoint = impliedStartPoint + self._moveTo(impliedStartPoint) + points = points[:1] + (impliedStartPoint,) if n > 0: # Split the string of points into discrete quadratic curve *************** *** 211,215 **** print "%s %s lineto" % (pt[0], pt[1]) def _curveToOne(self, bcp1, bcp2, pt): ! print "%s %s %s %s %s %s curveto" % (bcp1[0], bcp1[1], bcp2[0], bcp2[1], pt[0], pt[1]) def _closePath(self):  236,240  print "%s %s lineto" % (pt[0], pt[1]) def _curveToOne(self, bcp1, bcp2, pt): ! print "%s %s %s %s %s %s curveto" % (bcp1[0], bcp1[1], bcp2[0], bcp2[1], pt[0], pt[1]) def _closePath(self): *************** *** 225,230 **** pen = _TestPen(None) ! pen.moveTo((0, 0)) ! pen.lineTo((0, 100)) ! pen.curveTo((50, 75), (60, 50), (50, 25), (0, 0)) pen.closePath()  250,254  pen = _TestPen(None) ! # testing the "no oncurve point" scenario ! pen.qCurveTo((0, 0), (0, 100), (100, 100), (100, 0), None) pen.closePath() 