Skip to content

Instantly share code, notes, and snippets.

@frankrolf
Created June 14, 2017 19:09
Show Gist options
  • Select an option

  • Save frankrolf/36a759625115c86cab3f6822b6fc49ad to your computer and use it in GitHub Desktop.

Select an option

Save frankrolf/36a759625115c86cab3f6822b6fc49ad to your computer and use it in GitHub Desktop.
Export Robofont’s space center as a PNG file
import os
from AppKit import NSBitmapImageRep, NSPNGFileType, NSColor
from mojo.UI import CurrentSpaceCenter
def export_space_center_to_png(url):
sp = CurrentSpaceCenter()
sp_view = sp.glyphLineView.getNSScrollView()
sp_view.lockFocus()
rep = NSBitmapImageRep.alloc().initWithFocusedViewRect_(sp_view.bounds())
sp_view.unlockFocus()
data = rep.representationUsingType_properties_(NSPNGFileType, {})
data.writeToFile_atomically_(url, True)
sp_view.setBackgroundColor_(NSColor.whiteColor())
image_path = os.path.expanduser('~/Desktop/space_center.png')
export_space_center_to_png(image_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment