forked from adobe-type-tools/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuildAll.py
More file actions
executable file
·117 lines (90 loc) · 3.04 KB
/
buildAll.py
File metadata and controls
executable file
·117 lines (90 loc) · 3.04 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/python
import os
import sys
import time
from subprocess import Popen, PIPE
__doc__ = """
buildAll v1.1 - Aug 04 2013
This script takes a path to a folder as input, finds all the Type 1 fonts
(.pfa files) or UFO fonts inside that folder and its subdirectories, and
builds the OpenType (.otf) fonts using the FDK's makeotf tool. If a path is
not provided, the script will use the current path as the top-most directory.
The script ignores MM PFA fonts, usually named 'mmfont.pfa'.
The Type 1 fonts can also be in plain text format (.txt) where the Private
and CharStrings dictionaries are not encrypted. These files can be obtained
by using the FDK's detype1 tool.
==================================================
Versions:
v1.0 - Feb 22 2013 - Initial release
v1.1 - Aug 04 2013 - Added support for UFO files
"""
kFontProjFile = "current.fpr"
kFontTXT = "font.txt"
def getFontPaths(path):
fontsList = []
for r, folders, files in os.walk(os.path.realpath(path)):
fileAndFolderList = folders[:]
fileAndFolderList.extend(files)
for item in fileAndFolderList:
fileName, extension = os.path.splitext(item)
extension = extension.lower()
if extension == ".pfa" and not fileName == "mmfont":
fontsList.append(os.path.join(r, item))
elif extension == ".txt" and fileName == "font":
fontsList.append(os.path.join(r, item))
elif extension == ".ufo":
fontsList.append(os.path.join(r, item))
else:
continue
return fontsList
def doTask(fonts):
totalFonts = len(fonts)
print "%d fonts found\n" % totalFonts
i = 1
for font in fonts:
folderPath, fontFileName = os.path.split(font)
styleName = os.path.basename(folderPath)
# Change current directory to the folder where the font is contained
os.chdir(folderPath)
print '*******************************'
print 'Building %s...(%d/%d)' % (styleName, i, totalFonts)
cmd = 'makeotf -f "%s" -gs -r' % fontFileName # -gs option: only the glyphs listed in the GOADB file will be included in OTF
# cmd = 'makeotf -f "%s" -addn -r' % fontFileName # adds marking notdef glyph
popen = Popen(cmd, shell=True, stdout=PIPE)
popenout, popenerr = popen.communicate()
if popenout:
print popenout
if popenerr:
print popenerr
i += 1
# Delete project file
if os.path.exists(kFontProjFile):
os.remove(kFontProjFile)
def run():
# if a path is provided
if len(sys.argv[1:]):
baseFolderPath = sys.argv[1]
if baseFolderPath[-1] == '/': # remove last slash if present
baseFolderPath = baseFolderPath[:-1]
# make sure the path is valid
if not os.path.isdir(baseFolderPath):
print 'Invalid directory.'
return
# if a path is not provided, use the current directory
else:
baseFolderPath = os.getcwd()
t1 = time.time()
fontsList = getFontPaths(baseFolderPath)
if len(fontsList):
doTask(fontsList)
else:
print "No fonts found"
return
t2 = time.time()
elapsedSeconds = t2-t1
if (elapsedSeconds/60) < 1:
print 'Completed in %.1f seconds.' % elapsedSeconds
else:
print 'Completed in %.1f minutes.' % (elapsedSeconds/60)
if __name__=='__main__':
run()