Skip to content

Commit 92dc099

Browse files
committed
Simplify fontsList function.
1 parent d48eaaf commit 92dc099

6 files changed

Lines changed: 166 additions & 130 deletions

File tree

buildAll.py

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
#!/usr/bin/python
22

3-
__copyright__ = __license__ = """
3+
import os
4+
import sys
5+
import time
6+
from subprocess import Popen, PIPE
7+
8+
__copyright__ = __license__ = """
49
Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
5-
10+
611
Permission is hereby granted, free of charge, to any person obtaining a
7-
copy of this software and associated documentation files (the "Software"),
8-
to deal in the Software without restriction, including without limitation
9-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10-
and/or sell copies of the Software, and to permit persons to whom the
12+
copy of this software and associated documentation files (the "Software"),
13+
to deal in the Software without restriction, including without limitation
14+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
15+
and/or sell copies of the Software, and to permit persons to whom the
1116
Software is furnished to do so, subject to the following conditions:
12-
17+
1318
The above copyright notice and this permission notice shall be included in
1419
all copies or substantial portions of the Software.
15-
20+
1621
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1823
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2227
DEALINGS IN THE SOFTWARE.
2328
"""
2429

2530
__doc__ = """
2631
buildAll v1.1 - Aug 04 2013
2732
2833
This script takes a path to a folder as input, finds all the Type 1 fonts
29-
(.pfa files) or UFO fonts inside that folder and its subdirectories, and
30-
builds the OpenType (.otf) fonts using the FDK's makeotf tool. If a path is
34+
(.pfa files) or UFO fonts inside that folder and its subdirectories, and
35+
builds the OpenType (.otf) fonts using the FDK's makeotf tool. If a path is
3136
not provided, the script will use the current path as the top-most directory.
3237
The script ignores MM PFA fonts, usually named 'mmfont.pfa'.
33-
The Type 1 fonts can also be in plain text format (.txt) where the Private
38+
The Type 1 fonts can also be in plain text format (.txt) where the Private
3439
and CharStrings dictionaries are not encrypted. These files can be obtained
3540
by using the FDK's detype1 tool.
3641
@@ -40,23 +45,29 @@
4045
v1.1 - Aug 04 2013 - Added support for UFO files
4146
"""
4247

43-
import sys, os, time
44-
from subprocess import Popen, PIPE
45-
4648
kFontProjFile = "current.fpr"
4749
kFontTXT = "font.txt"
4850

49-
fontsList = []
50-
5151

5252
def getFontPaths(path):
53+
fontsList = []
5354
for r, folders, files in os.walk(path):
5455
fileAndFolderList = folders[:]
5556
fileAndFolderList.extend(files)
56-
57+
5758
for item in fileAndFolderList:
58-
if (item[-4:].lower() in [".pfa"] and item not in ["mmfont.pfa"]) or (item in [kFontTXT]) or (item[-4:].lower() in [".ufo"]):
59+
fileName, extension = os.path.splitext(item)
60+
extension = extension.lower()
61+
if extension == ".pfa" and not fileName == "mmfont":
62+
fontsList.append(os.path.join(r, item))
63+
elif extension == ".txt" and fileName == "font":
5964
fontsList.append(os.path.join(r, item))
65+
elif extension == ".ufo":
66+
fontsList.append(os.path.join(r, item))
67+
else:
68+
continue
69+
70+
return fontsList
6071

6172

6273
def doTask(fonts):
@@ -65,16 +76,16 @@ def doTask(fonts):
6576
i = 1
6677

6778
for font in fonts:
68-
folderPath, fontFileName = os.path.split(font) # path to the folder where the font is contained and the font's file name
69-
styleName = os.path.basename(folderPath) # name of the folder where the font is contained
79+
folderPath, fontFileName = os.path.split(font)
80+
styleName = os.path.basename(folderPath)
7081

7182
# Change current directory to the folder where the font is contained
7283
os.chdir(folderPath)
7384

7485
print '*******************************'
7586
print 'Building %s...(%d/%d)' % (styleName, i, totalFonts)
7687
cmd = 'makeotf -f "%s" -gs -r' % fontFileName # -gs option: only the glyphs listed in the GOADB file will be included in OTF
77-
# cmd = 'makeotf -f "%s" -addn -r' % fontFileName # adds marking notdef glyph
88+
# cmd = 'makeotf -f "%s" -addn -r' % fontFileName # adds marking notdef glyph
7889
popen = Popen(cmd, shell=True, stdout=PIPE)
7990
popenout, popenerr = popen.communicate()
8091
if popenout:
@@ -106,9 +117,8 @@ def run():
106117
baseFolderPath = os.getcwd()
107118

108119
t1 = time.time()
120+
fontsList = getFontPaths(baseFolderPath)
109121

110-
getFontPaths(baseFolderPath)
111-
112122
if len(fontsList):
113123
doTask(fontsList)
114124
else:
@@ -117,7 +127,7 @@ def run():
117127

118128
t2 = time.time()
119129
elapsedSeconds = t2-t1
120-
130+
121131
if (elapsedSeconds/60) < 1:
122132
print 'Completed in %.1f seconds.' % elapsedSeconds
123133
else:

checkAll.py

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,41 @@
11
#!/usr/bin/python
22

3-
__copyright__ = __license__ = """
3+
import os
4+
import sys
5+
import time
6+
from subprocess import Popen, PIPE
7+
8+
__copyright__ = __license__ = """
49
Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
5-
10+
611
Permission is hereby granted, free of charge, to any person obtaining a
7-
copy of this software and associated documentation files (the "Software"),
8-
to deal in the Software without restriction, including without limitation
9-
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10-
and/or sell copies of the Software, and to permit persons to whom the
12+
copy of this software and associated documentation files (the "Software"),
13+
to deal in the Software without restriction, including without limitation
14+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
15+
and/or sell copies of the Software, and to permit persons to whom the
1116
Software is furnished to do so, subject to the following conditions:
12-
17+
1318
The above copyright notice and this permission notice shall be included in
1419
all copies or substantial portions of the Software.
15-
20+
1621
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1823
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2227
DEALINGS IN THE SOFTWARE.
2328
"""
2429

2530
__doc__ = """
2631
checkAll v1.1 - Aug 04 2013
2732
2833
This script takes a path to a folder as input, finds all the Type 1 fonts
29-
(.pfa files) or UFO fonts inside that folder and its subdirectories, and
30-
removes their overlaps using the FDK's checkOutlines tool. If a path is not
34+
(.pfa files) or UFO fonts inside that folder and its subdirectories, and
35+
removes their overlaps using the FDK's checkOutlines tool. If a path is not
3136
provided, the script will use the current path as the top-most directory.
3237
The script ignores MM PFA fonts, usually named 'mmfont.pfa'.
33-
The Type 1 fonts can also be in plain text format (.txt) where the Private
38+
The Type 1 fonts can also be in plain text format (.txt) where the Private
3439
and CharStrings dictionaries are not encrypted. These files can be obtained
3540
by using the FDK's detype1 tool.
3641
@@ -40,23 +45,29 @@
4045
v1.1 - Aug 04 2013 - Added support for UFO files
4146
"""
4247

43-
import sys, os, time
44-
from subprocess import Popen, PIPE
45-
4648
kFontTXT = "font.txt"
4749
kTempPFA = "font_TEMP_.pfa"
4850

49-
fontsList = []
50-
5151

5252
def getFontPaths(path):
53+
fontsList = []
5354
for r, folders, files in os.walk(path):
5455
fileAndFolderList = folders[:]
5556
fileAndFolderList.extend(files)
56-
57+
5758
for item in fileAndFolderList:
58-
if (item[-4:].lower() in [".pfa"] and item not in ["mmfont.pfa"]) or (item in [kFontTXT]) or (item[-4:].lower() in [".ufo"]):
59+
fileName, extension = os.path.splitext(item)
60+
extension = extension.lower()
61+
if extension == ".pfa" and not fileName == "mmfont":
62+
fontsList.append(os.path.join(r, item))
63+
elif extension == ".txt" and fileName == "font":
5964
fontsList.append(os.path.join(r, item))
65+
elif extension == ".ufo":
66+
fontsList.append(os.path.join(r, item))
67+
else:
68+
continue
69+
70+
return fontsList
6071

6172

6273
def doTask(fonts):
@@ -65,12 +76,12 @@ def doTask(fonts):
6576
i = 1
6677

6778
for font in fonts:
68-
folderPath, fontFileName = os.path.split(font) # path to the folder where the font is contained and the font's file name
69-
styleName = os.path.basename(folderPath) # name of the folder where the font is contained
79+
folderPath, fontFileName = os.path.split(font)
80+
styleName = os.path.basename(folderPath)
7081

7182
# Change current directory to the folder where the font is contained
7283
os.chdir(folderPath)
73-
84+
7485
# If it's a txt font, convert it to pfa temporarily
7586
fontIsTXT = False
7687
if fontFileName == kFontTXT:
@@ -104,7 +115,7 @@ def doTask(fonts):
104115
print popenout
105116
if popenerr:
106117
print popenerr
107-
118+
108119
if os.path.exists(kTempPFA):
109120
os.remove(kTempPFA)
110121

@@ -127,9 +138,8 @@ def run():
127138
baseFolderPath = os.getcwd()
128139

129140
t1 = time.time()
141+
fontsList = getFontPaths(baseFolderPath)
130142

131-
getFontPaths(baseFolderPath)
132-
133143
if len(fontsList):
134144
doTask(fontsList)
135145
else:
@@ -138,7 +148,7 @@ def run():
138148

139149
t2 = time.time()
140150
elapsedSeconds = t2-t1
141-
151+
142152
if (elapsedSeconds/60) < 1:
143153
print 'Completed in %.1f seconds.' % elapsedSeconds
144154
else:

0 commit comments

Comments
 (0)