quartzPen.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from fontTools.pens.basePen import BasePen
  2. from Quartz.CoreGraphics import CGPathCreateMutable, CGPathMoveToPoint
  3. from Quartz.CoreGraphics import CGPathAddLineToPoint, CGPathAddCurveToPoint
  4. from Quartz.CoreGraphics import CGPathAddQuadCurveToPoint, CGPathCloseSubpath
  5. __all__ = ["QuartzPen"]
  6. class QuartzPen(BasePen):
  7. """A pen that creates a CGPath
  8. Parameters
  9. - path: an optional CGPath to add to
  10. - xform: an optional CGAffineTransform to apply to the path
  11. """
  12. def __init__(self, glyphSet, path=None, xform=None):
  13. BasePen.__init__(self, glyphSet)
  14. if path is None:
  15. path = CGPathCreateMutable()
  16. self.path = path
  17. self.xform = xform
  18. def _moveTo(self, pt):
  19. x, y = pt
  20. CGPathMoveToPoint(self.path, self.xform, x, y)
  21. def _lineTo(self, pt):
  22. x, y = pt
  23. CGPathAddLineToPoint(self.path, self.xform, x, y)
  24. def _curveToOne(self, p1, p2, p3):
  25. (x1, y1), (x2, y2), (x3, y3) = p1, p2, p3
  26. CGPathAddCurveToPoint(self.path, self.xform, x1, y1, x2, y2, x3, y3)
  27. def _qCurveToOne(self, p1, p2):
  28. (x1, y1), (x2, y2) = p1, p2
  29. CGPathAddQuadCurveToPoint(self.path, self.xform, x1, y1, x2, y2)
  30. def _closePath(self):
  31. CGPathCloseSubpath(self.path)