-
Notifications
You must be signed in to change notification settings - Fork 0
/
UFOarchiveMovie.py
73 lines (56 loc) · 1.64 KB
/
UFOarchiveMovie.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# DrawBot script that generate a "flip book" animation from UFOs
saveMovie = True
folders = [
u"/path/to/your/ufo/archive/folder",
#u"/path/to/your/ufo/archive/folder",
]
# you might want to change the layout here
w, h = 500, 600 # width, height
x, y = 250, 150 # xpos, ypos
s = 0.5 # scale, e.g. 0.5 * 1000 UPM = 500 pt
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
def drawFrame(font, glyph):
newPage(w, h)
save()
translate(x, y)
scale(s)
pen = CocoaPen(font)
glyph.draw(pen)
translate(-glyph.width/2, 0)
drawPath(pen.path)
restore()
from fontTools.pens.cocoaPen import CocoaPen
from robofab.world import OpenFont
import os
paths = []
for folder in folders:
for root, dirs, files in os.walk(folder):
for directory in dirs:
if directory.endswith(".ufo"):
paths.append(os.path.join(root, directory))
fonts = []
for path in paths:
font = OpenFont(path)
fonts.append(font)
skipCount = 0
frameCount = 0
for letter in letters:
prevPoints = None
for font in fonts:
if font.has_key(letter):
glyph = font[letter]
else:
continue
points = [(point.x, point.y) for contour in glyph.contours for point in contour.points]
if points != prevPoints and len(points) > 1:
drawFrame(font, glyph)
frameCount+=1
else:
skipCount+=1
prevPoints = points
print "%s fonts" % str(len(fonts))
print "%s frames" % frameCount
print "---"
print "skipped %s identical glyphs" % skipCount
if saveMovie:
saveImage(["~/Desktop/UFOarchive.mov"])