def __init__(self, outPointPen, transformation): """The 'outPointPen' argument is another point pen object. It will receive the transformed coordinates. The 'transformation' argument can either be a six-tuple, or a fontTools.misc.transform.Transform object. """ super().__init__(outPointPen) if not hasattr(transformation, "transformPoint"): from fontTools.misc.transform import Transform transformation = Transform(*transformation) self._transformation = transformation self._transformPoint = transformation.transformPoint def addPoint(self, pt, segmentType=None, smooth=False, name=None, **kwargs): self._outPen.addPoint( self._transformPoint(pt), segmentType, smooth, name, **kwargs ) def addComponent(self, baseGlyphName, transformation, **kwargs): transformation = self._transformation.transform(transformation) self._outPen.addComponent(baseGlyphName, transformation, **kwargs) if __name__ == "__main__": from fontTools.pens.basePen import _TestPen pen = TransformPen(_TestPen(None), (2, 0, 0.5, 2, -10, 0)) pen.moveTo((0, 0)) pen.lineTo((0, 100)) pen.curveTo((50, 75), (60, 50), (50, 25), (0, 0)) pen.closePath()
def qCurveTo(self, *points): if points[-1] is None: points = self._transformPoints(points[:-1]) + [None] else: points = self._transformPoints(points) self._outPen.qCurveTo(*points) def _transformPoints(self, points): new = [] transformPoint = self._transformPoint for pt in points: new.append(transformPoint(pt)) return new def closePath(self): self._outPen.closePath() def addComponent(self, glyphName, transformation): transformation = self._transformation.transform(transformation) self._outPen.addComponent(glyphName, transformation) if __name__ == "__main__": from fontTools.pens.basePen import _TestPen pen = TransformPen(_TestPen(None), (2, 0, 0.5, 2, -10, 0)) pen.moveTo((0, 0)) pen.lineTo((0, 100)) pen.curveTo((50, 75), (60, 50), (50, 25), (0, 0)) pen.closePath()
def moveTo(self, p0): for pen in self.pens: pen.moveTo(p0) def lineTo(self, p1): for pen in self.pens: pen.lineTo(p1) def qCurveTo(self, *points): for pen in self.pens: pen.qCurveTo(*points) def curveTo(self, *points): for pen in self.pens: pen.curveTo(*points) def closePath(self): for pen in self.pens: pen.closePath() def endPath(self): for pen in self.pens: pen.endPath() def addComponent(self, glyphName, transformation): for pen in self.pens: pen.addComponent(glyphName, transformation) if __name__ == "__main__": from fontTools.pens.basePen import _TestPen pen = TeePen(_TestPen(), _TestPen()) pen.moveTo((0, 0)) pen.lineTo((0, 100)) pen.curveTo((50, 75), (60, 50), (50, 25)) pen.closePath()
pen.lineTo(p1) def qCurveTo(self, *points): for pen in self.pens: pen.qCurveTo(*points) def curveTo(self, *points): for pen in self.pens: pen.curveTo(*points) def closePath(self): for pen in self.pens: pen.closePath() def endPath(self): for pen in self.pens: pen.endPath() def addComponent(self, glyphName, transformation): for pen in self.pens: pen.addComponent(glyphName, transformation) if __name__ == "__main__": from fontTools.pens.basePen import _TestPen pen = TeePen(_TestPen(), _TestPen()) pen.moveTo((0, 0)) pen.lineTo((0, 100)) pen.curveTo((50, 75), (60, 50), (50, 25)) pen.closePath()