Skip to content

Commit

Permalink
back to ..misc.platform import platform with SimpleNamespace
Browse files Browse the repository at this point in the history
  • Loading branch information
stenson committed Jan 17, 2025
1 parent 04cb905 commit 5e2747b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Lib/fontgoggles/font/dsFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from ..compile.dsCompiler import getTTPaths
from ..misc.hbShape import HBShape
from ..misc.properties import cachedProperty
import fontgoggles.misc.platform as platform
from ..misc.platform import platform


class DesignSpaceSourceError(CompilerError):
Expand Down Expand Up @@ -443,7 +443,7 @@ def verticalOrigin(self):
return self.getPoints()[-2]

def getOutline(self):
return platform.platform.pathFromArrays(self, self.getPoints(), self.tags, self.contours)
return platform.pathFromArrays(self, self.getPoints(), self.tags, self.contours)

def draw(self, pen):
ppen = PointToSegmentPen(pen)
Expand Down
12 changes: 6 additions & 6 deletions Lib/fontgoggles/font/glyphDrawing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from fontTools.misc.arrayTools import unionRect
import fontgoggles.misc.platform as platform
from ..misc.platform import platform
from ..misc.properties import cachedProperty


Expand All @@ -23,11 +23,11 @@ def __init__(self, path):
def bounds(self):
bounds = None
if self.path.elementCount():
bounds = platform.platform.convertRect(self.path.controlPointBounds())
bounds = platform.convertRect(self.path.controlPointBounds())
return bounds

def draw(self, colorPalette, defaultColor):
platform.platform.convertColor(defaultColor).set()
platform.convertColor(defaultColor).set()
self.path.fill()

def pointInside(self, pt):
Expand All @@ -45,7 +45,7 @@ def bounds(self):
for path, colorID in self.layers:
if not path.elementCount():
continue
pathBounds = platform.platform.convertRect(path.controlPointBounds())
pathBounds = platform.convertRect(path.controlPointBounds())
if bounds is None:
bounds = pathBounds
else:
Expand All @@ -59,7 +59,7 @@ def draw(self, colorPalette, defaultColor):
if colorID < len(colorPalette) else
defaultColor
)
platform.platform.convertColor(color).set()
platform.convertColor(color).set()
path.fill()

def pointInside(self, pt):
Expand All @@ -76,7 +76,7 @@ def bounds(self):
return self.colorFont.getGlyphBounds(self.glyphName)

def draw(self, colorPalette, defaultColor):
platform.platform.drawCOLRv1Glyph(self.colorFont, self.glyphName, colorPalette, defaultColor)
platform.drawCOLRv1Glyph(self.colorFont, self.glyphName, colorPalette, defaultColor)

def pointInside(self, pt):
return False # TODO: implement
6 changes: 3 additions & 3 deletions Lib/fontgoggles/font/otfFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
from ..compile.compilerPool import compileTTXToBytes
from ..misc.hbShape import HBShape
from ..misc.properties import cachedProperty
import fontgoggles.misc.platform as platform
from ..misc.platform import platform


class _OTFBaseFont(BaseFont):

def _getGlyphOutline(self, name):
return platform.platform.pathFromGlyph(self.shaper.font, self.shaper.glyphMap[name])
return platform.pathFromGlyph(self.shaper.font, self.shaper.glyphMap[name])

def _getGlyphDrawing(self, glyphName, colorLayers):
if "VarC" in self.ttFont:
penwrapper = platform.platform.PenWrapper(None)
penwrapper = platform.PenWrapper(None)
location = self._currentVarLocation or {}
self.varcFont.drawGlyph(penwrapper.pen, glyphName, location)
return GlyphDrawing(penwrapper.getOutline())
Expand Down
6 changes: 3 additions & 3 deletions Lib/fontgoggles/font/ufoFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from ..compile.ufoCompiler import fetchGlyphInfo
from ..misc.hbShape import HBShape
from ..misc.properties import cachedProperty
import fontgoggles.misc.platform as platform
from ..misc.platform import platform


class UFOFont(BaseFont):
Expand Down Expand Up @@ -151,7 +151,7 @@ def _getGlyph(self, glyphName, layerName=None):
return glyph

def _addOutlinePathToGlyph(self, glyph):
penwrapper = platform.platform.PenWrapper(self.glyphSet)
penwrapper = platform.PenWrapper(self.glyphSet)
glyph.draw(penwrapper.pen)
glyph.outline = penwrapper.getOutline()

Expand Down Expand Up @@ -258,7 +258,7 @@ def setVarLocation(self, varLocation):
pass

def getOutline(self):
penwrapper = platform.platform.PenWrapper(None)
penwrapper = platform.PenWrapper(None)
self.draw(penwrapper.pen)
return penwrapper.getOutline()

Expand Down
9 changes: 7 additions & 2 deletions Lib/fontgoggles/misc/platform.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from types import SimpleNamespace
from fontTools.pens.recordingPen import RecordingPen

"""
Expand Down Expand Up @@ -101,14 +102,18 @@ def getOutline(self):
return self.pen


platform = PlatformCocoa if CAN_COCOA else PlatformGeneric
platform = SimpleNamespace()

_platform = PlatformCocoa if CAN_COCOA else PlatformGeneric
platform.__dict__.update(**_platform.__dict__)


def setUseCocoa(onOff):
global platform
if onOff:
assert CAN_COCOA
platform = PlatformCocoa if onOff else PlatformGeneric
_platform = PlatformCocoa if onOff else PlatformGeneric
platform.__dict__.update(**_platform.__dict__)


def getUseCocoa():
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_makeOutline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from fontTools.ttLib import TTFont
from fontgoggles.font.otfFont import OTFFont
import fontgoggles.misc.platform as platform
from fontgoggles.misc.platform import platform
from testSupport import getFontPath


Expand All @@ -19,7 +19,7 @@ async def test_getOutlinePath():

for glyphName in ["a", "B", "O", "period", "bar", "aring"]:
p = font._getGlyphOutline(glyphName)
penwrapper = platform.platform.PenWrapper(ttfGlyphSet)
penwrapper = platform.PenWrapper(ttfGlyphSet)
ttfGlyphSet[glyphName].draw(penwrapper.pen)
# The paths are not identical, due to different rounding
# of the implied points, and different closepath behavior,
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_noCocoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from asyncio import run
from fontgoggles.font import getOpener
from fontgoggles.misc.textInfo import TextInfo
from fontgoggles.misc.platform import platform, setUseCocoa
from testSupport import getFontPath
from fontTools.pens.recordingPen import RecordingPen

import fontgoggles.misc.platform as platform

font_paths = [
"MutatorSans.ttf",
Expand Down Expand Up @@ -36,7 +36,7 @@ def getDrawings(path):
for g in glyphDrawings:
assert "NSBezierPath" in str(type(g.path))

platform.setUseCocoa(False)
setUseCocoa(False)

for font_path in font_paths:
glyphDrawings = getDrawings(font_path)
Expand Down

0 comments on commit 5e2747b

Please sign in to comment.