Skedge
🎉 Well, wait no longer! “Skedge” let’s you do exactly this! 🎉
“Skedge” is your playground, your tool to explore how to use python to build incredible anylitic tools for your workflow. Visual feedback in realtime is something that we designers always strive for.
Hopefully “Skedge” will tear down the inhibition level for beginners and be a companion on the way to learn coding. The sense of achievement will make you happy. But this tool will help you anytime, no matter if you just started with python or if you’re an experienced developer already.
...
1) A plugin which draws something to your active Edit Tab
Example
How to use
- (If you haven’t yt, install once from the Plugin Manager in Glyphs.)
- Open “Skedge” from the Window menu. It will present you a super simple sample code to begin with.
- You can open and/or save your code for later. Just hit
Cmd+S
orCmd+O
. - Switch off the checkbox “Live”, if you don’t want to see changes in realtime.
- If so, be sure to hit the “Run” button (or
Cmd+R
) to run your code. Cmd+K
resets the drawing in your Edit Tab. The same happens when you close the window.Cmd+P
lets you print your code or save it as PDF.- Python etiquette: please use
TABS
! I’m not trying to force you into that endless battle, I just didn’t prepare the tool to deal withSPACES
yet. Bear with me. BTW: f*** spaces! :D - The code in “Skedge” can be almost exactly transferred into an actual reporter plugin. For this, don’t forget to build it as a
class
like theglyphsReporter
do. You’ll have to instantiate and call it in your Skedge code, which you don’t have to do later in the Reporter Plugin.
Reset to Default Code
In case something goes wrong and you want Skedge to launch again with the default code, rather than your last state, run this once in GlyphApp’s Macro Panel:
del(Glyphs.defaults["SkedgeCode"])
Help
You find help and code examples here:
It’s also always possible to peek into public plugins:
and other people who are endlessly kind to share their skills with the world. :)
Sample Codes
You can dump these snippets right into “Skedge” and they will (hopefully) just do what they claim to do:
01)
###################
# Draw Layer Bounds
###################
from AppKit import NSRectFill, NSRect, NSMakeRect
NSColor.yellowColor().set()
bounds = layer.bounds
x = bounds.origin.x
y = bounds.origin.y
width = bounds.size.width
height = bounds.size.height
rect = NSMakeRect(x, y, width, height)
NSRectFill(rect)
02)
###################################################################
# Draw filled Path with red outline and highlight every second Node
###################################################################
import traceback
scale = Glyphs.font.currentTab.scale
def badge(x, y, size):
myPath = NSBezierPath.alloc().init()
myRect = NSRect( ( x-size/2, y-size/2 ), ( size, size ) )
thisPath = NSBezierPath.bezierPathWithOvalInRect_( myRect )
myPath.appendBezierPath_( thisPath )
NSColor.colorWithCalibratedRed_green_blue_alpha_( 0.5, .5, 0.5, .3 ).set()
myPath.fill()
for path in layer.paths:
NSColor.grayColor().colorWithAlphaComponent_(0.3).set()
bp = path.bezierPath
bp.fill()
bp.setLineWidth_(5/scale)
NSColor.redColor().set()
bp.stroke()
for i, node in enumerate(path.nodes):
if i % 2:
badge(node.x, node.y, 20/scale )
03)
#################################################
# Draw plumblines at each path’s center (x and y)
#################################################
import traceback
global layer, scale, drawLine ## Skedge-Hack
scale = Glyphs.font.currentTab.scale
layer = Glyphs.font.selectedLayers[0]
NSColor.blueColor().set()
def drawLine((x1, y1), (x2, y2)):
strokeWidth = 1/scale
path = NSBezierPath.bezierPath()
path.moveToPoint_((x1, y1))
path.lineToPoint_((x2, y2))
path.setLineWidth_(strokeWidth)
path.setLineDash_count_phase_((10, 2), 2, 0.0)
path.stroke()
def DrawCross((x, y), (width, height)):
### BOUNDS DIMENSIONS
xRight = x + width
yTop = y + height
xCenter = (x + width/2)
yCenter = (y + height/2)
### LAYER/METRIC DIMENSIONS
left = 0
right = layer.width
ascender = layer.glyphMetrics()[1]
descender = layer.glyphMetrics()[3]
drawLine((left, yCenter), (right, yCenter))
drawLine((xCenter, descender), (xCenter, ascender))
for path in layer.paths:
DrawCross(*[p for p in path.bounds])
04)
#################################################
# # Draw line @ half Cap Height
#################################################
from AppKit import NSColor, NSBezierPath
scale = Glyphs.font.currentTab.scale
layer = Glyphs.font.selectedLayers[0]
def myColor(a, b, c, d):
c = NSColor.colorWithHue_saturation_brightness_alpha_(a, b, c, d)
return c
def line(x1, y1, x2, y2, scale):
myPath = NSBezierPath.alloc().init()
myPath.moveTo_((x1, y1))
myPath.lineTo_((x2, y2))
NSColor.systemPurpleColor().colorWithAlphaComponent_(0.9).set()
myPath.setLineWidth_(.5/scale)
myPath.stroke()
capHeight = layer.associatedFontMaster().capHeight
width = layer.width
line(0, capHeight/2, width, capHeight/2, scale)
Important
- Beta! Please backup your files. No guarantee for destroying your files.
- Take care when doing transforms or things alike on your layer's bezierPath. Since it will actually address the real path, be sure to make a
.copy()
of your layer before proceeding with those. If you’re just reading data and drawing new objects from that data, you should be fine.
Known Issues
- Once a script was opened via cmd+o, the floating window is not such anymore, it will always go the the background now when you click into the Edit Tab.
- Some people report a crash caused by scrolling in the Code Editor. I cannot reproduce yet, so I’ll need Console Logs.
Some Plugins which add a DRAWBACKGROUND callback could interfere with this plugin and hence either or both fail to operate.[Solved in Glyphs builds higher than around 1110]- Syntax Highlighting is yet very rudimentary. But waaay better than none.
- Unfortunately It can fail to work in some environments. I witnessed one script executing fine on one computer and refusing to work on others without any tracebacks, error throws or console logs. Don’t panic and let me know. I’m happy to find the cause.
Copying code from certain sources can mess with the syntax highlighting. Maybe I got a severe setup issue with my self written syntax highlighting. Maybecmd
+shift
-pasting helps.
TODO
- Autosave text edits. Reopening Skedge now remembers your code. Thanks Georg!
- Fix encoding. Cannot save a file with words like »don’t«.
- Display change of file in Window Title (Completely different file handling).
- Skedge has some peculiar quirks that don’t need to be transferred to the actual reporterPlugin code later. (For instance calling some variables and functions
global
) - Provide more code snippets.
- Sophisticated syntax highlighting.
- Add license to Repo.
Pull Requests
Feel free to comment or pull requests for any improvements.
License
Copyright 2017 Mark Frömberg @Mark2Mark
Made possible with the Glyphs SDK by Georg Seifert (@schriftgestalt) and Rainer Erich Scheichelbauer (@mekkablue). Thanks to Georg Seifert (@schriftgestalt) for streamlining and helping to make this tool still work after a lot of recent API changes!
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
See the License file included in this repository for further details.