teePen.py 1.3 KB

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