From 0bf67cc0c979c036d61083d461a3a68645bccf42 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 25 May 2024 09:38:39 -0600 Subject: [PATCH] [statisticsPen] Fix __start_point access Fixes https://github.com/fonttools/fonttools/issues/3527 --- Lib/fontTools/misc/symfont.py | 19 +++++++++---------- Lib/fontTools/pens/momentsPen.py | 11 ++++++----- Lib/fontTools/pens/statisticsPen.py | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Lib/fontTools/misc/symfont.py b/Lib/fontTools/misc/symfont.py index fb9e20a46..3a8819c77 100644 --- a/Lib/fontTools/misc/symfont.py +++ b/Lib/fontTools/misc/symfont.py @@ -76,16 +76,16 @@ class GreenPen(BasePen): self.value = 0 def _moveTo(self, p0): - self.__startPoint = p0 + self._startPoint = p0 def _closePath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: - self._lineTo(self.__startPoint) + if p0 != self._startPoint: + self._lineTo(self._startPoint) def _endPath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: + if p0 != self._startPoint: # Green theorem is not defined on open contours. raise NotImplementedError @@ -145,19 +145,18 @@ class %s(BasePen): print( """ def _moveTo(self, p0): - self.__startPoint = p0 + self._startPoint = p0 def _closePath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: - self._lineTo(self.__startPoint) + if p0 != self._startPoint: + self._lineTo(self._startPoint) def _endPath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: - # Green theorem is not defined on open contours. + if p0 != self._startPoint: raise OpenContourError( - "Green theorem is not defined on open contours." + "Glyph statistics is not defined on open contours." ) """, end="", diff --git a/Lib/fontTools/pens/momentsPen.py b/Lib/fontTools/pens/momentsPen.py index 4c7ddfe32..2afb8fdbd 100644 --- a/Lib/fontTools/pens/momentsPen.py +++ b/Lib/fontTools/pens/momentsPen.py @@ -15,6 +15,7 @@ __all__ = ["MomentsPen"] class MomentsPen(BasePen): + def __init__(self, glyphset=None): BasePen.__init__(self, glyphset) @@ -26,17 +27,17 @@ class MomentsPen(BasePen): self.momentYY = 0 def _moveTo(self, p0): - self.__startPoint = p0 + self._startPoint = p0 def _closePath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: - self._lineTo(self.__startPoint) + if p0 != self._startPoint: + self._lineTo(self._startPoint) def _endPath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: - raise OpenContourError("Glyph statistics not defined on open contours.") + if p0 != self._startPoint: + raise OpenContourError("Glyph statistics is not defined on open contours.") @cython.locals(r0=cython.double) @cython.locals(r1=cython.double) diff --git a/Lib/fontTools/pens/statisticsPen.py b/Lib/fontTools/pens/statisticsPen.py index 699b14ca7..b91d93b6e 100644 --- a/Lib/fontTools/pens/statisticsPen.py +++ b/Lib/fontTools/pens/statisticsPen.py @@ -123,7 +123,7 @@ class StatisticsControlPen(StatisticsBase, BasePen): def _endPath(self): p0 = self._getCurrentPoint() - if p0 != self.__startPoint: + if p0 != self._startPoint: raise OpenContourError("Glyph statistics not defined on open contours.") def _update(self):