-
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.
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 |
Hi @justvanrossum — no worries at all on timing, there's no urgency on my end as I've already published a version of the coldtype-fontgoggles idea on pypi. I’m happy to modify this PR, although I'm not sure your suggestion works for my use case, as this isn’t a classic platform-detection situation. I use the I think I could get your idea to work if I could override Would an environment variable read at initialization + the one big if/else statement be preferable to the current runtime-modifiable code? Sorry for the long note! |
Ahhhh yes, I understand, you're "poking" the USE_COCOA var, so this isn't a static thing at all. Let me think about this a bit more. |
I've been thinking about this a bit myself and I realiazed the coldtype-fontgoggles fork on pypi could just hardcode USE_COCOA to be False as a patch, so it could be a fully static thing as you've outlined, i.e. in the fork USE_COCOA is always False but in the real fontgoggles repo it'd be an actual platform-detect based on |
Hm, I still prefer something dynamic, also so we can easily test both. I'm leaning to something closer to your original proposal: to have an object in platform.py that provides the functionality. Something in this direction: class PlatformCocoa:
@staticmethod
def makePathFromArrays(...):
...
class PlatformGeneric:
@staticmethod
def makePathFromArrays(...):
...
platform = PlatformCocoa if CAN_COCOA else PlatformGeneric
def setUseCocoa(onOff):
global platform
if onOff:
assert CAN_COCOA
platform = PlatformCocoa if onOff else PlatformGeneric
def getUseCocoa():
return platform is PlatformCocoa |
Works for me! Just pushed up code in that style. I think the only "odd" thing is that you can’t do import fontgoggles.misc.platform as platform
print(platform.platform) # <class 'fontgoggles.misc.platform.PlatformCocoa'>
platform.setUseCocoa(False)
print(platform.platform) # <class 'fontgoggles.misc.platform.PlatformGeneric'> and then everything works as it should. If it’s a relative import in the style you’re using, then it doesn't seem to work: from ..misc.platform import platform, setUseCocoa
print(platform) # <class 'fontgoggles.misc.platform.PlatformCocoa'>
setUseCocoa(False)
print(platform) # # <class 'fontgoggles.misc.platform.PlatformCocoa'> Basically that just means there’s lots of |
You're right, the |
the |
Makes sense to me, I've just pushed that up and got rid of all the _platform = PlatformCocoa if CAN_COCOA else PlatformGeneric
platform.__dict__.update(**_platform.__dict__) |
Yeah, that One ore request: instead of the PenWrapper attribute I'd like you to take the suggestion from this comment, but then as |
Ah, sorry for missing that! Just pushed up |
You can leave out the |
Forgot to comment here that I deleted the pen init argument, and just now I just realized the |
Just discovered the SimpleNamespace + |
Ah, you're right. The app is currently built with 3.12, the README asks for 3.10 or up, but the (root) setup.py asks for 3.7 and up. The latter is out of date. I suppose we should bump that to 3.10 as well. |
…espace solution can't accomodate @staticmethod's otherwise
Sounds good to me, I’ve bumped setup.py to 3.10 on this PR. |
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!