-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optional cross-platform outline rendering mode #451
base: master
Are you sure you want to change the base?
Conversation
…(wip; only CocoaPen has been abstracted, not makePathFromArrays)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what to do about the "Turbo" build. Maybe it is fine for now. Ideally you'd distribute a wheel for macOS that includes the Turbo binary, but that is a pain to set up (and TBH I wouldn't know where to start at this point).
Let me know what you think about my other comments.
Lib/fontgoggles/misc/platform.py
Outdated
CAN_COCOA = False | ||
|
||
|
||
class Platform(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to get rid of this additional class. All its methods are static, so might as well be functions in this module. If you like the "[Pp]latform" prefix in the client code, you could import the module "platform" instead of its contents, but I don't mind if you'd just import the needed names, ie. from ..misc.platform import pathFromGlyph
.
(Although then perhaps it's nicer to stick with the original funtion names, eg. makePathFromGlyph
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! I went with just importing the names. The idea of the Platform
class was just to have an easy way to set the global variable (Platform.UseCocoa
) but it’s just as easy to import as platform
and then set platform.USE_COCOA
(as in the updated noCocoa test)
requirements.txt
Outdated
@@ -4,15 +4,15 @@ py2app==0.28.8 | |||
pyobjc==10.3.1 | |||
corefoundationasyncio==0.0.1 | |||
cocoa-vanilla==0.6.0 | |||
blackrenderer==0.6.0 | |||
fonttools[woff,lxml,unicode,ufo,type1]==4.53.1 | |||
### blackrenderer==0.6.0 # moved to setup.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should stay, as they get updated by dependabot. Also, in setup.py you should ideally not pin dependencies, although you are right they should be mentioned (but either without version, or with a minimal version).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally makes sense. I did keep the pinned ==
for python-bidi
since there’s the issue of the interface change there, does that work?
I've fixed the ufo2ft problem, so if you rebase/merge main you should be able to unpin it. |
(I messed up some other dependencies in the meantime, working on it) |
Should be all good after #454 |
Applogies for my slow progress on this. I have one more request regarding the platform module: that all functions/classes that need alternate implementations aren't wrapped, but left as is, and that compatible implementations are provided in the For example, for the if USE_COCOA:
from ..mac.makePathFromOutline import makePathFromGlyph
else:
def makePathFromGlyph(font, gid):
rp = RecordingPen()
font.draw_glyph_with_pen(gid, rp)
return rp There are two cases where you don't provide an alternative implementation, yet don't raise if USE_COCOA:
from ..mac.drawing import nsColorFromRGBA
else:
def nsColorFromRGBA(c):
raise NotImplementedError()
if USE_COCOA:
from ..mac.makePathFromOutline import makePathFromArrays
else:
makePathFromArrays = None # caller should use pen protocol instead And then in def getOutline(self):
if makePathFromArrays is not None:
return makePathFromArrays(self.getPoints(), self.tags, self.contours)
else:
rp = RecordingPen()
self.draw(rp)
return rp For the if USE_COCOA:
PlatformPen = CocoaPen
else:
class PlatformPen(RecordingPen):
@property
def path(self):
return self It could be one big |
In order to use FontGoggles as a code-only and cross-platform dependency in coldtype, I’ve refactored some code to use a new wrapper for all the mac-only operations in
Lib/fontgoggles/compile and Lib/fontgoggles/font
. The main outcome is that there’s now an additionalRecordingPen
-based code path for all of the outline-building (which I use in coldtype). Most of the new code here is inLib/fontgoggles/misc/platform.py
.One odd thing / TODO here is that the code is now cross-platform, but the test I wrote assumes the test only runs on macOS (since it’s assuming
Platform.UseCocoa
will beTrue
in the default setup). I’m not sure if this should be spelled out explicitly, since the tests only run on macOS anyway.I’ve also wrapped the Turbo build step in a try/except since the darwin test isn't fully accurate, i.e. if you install this fork of fontgoggles into DrawBot, the build_lib.sh step fails even though it's building on mac. Obviously that's not ideal since the build step is necessary for the GUI version to work, though does ensure a more constrained environment like DrawBot or Blender python can install this without issue.
Thanks for taking a look!