diff --git a/Lib/fontgoggles/font/otfFont.py b/Lib/fontgoggles/font/otfFont.py index abf05a72..28ff8c57 100644 --- a/Lib/fontgoggles/font/otfFont.py +++ b/Lib/fontgoggles/font/otfFont.py @@ -15,10 +15,10 @@ def _getGlyphOutline(self, name): def _getGlyphDrawing(self, glyphName, colorLayers): if "VarC" in self.ttFont: - penwrapper = platform.PenWrapper(None) + pen = platform.Pen(None) location = self._currentVarLocation or {} - self.varcFont.drawGlyph(penwrapper.pen, glyphName, location) - return GlyphDrawing(penwrapper.getOutline()) + self.varcFont.drawGlyph(pen, glyphName, location) + return GlyphDrawing(pen.path) if colorLayers: if self.colorLayers is not None: layers = self.colorLayers.get(glyphName) diff --git a/Lib/fontgoggles/font/ufoFont.py b/Lib/fontgoggles/font/ufoFont.py index e36241a7..86e954c9 100644 --- a/Lib/fontgoggles/font/ufoFont.py +++ b/Lib/fontgoggles/font/ufoFont.py @@ -151,9 +151,9 @@ def _getGlyph(self, glyphName, layerName=None): return glyph def _addOutlinePathToGlyph(self, glyph): - penwrapper = platform.PenWrapper(self.glyphSet) - glyph.draw(penwrapper.pen) - glyph.outline = penwrapper.getOutline() + pen = platform.Pen(self.glyphSet) + glyph.draw(pen) + glyph.outline = pen.path def _getHorizontalAdvance(self, glyphName): glyph = self._getGlyph(glyphName) @@ -258,9 +258,9 @@ def setVarLocation(self, varLocation): pass def getOutline(self): - penwrapper = platform.PenWrapper(None) - self.draw(penwrapper.pen) - return penwrapper.getOutline() + pen = platform.Pen(None) + self.draw(pen) + return pen.path class Glyph(GLIFGlyph): diff --git a/Lib/fontgoggles/misc/platform.py b/Lib/fontgoggles/misc/platform.py index d11df8e9..90e45ea3 100644 --- a/Lib/fontgoggles/misc/platform.py +++ b/Lib/fontgoggles/misc/platform.py @@ -54,16 +54,8 @@ def drawCOLRv1Glyph(colorFont, glyphName, colorPalette, defaultColor): palette=colorPalette, textColor=defaultColor, ) - - class PenWrapper: - def __init__(self, glyphSet, path=None): - self.pen = CocoaPen(glyphSet, path=path) - - def draw(self, pen): - self.pen.draw(pen) - - def getOutline(self): - return self.pen.path + + Pen = CocoaPen class PlatformGeneric: @@ -90,16 +82,14 @@ def convertColor(c): @staticmethod def drawCOLRv1Glyph(colorFont, glyphName, colorPalette, defaultColor): raise NotImplementedError() - - class PenWrapper: - def __init__(self, glyphSet, path=None): - self.pen = RecordingPen() - - def draw(self, pen): - self.pen.draw(pen) - - def getOutline(self): - return self.pen + + class Pen(RecordingPen): + def __init__(self, glyphSet, path=None): # to match CocoaPen constructor + super().__init__() + + @property + def path(self): + return self platform = SimpleNamespace() diff --git a/Tests/test_makeOutline.py b/Tests/test_makeOutline.py index a26427bf..1ed59201 100644 --- a/Tests/test_makeOutline.py +++ b/Tests/test_makeOutline.py @@ -19,12 +19,12 @@ async def test_getOutlinePath(): for glyphName in ["a", "B", "O", "period", "bar", "aring"]: p = font._getGlyphOutline(glyphName) - penwrapper = platform.PenWrapper(ttfGlyphSet) - ttfGlyphSet[glyphName].draw(penwrapper.pen) + pen = platform.Pen(ttfGlyphSet) + ttfGlyphSet[glyphName].draw(pen) # The paths are not identical, due to different rounding # of the implied points, and different closepath behavior, # so comparing is hard, so we'll settle for a bounding box. - assert p.controlPointBounds() == penwrapper.pen.path.controlPointBounds() + assert p.controlPointBounds() == pen.path.controlPointBounds() @pytest.mark.asyncio