diff --git a/Lib/fontgoggles/font/dsFont.py b/Lib/fontgoggles/font/dsFont.py index 348c6773..72b29a42 100644 --- a/Lib/fontgoggles/font/dsFont.py +++ b/Lib/fontgoggles/font/dsFont.py @@ -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): @@ -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) diff --git a/Lib/fontgoggles/font/glyphDrawing.py b/Lib/fontgoggles/font/glyphDrawing.py index 86467fed..8492b27e 100644 --- a/Lib/fontgoggles/font/glyphDrawing.py +++ b/Lib/fontgoggles/font/glyphDrawing.py @@ -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 @@ -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): @@ -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: @@ -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): @@ -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 diff --git a/Lib/fontgoggles/font/otfFont.py b/Lib/fontgoggles/font/otfFont.py index 6a033a03..abf05a72 100644 --- a/Lib/fontgoggles/font/otfFont.py +++ b/Lib/fontgoggles/font/otfFont.py @@ -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()) diff --git a/Lib/fontgoggles/font/ufoFont.py b/Lib/fontgoggles/font/ufoFont.py index d5fab608..e36241a7 100644 --- a/Lib/fontgoggles/font/ufoFont.py +++ b/Lib/fontgoggles/font/ufoFont.py @@ -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): @@ -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() @@ -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() diff --git a/Lib/fontgoggles/misc/platform.py b/Lib/fontgoggles/misc/platform.py index f525edcd..d11df8e9 100644 --- a/Lib/fontgoggles/misc/platform.py +++ b/Lib/fontgoggles/misc/platform.py @@ -1,3 +1,4 @@ +from types import SimpleNamespace from fontTools.pens.recordingPen import RecordingPen """ @@ -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(): diff --git a/Tests/test_makeOutline.py b/Tests/test_makeOutline.py index 55bfca8f..a26427bf 100644 --- a/Tests/test_makeOutline.py +++ b/Tests/test_makeOutline.py @@ -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 @@ -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, diff --git a/Tests/test_noCocoa.py b/Tests/test_noCocoa.py index 53fe731b..1e9e98c6 100644 --- a/Tests/test_noCocoa.py +++ b/Tests/test_noCocoa.py @@ -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", @@ -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)