Last active
August 29, 2015 14:01
-
-
Save roberto-arista/8065cd851307ff79beb3 to your computer and use it in GitHub Desktop.
From UFO Robofab to Drawbot context
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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