Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## [FontTools-checkins] CVS: fonttools/Lib/fontTools/pens basePen.py,1.3,1.4

 [FontTools-checkins] CVS: fonttools/Lib/fontTools/pens basePen.py,1.3,1.4 From: Just van Rossum - 2003-08-28 19:30:52 ```Update of /cvsroot/fonttools/fonttools/Lib/fontTools/pens In directory sc8-pr-cvs1:/tmp/cvs-serv4225 Modified Files: basePen.py Log Message: - added support for quadratic contours that have NO on-curve 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 on-curve, all others are off-curve ! (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 TrueType-style curves, breaking up curves using ! implied points: between each two consequtive off-curve 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 on-curve, all others are off-curve ! points. ! This method implements TrueType-style curves, breaking up curves ! using 'implied points': between each two consequtive off-curve points, ! there is one implied point exactly in the middle between them. ! ! The last argument (normally the on-curve point) may be None. ! This is to support contours that have NO on-curve 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 6-tuple ! 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 on-curve points. BasePen supports + # this by allowing the final argument (the expected on-curve + # point) to be None. We simulate the feature by making the implied + # on-curve point between the last and the first off-curve points + # explicit. + x, y = points[-2] # last off-curve point + nx, ny = points[0] # first off-curve 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 on-curve point" scenario ! pen.qCurveTo((0, 0), (0, 100), (100, 100), (100, 0), None) pen.closePath() ```

 [FontTools-checkins] CVS: fonttools/Lib/fontTools/pens basePen.py,1.3,1.4 From: Just van Rossum - 2003-08-28 19:30:52 ```Update of /cvsroot/fonttools/fonttools/Lib/fontTools/pens In directory sc8-pr-cvs1:/tmp/cvs-serv4225 Modified Files: basePen.py Log Message: - added support for quadratic contours that have NO on-curve 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 on-curve, all others are off-curve ! (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 TrueType-style curves, breaking up curves using ! implied points: between each two consequtive off-curve 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 on-curve, all others are off-curve ! points. ! This method implements TrueType-style curves, breaking up curves ! using 'implied points': between each two consequtive off-curve points, ! there is one implied point exactly in the middle between them. ! ! The last argument (normally the on-curve point) may be None. ! This is to support contours that have NO on-curve 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 6-tuple ! 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 on-curve points. BasePen supports + # this by allowing the final argument (the expected on-curve + # point) to be None. We simulate the feature by making the implied + # on-curve point between the last and the first off-curve points + # explicit. + x, y = points[-2] # last off-curve point + nx, ny = points[0] # first off-curve 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 on-curve point" scenario ! pen.qCurveTo((0, 0), (0, 100), (100, 100), (100, 0), None) pen.closePath() ```