pointPen.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. """
  2. =========
  3. PointPens
  4. =========
  5. Where **SegmentPens** have an intuitive approach to drawing
  6. (if you're familiar with postscript anyway), the **PointPen**
  7. is geared towards accessing all the data in the contours of
  8. the glyph. A PointPen has a very simple interface, it just
  9. steps through all the points in a call from glyph.drawPoints().
  10. This allows the caller to provide more data for each point.
  11. For instance, whether or not a point is smooth, and its name.
  12. """
  13. from __future__ import annotations
  14. import math
  15. from typing import Any, Dict, List, Optional, Tuple
  16. from fontTools.misc.enumTools import StrEnum
  17. from fontTools.misc.loggingTools import LogMixin
  18. from fontTools.misc.transform import DecomposedTransform, Identity
  19. from fontTools.pens.basePen import AbstractPen, MissingComponentError, PenError
  20. __all__ = [
  21. "AbstractPointPen",
  22. "BasePointToSegmentPen",
  23. "PointToSegmentPen",
  24. "SegmentToPointPen",
  25. "GuessSmoothPointPen",
  26. "ReverseContourPointPen",
  27. "ReverseFlipped",
  28. ]
  29. # Some type aliases to make it easier below
  30. Point = Tuple[float, float]
  31. PointName = Optional[str]
  32. # [(pt, smooth, name, kwargs)]
  33. SegmentPointList = List[Tuple[Optional[Point], bool, PointName, Any]]
  34. SegmentType = Optional[str]
  35. SegmentList = List[Tuple[SegmentType, SegmentPointList]]
  36. class ReverseFlipped(StrEnum):
  37. """How to handle flipped components during decomposition.
  38. NO: Don't reverse flipped components
  39. KEEP_START: Reverse flipped components, keeping original starting point
  40. ON_CURVE_FIRST: Reverse flipped components, ensuring first point is on-curve
  41. """
  42. NO = "no"
  43. KEEP_START = "keep_start"
  44. ON_CURVE_FIRST = "on_curve_first"
  45. class AbstractPointPen:
  46. """Baseclass for all PointPens."""
  47. def beginPath(self, identifier: Optional[str] = None, **kwargs: Any) -> None:
  48. """Start a new sub path."""
  49. raise NotImplementedError
  50. def endPath(self) -> None:
  51. """End the current sub path."""
  52. raise NotImplementedError
  53. def addPoint(
  54. self,
  55. pt: Tuple[float, float],
  56. segmentType: Optional[str] = None,
  57. smooth: bool = False,
  58. name: Optional[str] = None,
  59. identifier: Optional[str] = None,
  60. **kwargs: Any,
  61. ) -> None:
  62. """Add a point to the current sub path."""
  63. raise NotImplementedError
  64. def addComponent(
  65. self,
  66. baseGlyphName: str,
  67. transformation: Tuple[float, float, float, float, float, float],
  68. identifier: Optional[str] = None,
  69. **kwargs: Any,
  70. ) -> None:
  71. """Add a sub glyph."""
  72. raise NotImplementedError
  73. def addVarComponent(
  74. self,
  75. glyphName: str,
  76. transformation: DecomposedTransform,
  77. location: Dict[str, float],
  78. identifier: Optional[str] = None,
  79. **kwargs: Any,
  80. ) -> None:
  81. """Add a VarComponent sub glyph. The 'transformation' argument
  82. must be a DecomposedTransform from the fontTools.misc.transform module,
  83. and the 'location' argument must be a dictionary mapping axis tags
  84. to their locations.
  85. """
  86. # ttGlyphSet decomposes for us
  87. raise AttributeError
  88. class BasePointToSegmentPen(AbstractPointPen):
  89. """
  90. Base class for retrieving the outline in a segment-oriented
  91. way. The PointPen protocol is simple yet also a little tricky,
  92. so when you need an outline presented as segments but you have
  93. as points, do use this base implementation as it properly takes
  94. care of all the edge cases.
  95. """
  96. def __init__(self) -> None:
  97. self.currentPath = None
  98. def beginPath(self, identifier=None, **kwargs):
  99. if self.currentPath is not None:
  100. raise PenError("Path already begun.")
  101. self.currentPath = []
  102. def _flushContour(self, segments: SegmentList) -> None:
  103. """Override this method.
  104. It will be called for each non-empty sub path with a list
  105. of segments: the 'segments' argument.
  106. The segments list contains tuples of length 2:
  107. (segmentType, points)
  108. segmentType is one of "move", "line", "curve" or "qcurve".
  109. "move" may only occur as the first segment, and it signifies
  110. an OPEN path. A CLOSED path does NOT start with a "move", in
  111. fact it will not contain a "move" at ALL.
  112. The 'points' field in the 2-tuple is a list of point info
  113. tuples. The list has 1 or more items, a point tuple has
  114. four items:
  115. (point, smooth, name, kwargs)
  116. 'point' is an (x, y) coordinate pair.
  117. For a closed path, the initial moveTo point is defined as
  118. the last point of the last segment.
  119. The 'points' list of "move" and "line" segments always contains
  120. exactly one point tuple.
  121. """
  122. raise NotImplementedError
  123. def endPath(self) -> None:
  124. if self.currentPath is None:
  125. raise PenError("Path not begun.")
  126. points = self.currentPath
  127. self.currentPath = None
  128. if not points:
  129. return
  130. if len(points) == 1:
  131. # Not much more we can do than output a single move segment.
  132. pt, segmentType, smooth, name, kwargs = points[0]
  133. segments: SegmentList = [("move", [(pt, smooth, name, kwargs)])]
  134. self._flushContour(segments)
  135. return
  136. segments = []
  137. if points[0][1] == "move":
  138. # It's an open contour, insert a "move" segment for the first
  139. # point and remove that first point from the point list.
  140. pt, segmentType, smooth, name, kwargs = points[0]
  141. segments.append(("move", [(pt, smooth, name, kwargs)]))
  142. points.pop(0)
  143. else:
  144. # It's a closed contour. Locate the first on-curve point, and
  145. # rotate the point list so that it _ends_ with an on-curve
  146. # point.
  147. firstOnCurve = None
  148. for i in range(len(points)):
  149. segmentType = points[i][1]
  150. if segmentType is not None:
  151. firstOnCurve = i
  152. break
  153. if firstOnCurve is None:
  154. # Special case for quadratics: a contour with no on-curve
  155. # points. Add a "None" point. (See also the Pen protocol's
  156. # qCurveTo() method and fontTools.pens.basePen.py.)
  157. points.append((None, "qcurve", None, None, None))
  158. else:
  159. points = points[firstOnCurve + 1 :] + points[: firstOnCurve + 1]
  160. currentSegment: SegmentPointList = []
  161. for pt, segmentType, smooth, name, kwargs in points:
  162. currentSegment.append((pt, smooth, name, kwargs))
  163. if segmentType is None:
  164. continue
  165. segments.append((segmentType, currentSegment))
  166. currentSegment = []
  167. self._flushContour(segments)
  168. def addPoint(
  169. self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
  170. ):
  171. if self.currentPath is None:
  172. raise PenError("Path not begun")
  173. self.currentPath.append((pt, segmentType, smooth, name, kwargs))
  174. class PointToSegmentPen(BasePointToSegmentPen):
  175. """
  176. Adapter class that converts the PointPen protocol to the
  177. (Segment)Pen protocol.
  178. NOTE: The segment pen does not support and will drop point names, identifiers
  179. and kwargs.
  180. """
  181. def __init__(self, segmentPen, outputImpliedClosingLine: bool = False) -> None:
  182. BasePointToSegmentPen.__init__(self)
  183. self.pen = segmentPen
  184. self.outputImpliedClosingLine = outputImpliedClosingLine
  185. def _flushContour(self, segments):
  186. if not segments:
  187. raise PenError("Must have at least one segment.")
  188. pen = self.pen
  189. if segments[0][0] == "move":
  190. # It's an open path.
  191. closed = False
  192. points = segments[0][1]
  193. if len(points) != 1:
  194. raise PenError(f"Illegal move segment point count: {len(points)}")
  195. movePt, _, _, _ = points[0]
  196. del segments[0]
  197. else:
  198. # It's a closed path, do a moveTo to the last
  199. # point of the last segment.
  200. closed = True
  201. segmentType, points = segments[-1]
  202. movePt, _, _, _ = points[-1]
  203. if movePt is None:
  204. # quad special case: a contour with no on-curve points contains
  205. # one "qcurve" segment that ends with a point that's None. We
  206. # must not output a moveTo() in that case.
  207. pass
  208. else:
  209. pen.moveTo(movePt)
  210. outputImpliedClosingLine = self.outputImpliedClosingLine
  211. nSegments = len(segments)
  212. lastPt = movePt
  213. for i in range(nSegments):
  214. segmentType, points = segments[i]
  215. points = [pt for pt, _, _, _ in points]
  216. if segmentType == "line":
  217. if len(points) != 1:
  218. raise PenError(f"Illegal line segment point count: {len(points)}")
  219. pt = points[0]
  220. # For closed contours, a 'lineTo' is always implied from the last oncurve
  221. # point to the starting point, thus we can omit it when the last and
  222. # starting point don't overlap.
  223. # However, when the last oncurve point is a "line" segment and has same
  224. # coordinates as the starting point of a closed contour, we need to output
  225. # the closing 'lineTo' explicitly (regardless of the value of the
  226. # 'outputImpliedClosingLine' option) in order to disambiguate this case from
  227. # the implied closing 'lineTo', otherwise the duplicate point would be lost.
  228. # See https://github.com/googlefonts/fontmake/issues/572.
  229. if (
  230. i + 1 != nSegments
  231. or outputImpliedClosingLine
  232. or not closed
  233. or pt == lastPt
  234. ):
  235. pen.lineTo(pt)
  236. lastPt = pt
  237. elif segmentType == "curve":
  238. pen.curveTo(*points)
  239. lastPt = points[-1]
  240. elif segmentType == "qcurve":
  241. pen.qCurveTo(*points)
  242. lastPt = points[-1]
  243. else:
  244. raise PenError(f"Illegal segmentType: {segmentType}")
  245. if closed:
  246. pen.closePath()
  247. else:
  248. pen.endPath()
  249. def addComponent(self, glyphName, transform, identifier=None, **kwargs):
  250. del identifier # unused
  251. del kwargs # unused
  252. self.pen.addComponent(glyphName, transform)
  253. class SegmentToPointPen(AbstractPen):
  254. """
  255. Adapter class that converts the (Segment)Pen protocol to the
  256. PointPen protocol.
  257. """
  258. def __init__(self, pointPen, guessSmooth=True) -> None:
  259. if guessSmooth:
  260. self.pen = GuessSmoothPointPen(pointPen)
  261. else:
  262. self.pen = pointPen
  263. self.contour: Optional[List[Tuple[Point, SegmentType]]] = None
  264. def _flushContour(self) -> None:
  265. pen = self.pen
  266. pen.beginPath()
  267. for pt, segmentType in self.contour:
  268. pen.addPoint(pt, segmentType=segmentType)
  269. pen.endPath()
  270. def moveTo(self, pt):
  271. self.contour = []
  272. self.contour.append((pt, "move"))
  273. def lineTo(self, pt):
  274. if self.contour is None:
  275. raise PenError("Contour missing required initial moveTo")
  276. self.contour.append((pt, "line"))
  277. def curveTo(self, *pts):
  278. if not pts:
  279. raise TypeError("Must pass in at least one point")
  280. if self.contour is None:
  281. raise PenError("Contour missing required initial moveTo")
  282. for pt in pts[:-1]:
  283. self.contour.append((pt, None))
  284. self.contour.append((pts[-1], "curve"))
  285. def qCurveTo(self, *pts):
  286. if not pts:
  287. raise TypeError("Must pass in at least one point")
  288. if pts[-1] is None:
  289. self.contour = []
  290. else:
  291. if self.contour is None:
  292. raise PenError("Contour missing required initial moveTo")
  293. for pt in pts[:-1]:
  294. self.contour.append((pt, None))
  295. if pts[-1] is not None:
  296. self.contour.append((pts[-1], "qcurve"))
  297. def closePath(self):
  298. if self.contour is None:
  299. raise PenError("Contour missing required initial moveTo")
  300. # Remove the last point if it's a duplicate of the first, but only if both
  301. # are on-curve points (segmentType is not None); for quad blobs
  302. # (all off-curve) every point must be preserved:
  303. # https://github.com/fonttools/fonttools/issues/4014
  304. if (
  305. len(self.contour) > 1
  306. and (self.contour[0][0] == self.contour[-1][0])
  307. and self.contour[0][1] is not None
  308. and self.contour[-1][1] is not None
  309. ):
  310. self.contour[0] = self.contour[-1]
  311. del self.contour[-1]
  312. else:
  313. # There's an implied line at the end, replace "move" with "line"
  314. # for the first point
  315. pt, tp = self.contour[0]
  316. if tp == "move":
  317. self.contour[0] = pt, "line"
  318. self._flushContour()
  319. self.contour = None
  320. def endPath(self):
  321. if self.contour is None:
  322. raise PenError("Contour missing required initial moveTo")
  323. self._flushContour()
  324. self.contour = None
  325. def addComponent(self, glyphName, transform):
  326. if self.contour is not None:
  327. raise PenError("Components must be added before or after contours")
  328. self.pen.addComponent(glyphName, transform)
  329. class GuessSmoothPointPen(AbstractPointPen):
  330. """
  331. Filtering PointPen that tries to determine whether an on-curve point
  332. should be "smooth", ie. that it's a "tangent" point or a "curve" point.
  333. """
  334. def __init__(self, outPen, error=0.05):
  335. self._outPen = outPen
  336. self._error = error
  337. self._points = None
  338. def _flushContour(self):
  339. if self._points is None:
  340. raise PenError("Path not begun")
  341. points = self._points
  342. nPoints = len(points)
  343. if not nPoints:
  344. return
  345. if points[0][1] == "move":
  346. # Open path.
  347. indices = range(1, nPoints - 1)
  348. elif nPoints > 1:
  349. # Closed path. To avoid having to mod the contour index, we
  350. # simply abuse Python's negative index feature, and start at -1
  351. indices = range(-1, nPoints - 1)
  352. else:
  353. # closed path containing 1 point (!), ignore.
  354. indices = []
  355. for i in indices:
  356. pt, segmentType, _, name, kwargs = points[i]
  357. if segmentType is None:
  358. continue
  359. prev = i - 1
  360. next = i + 1
  361. if points[prev][1] is not None and points[next][1] is not None:
  362. continue
  363. # At least one of our neighbors is an off-curve point
  364. pt = points[i][0]
  365. prevPt = points[prev][0]
  366. nextPt = points[next][0]
  367. if pt != prevPt and pt != nextPt:
  368. dx1, dy1 = pt[0] - prevPt[0], pt[1] - prevPt[1]
  369. dx2, dy2 = nextPt[0] - pt[0], nextPt[1] - pt[1]
  370. a1 = math.atan2(dy1, dx1)
  371. a2 = math.atan2(dy2, dx2)
  372. if abs(a1 - a2) < self._error:
  373. points[i] = pt, segmentType, True, name, kwargs
  374. for pt, segmentType, smooth, name, kwargs in points:
  375. self._outPen.addPoint(pt, segmentType, smooth, name, **kwargs)
  376. def beginPath(self, identifier=None, **kwargs):
  377. if self._points is not None:
  378. raise PenError("Path already begun")
  379. self._points = []
  380. if identifier is not None:
  381. kwargs["identifier"] = identifier
  382. self._outPen.beginPath(**kwargs)
  383. def endPath(self):
  384. self._flushContour()
  385. self._outPen.endPath()
  386. self._points = None
  387. def addPoint(
  388. self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
  389. ):
  390. if self._points is None:
  391. raise PenError("Path not begun")
  392. if identifier is not None:
  393. kwargs["identifier"] = identifier
  394. self._points.append((pt, segmentType, False, name, kwargs))
  395. def addComponent(self, glyphName, transformation, identifier=None, **kwargs):
  396. if self._points is not None:
  397. raise PenError("Components must be added before or after contours")
  398. if identifier is not None:
  399. kwargs["identifier"] = identifier
  400. self._outPen.addComponent(glyphName, transformation, **kwargs)
  401. def addVarComponent(
  402. self, glyphName, transformation, location, identifier=None, **kwargs
  403. ):
  404. if self._points is not None:
  405. raise PenError("VarComponents must be added before or after contours")
  406. if identifier is not None:
  407. kwargs["identifier"] = identifier
  408. self._outPen.addVarComponent(glyphName, transformation, location, **kwargs)
  409. class ReverseContourPointPen(AbstractPointPen):
  410. """
  411. This is a PointPen that passes outline data to another PointPen, but
  412. reversing the winding direction of all contours. Components are simply
  413. passed through unchanged.
  414. Closed contours are reversed in such a way that the first point remains
  415. the first point.
  416. """
  417. def __init__(self, outputPointPen):
  418. self.pen = outputPointPen
  419. # a place to store the points for the current sub path
  420. self.currentContour = None
  421. def _flushContour(self):
  422. pen = self.pen
  423. contour = self.currentContour
  424. if not contour:
  425. pen.beginPath(identifier=self.currentContourIdentifier)
  426. pen.endPath()
  427. return
  428. closed = contour[0][1] != "move"
  429. if not closed:
  430. lastSegmentType = "move"
  431. else:
  432. # Remove the first point and insert it at the end. When
  433. # the list of points gets reversed, this point will then
  434. # again be at the start. In other words, the following
  435. # will hold:
  436. # for N in range(len(originalContour)):
  437. # originalContour[N] == reversedContour[-N]
  438. contour.append(contour.pop(0))
  439. # Find the first on-curve point.
  440. firstOnCurve = None
  441. for i in range(len(contour)):
  442. if contour[i][1] is not None:
  443. firstOnCurve = i
  444. break
  445. if firstOnCurve is None:
  446. # There are no on-curve points, be basically have to
  447. # do nothing but contour.reverse().
  448. lastSegmentType = None
  449. else:
  450. lastSegmentType = contour[firstOnCurve][1]
  451. contour.reverse()
  452. if not closed:
  453. # Open paths must start with a move, so we simply dump
  454. # all off-curve points leading up to the first on-curve.
  455. while contour[0][1] is None:
  456. contour.pop(0)
  457. pen.beginPath(identifier=self.currentContourIdentifier)
  458. for pt, nextSegmentType, smooth, name, kwargs in contour:
  459. if nextSegmentType is not None:
  460. segmentType = lastSegmentType
  461. lastSegmentType = nextSegmentType
  462. else:
  463. segmentType = None
  464. pen.addPoint(
  465. pt, segmentType=segmentType, smooth=smooth, name=name, **kwargs
  466. )
  467. pen.endPath()
  468. def beginPath(self, identifier=None, **kwargs):
  469. if self.currentContour is not None:
  470. raise PenError("Path already begun")
  471. self.currentContour = []
  472. self.currentContourIdentifier = identifier
  473. self.onCurve = []
  474. def endPath(self):
  475. if self.currentContour is None:
  476. raise PenError("Path not begun")
  477. self._flushContour()
  478. self.currentContour = None
  479. def addPoint(
  480. self, pt, segmentType=None, smooth=False, name=None, identifier=None, **kwargs
  481. ):
  482. if self.currentContour is None:
  483. raise PenError("Path not begun")
  484. if identifier is not None:
  485. kwargs["identifier"] = identifier
  486. self.currentContour.append((pt, segmentType, smooth, name, kwargs))
  487. def addComponent(self, glyphName, transform, identifier=None, **kwargs):
  488. if self.currentContour is not None:
  489. raise PenError("Components must be added before or after contours")
  490. self.pen.addComponent(glyphName, transform, identifier=identifier, **kwargs)
  491. class DecomposingPointPen(LogMixin, AbstractPointPen):
  492. """Implements a 'addComponent' method that decomposes components
  493. (i.e. draws them onto self as simple contours).
  494. It can also be used as a mixin class (e.g. see DecomposingRecordingPointPen).
  495. You must override beginPath, addPoint, endPath. You may
  496. additionally override addVarComponent and addComponent.
  497. By default a warning message is logged when a base glyph is missing;
  498. set the class variable ``skipMissingComponents`` to False if you want
  499. all instances of a sub-class to raise a :class:`MissingComponentError`
  500. exception by default.
  501. """
  502. skipMissingComponents = True
  503. # alias error for convenience
  504. MissingComponentError = MissingComponentError
  505. def __init__(
  506. self,
  507. glyphSet,
  508. *args,
  509. skipMissingComponents=None,
  510. reverseFlipped: bool | ReverseFlipped = False,
  511. **kwargs,
  512. ):
  513. """Takes a 'glyphSet' argument (dict), in which the glyphs that are referenced
  514. as components are looked up by their name.
  515. If the optional 'reverseFlipped' argument is True or a ReverseFlipped enum value,
  516. components whose transformation matrix has a negative determinant will be decomposed
  517. with a reversed path direction to compensate for the flip.
  518. The reverseFlipped parameter can be:
  519. - False or ReverseFlipped.NO: Don't reverse flipped components
  520. - True or ReverseFlipped.KEEP_START: Reverse, keeping original starting point
  521. - ReverseFlipped.ON_CURVE_FIRST: Reverse, ensuring first point is on-curve
  522. The optional 'skipMissingComponents' argument can be set to True/False to
  523. override the homonymous class attribute for a given pen instance.
  524. """
  525. super().__init__(*args, **kwargs)
  526. self.glyphSet = glyphSet
  527. self.skipMissingComponents = (
  528. self.__class__.skipMissingComponents
  529. if skipMissingComponents is None
  530. else skipMissingComponents
  531. )
  532. # Handle backward compatibility and validate string inputs
  533. if reverseFlipped is False:
  534. self.reverseFlipped = ReverseFlipped.NO
  535. elif reverseFlipped is True:
  536. self.reverseFlipped = ReverseFlipped.KEEP_START
  537. else:
  538. self.reverseFlipped = ReverseFlipped(reverseFlipped)
  539. def addComponent(self, baseGlyphName, transformation, identifier=None, **kwargs):
  540. """Transform the points of the base glyph and draw it onto self.
  541. The `identifier` parameter and any extra kwargs are ignored.
  542. """
  543. from fontTools.pens.transformPen import TransformPointPen
  544. try:
  545. glyph = self.glyphSet[baseGlyphName]
  546. except KeyError:
  547. if not self.skipMissingComponents:
  548. raise MissingComponentError(baseGlyphName)
  549. self.log.warning(
  550. "glyph '%s' is missing from glyphSet; skipped" % baseGlyphName
  551. )
  552. else:
  553. pen = self
  554. if transformation != Identity:
  555. pen = TransformPointPen(pen, transformation)
  556. if self.reverseFlipped != ReverseFlipped.NO:
  557. # if the transformation has a negative determinant, it will
  558. # reverse the contour direction of the component
  559. a, b, c, d = transformation[:4]
  560. if a * d - b * c < 0:
  561. pen = ReverseContourPointPen(pen)
  562. if self.reverseFlipped == ReverseFlipped.ON_CURVE_FIRST:
  563. from fontTools.pens.filterPen import OnCurveFirstPointPen
  564. # Ensure the starting point is an on-curve.
  565. # Wrap last so this filter runs first during drawPoints
  566. pen = OnCurveFirstPointPen(pen)
  567. glyph.drawPoints(pen)