How important is it for you to do it with RoboFab? I can tell you how to do it with the plain vanilla Python API:
#MenuTitle: Drawing Sample
# -*- coding: utf-8 -*-
__doc__="""
Draw a sample path.
"""
from GlyphApp import GSLINE, GSCURVE, GSOFFCURVE
thisFont = Glyphs.font
thisLayer = thisFont.selectedLayers[0]
def addLineToPath( path, point ):
newNode = GSNode()
newNode.type = GSLINE
newNode.position = point
path.nodes.append(newNode)
def addCurveToPath( path, threePoints ):
for i, point in enumerate( threePoints ):
newNode = GSNode()
if i == 2:
newNode.type = GSCURVE
else:
newNode.type = GSOFFCURVE
newNode.position = point
path.nodes.append(newNode)
def addSegmentsToPath( path, segments ):
for segment in segments:
if len(segment) == 1:
point = NSPoint( segment[0][0], segment[0][1] )
addLineToPath( path, point )
elif len(segment) == 3:
points = (
NSPoint( segment[0][0], segment[0][1] ),
NSPoint( segment[1][0], segment[1][1] ),
NSPoint( segment[2][0], segment[2][1] )
)
addCurveToPath( path, points )
newPath = GSPath()
addSegmentsToPath(
newPath,
( (800, 100) ),
( (1000, 300), (1000, 600), (800, 800) ),
( (100, 800) ),
( (100, 100) )
)
newPath.close = True
thisLayer.paths.append(newPath)
Sorry to overcomplicate things a bit, but I could not resist abstracting into functions straight away.
Basically you create a GSNode
, set its type to one of GSLINE
, GSCURVE
, or GSOFFCURVE
, and set its position to an NSPoint
. Then you append that node to a path’s nodes
property, e.g., mypath.nodes.append(mynode)
. Eventually you set the path’s closed
property to True
and append the path to a layer’s paths
property.