1"""Pen multiplexing drawing to one or more pens.""" 2from __future__ import print_function, division, absolute_import 3from fontTools.misc.py23 import * 4from fontTools.pens.basePen import AbstractPen 5 6 7__all__ = ["TeePen"] 8 9 10class TeePen(AbstractPen): 11 """Pen multiplexing drawing to one or more pens. 12 13 Use either as TeePen(pen1, pen2, ...) or TeePen(iterableOfPens).""" 14 15 def __init__(self, *pens): 16 if len(pens) == 1: 17 pens = pens[0] 18 self.pens = pens 19 def moveTo(self, p0): 20 for pen in self.pens: 21 pen.moveTo(p0) 22 def lineTo(self, p1): 23 for pen in self.pens: 24 pen.lineTo(p1) 25 def qCurveTo(self, *points): 26 for pen in self.pens: 27 pen.qCurveTo(*points) 28 def curveTo(self, *points): 29 for pen in self.pens: 30 pen.curveTo(*points) 31 def closePath(self): 32 for pen in self.pens: 33 pen.closePath() 34 def endPath(self): 35 for pen in self.pens: 36 pen.endPath() 37 def addComponent(self, glyphName, transformation): 38 for pen in self.pens: 39 pen.addComponent(glyphName, transformation) 40 41 42if __name__ == "__main__": 43 from fontTools.pens.basePen import _TestPen 44 pen = TeePen(_TestPen(), _TestPen()) 45 pen.moveTo((0, 0)) 46 pen.lineTo((0, 100)) 47 pen.curveTo((50, 75), (60, 50), (50, 25)) 48 pen.closePath() 49