Skip to content

Instantly share code, notes, and snippets.

@LettError
Created December 8, 2023 09:21
Show Gist options
  • Save LettError/52e431f922b139cbf8b51f026a5dd628 to your computer and use it in GitHub Desktop.
Save LettError/52e431f922b139cbf8b51f026a5dd628 to your computer and use it in GitHub Desktop.
Generate a preview font with the current designspace and show it in the current spacecenter
from fontTools.designspaceLib import InstanceDescriptor
from mojo.UI import CurrentSpaceCenter
# Scripting with live designspaces
# demo [email protected] 8.12.2023
# have a desigspace open in DSE2
d = CurrentDesignspace()
# have a spacecenter open
sp = CurrentSpaceCenter()
# you probably want more control over what axis values to look at
# and maybe even a fancy interface
# but that is beyond the scope of this demo
# so for now, a random location
loc = d.randomLocation()
# see the location is just a dict with axisName: axisValue pairs,
print(loc)
# make an "instance descriptor" object to specify what we want to see
preview = InstanceDescriptor()
#preview.familyName = "MyPreview"
#preview.styleName = "MyStyle"
preview.designLocation = loc
# now we're asking the designspace to make a font object with these specs
r = d.makeInstance(preview)
print(r)
# finally, we give the resulting font to the space center.
sp.setFont(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment