fonttools/Lib/fontTools/pens/quartzPen.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

44 lines
1.3 KiB
Python
Raw Normal View History

2020-11-19 11:54:56 +01:00
from fontTools.pens.basePen import BasePen
from Quartz.CoreGraphics import CGPathCreateMutable, CGPathMoveToPoint
from Quartz.CoreGraphics import CGPathAddLineToPoint, CGPathAddCurveToPoint
from Quartz.CoreGraphics import CGPathAddQuadCurveToPoint, CGPathCloseSubpath
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
__all__ = ["QuartzPen"]
class QuartzPen(BasePen):
"""A pen that creates a CGPath
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
Parameters
- path: an optional CGPath to add to
- xform: an optional CGAffineTransform to apply to the path
2022-12-13 11:26:36 +00:00
"""
2020-11-19 11:54:56 +01:00
def __init__(self, glyphSet, path=None, xform=None):
BasePen.__init__(self, glyphSet)
if path is None:
path = CGPathCreateMutable()
self.path = path
self.xform = xform
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
def _moveTo(self, pt):
x, y = pt
CGPathMoveToPoint(self.path, self.xform, x, y)
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
def _lineTo(self, pt):
x, y = pt
CGPathAddLineToPoint(self.path, self.xform, x, y)
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
def _curveToOne(self, p1, p2, p3):
(x1, y1), (x2, y2), (x3, y3) = p1, p2, p3
CGPathAddCurveToPoint(self.path, self.xform, x1, y1, x2, y2, x3, y3)
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
def _qCurveToOne(self, p1, p2):
(x1, y1), (x2, y2) = p1, p2
CGPathAddQuadCurveToPoint(self.path, self.xform, x1, y1, x2, y2)
2022-12-13 11:26:36 +00:00
2020-11-19 11:54:56 +01:00
def _closePath(self):
CGPathCloseSubpath(self.path)