Skip to content

Commit

Permalink
get rid of PenWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
stenson committed Jan 17, 2025
1 parent 5e2747b commit dd11df3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Lib/fontgoggles/font/otfFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions Lib/fontgoggles/font/ufoFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
30 changes: 10 additions & 20 deletions Lib/fontgoggles/misc/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_makeOutline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd11df3

Please sign in to comment.