Scripting
Till now you can use all methods and properties (documentation below) of the cocoa framework provided by the pyObjc bridge or the JSTalk bridge. There will be a scripting layer to simplify the access. This layer may be compatible to RoboFab.The usage of the (rather laborious) cocoa accessor methods ensure the proper setup of the objects and support e.g. undo/redo.
Documentation:
Plugins
There are four kinds of plugins so far:- Tools: They will be loaded in the main toolbar. (5 shipping: Select, Draw, Text, Hand, Zoom)
- Import/Export: Easy way to support new file and font formats. (shipping: Im/Export of OTF and UFO)
- Palette: Some features need a palette to be on screen all the time. (shipping: Transform; planned Loupe)
- Effects/Filter: Features like Remove overlap, Bold, Clean ... (2 shipping: Remove Overlap, Round Corners)
Plugins can be developed in ObjectivC (recommended) and Python (via PyPbjC bridge).
Using the integrated macro panel
This is only a very small example but shows the basics.It gets the fist Master of the glyph "a", prints all nodes and shift them 10.5 units to the right.
FontMaster = Font.fontMasterAtIndex_(0)
Layer = Font.glyphForName_("a").layerForKey_(FontMaster.id())
for currPath in Layer.paths():
if (currPath.closed()):
print "closed Path"
for currNode in currPath.nodes():
print currNode
Position = currNode.position()
Position.x = Position.x + 10.5
print Position
currNode.setPosition_(Position)
Layer = Font.glyphForName_("a").layerForKey_(FontMaster.id())
for currPath in Layer.paths():
if (currPath.closed()):
print "closed Path"
for currNode in currPath.nodes():
print currNode
Position = currNode.position()
Position.x = Position.x + 10.5
print Position
currNode.setPosition_(Position)
Sample app to demonstrate the use of the Distributed Objects Connection.
Now with live update (works with Glyphs 0.2.1 and later)Using Python
From within any python installed pyObjC (e.g. the standard python shipped with MacOSX).You only need to include the "JSTalk.py".
import JSTalk
JSTest = JSTalk.application("Glyphs");
doc = JSTest.orderedDocuments()[0] #the active document
Font = doc.font()
FontMaster = Font.fontMasters()[0]
Glyph = Font.glyphForName_("A")
Layer = Glyph.layerForKey_(FontMaster.id())
print(Layer)
for i in range(len(Layer.paths())):
print "Path: %d" % i
Path = Layer.paths()[i]
for j in range(len(Path.nodes())):
Node = Path.nodes()[j];
Node.setPosition_((Node.position().x * 0.5, Node.position().y))
print(" Node[%d] {%1.1f, %1.1f}" % (j, Node.position().x, Node.position().y))
JSTest = JSTalk.application("Glyphs");
doc = JSTest.orderedDocuments()[0] #the active document
Font = doc.font()
FontMaster = Font.fontMasters()[0]
Glyph = Font.glyphForName_("A")
Layer = Glyph.layerForKey_(FontMaster.id())
print(Layer)
for i in range(len(Layer.paths())):
print "Path: %d" % i
Path = Layer.paths()[i]
for j in range(len(Path.nodes())):
Node = Path.nodes()[j];
Node.setPosition_((Node.position().x * 0.5, Node.position().y))
print(" Node[%d] {%1.1f, %1.1f}" % (j, Node.position().x, Node.position().y))
Using JSTalk
JSTalk provides a preprocessor witch allows the usage of the cocoa style in Javascript.Script example in cocoa style:
doc = [[JSTalk application:"Glyphs"] orderedDocuments][0];
Font = [doc font];
FontMaster = [Font fontMasterAtIndex:0];
Glyph = [Font glyphForName:"A"];
Layer = [Glyph layerForKey:[FontMaster id]];
print(Layer);
for( i = 0; i < [[Layer paths] count]; i=i+1) {
print("Path: "+i);
Path = [Layer pathAtIndex:i];
for(j = 0; j < [[Path nodes] count]; j=j+1) {
Node = [Path nodes][j];
print("Node["+j+"] {"+[Node position].x+", "+[Node position].y+"}");
}
}
Font = [doc font];
FontMaster = [Font fontMasterAtIndex:0];
Glyph = [Font glyphForName:"A"];
Layer = [Glyph layerForKey:[FontMaster id]];
print(Layer);
for( i = 0; i < [[Layer paths] count]; i=i+1) {
print("Path: "+i);
Path = [Layer pathAtIndex:i];
for(j = 0; j < [[Path nodes] count]; j=j+1) {
Node = [Path nodes][j];
print("Node["+j+"] {"+[Node position].x+", "+[Node position].y+"}");
}
}
the same in bridged stile:
doc = JSTalk.application_("Glyphs").orderedDocuments()[0];
Font = doc.font();
FontMaster = Font.fontMasters()[0];
Glyph = Font.glyphForName_("A");
Layer = Glyph.layerForKey_(FontMaster.id());
print(Layer);
for( i = 0; i < Layer.paths().length(); i=i+1) {
print("Path: "+i);
Path = Layer.pathAtIndex_(i);
for(j = 0; j < Path.nodes().length(); j=j+1) {
print();
Node = Path.nodes()[j];
Node.position = NSMakePoint(Node.position().x * 0.5, Node.position().y);
print("Node["+j+"] {"+Node.position().x+", "+Node.position().y+"}");
}
}
Font = doc.font();
FontMaster = Font.fontMasters()[0];
Glyph = Font.glyphForName_("A");
Layer = Glyph.layerForKey_(FontMaster.id());
print(Layer);
for( i = 0; i < Layer.paths().length(); i=i+1) {
print("Path: "+i);
Path = Layer.pathAtIndex_(i);
for(j = 0; j < Path.nodes().length(); j=j+1) {
print();
Node = Path.nodes()[j];
Node.position = NSMakePoint(Node.position().x * 0.5, Node.position().y);
print("Node["+j+"] {"+Node.position().x+", "+Node.position().y+"}");
}
}