Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
From UFO Robofab to Drawbot context
### Module
from robofab.world import OpenFont
### Functions
def drawCon(con):
bezierPath = BezierPath()
# Iteration over segments
for seg in con:
if seg.type == 'move':
x1 = seg.points[0].x
y1 = seg.points[0].y
bezierPath.moveTo((x1, y1))
elif seg.type == 'line':
x1 = seg.points[0].x
y1 = seg.points[0].y
bezierPath.lineTo((x1, y1 ))
elif seg.type == 'curve':
x1 = seg.points[0].x
y1 = seg.points[0].y
x2 = seg.points[1].x
y2 = seg.points[1].y
x3 = seg.points[2].x
y3 = seg.points[2].y
bezierPath.curveTo((x1, y1), (x2, y2), (x3, y3))
bezierPath.closePath()
drawPath(bezierPath)
def drawGlyph(glyph):
counterclockwise = []
clockwise = []
for con in glyph:
if con.clockwise == 1:
clockwise.append(con.index)
else:
counterclockwise.append(con.index)
# Iterating over counterclockwise contours
for con_index in counterclockwise:
con = glyph[con_index]
if con.clockwise == 1:
fill(255)
else:
fill(0)
drawCon(con)
# Iterating over clockwise contours
for con_index in clockwise:
con = glyph[con_index]
if con.clockwise == 1:
fill(255)
elif con.clockwise == 0:
fill(0)
drawCon(con)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment