forked from adobe-type-tools/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateAllMarkFiles.py
More file actions
executable file
·118 lines (92 loc) · 2.85 KB
/
generateAllMarkFiles.py
File metadata and controls
executable file
·118 lines (92 loc) · 2.85 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
118
#!/usr/bin/python
import os
import sys
import time
############################################
# THE VALUES BELOW CAN BE EDITED AS NEEDED #
############################################
writeClassesFile = True
# TRUE: Writes mark classes to external file.
# FALSE: Writes mark classes as part of mark.fea file.
genMkmkFeature = True
# TRUE: Writes mkmk.fea file.
# FALSE: Ignores mark-to-mark placement.
indianScriptsFormat = True
# TRUE: Writes abvm.fea and blwm.fea files.
# FALSE: Writes simple mark.fea file.
trimCasingTags = True
# TRUE: Trims casing tags so that all marks can be applied to UC/LC.
# FALSE: Leaves casing tags as is.
# ------------------------------------------
libraryNotFound = False
try:
from defcon import Font
except:
print "ERROR: This script requires defcon. It can be downloaded from https://github.com/typesupply/defcon"
libraryNotFound = True
try:
import WriteFeaturesMarkFDK
except:
print "ERROR: This script requires WriteFeaturesMarkFDK.py. It can be downloaded from https://github.com/adobe-type-tools/python-modules"
libraryNotFound = True
if libraryNotFound:
sys.exit()
fontsList = []
def getFontPaths(path, startpath):
files = os.listdir(path)
for file in files:
if file[-4:].lower() in [".ufo"]:
fontsList.append(os.path.join(path, file))
else:
if os.path.isdir(os.path.join(path, file)):
getFontPaths(os.path.join(path, file), startpath)
def doTask(fonts, startpath):
totalFonts = len(fonts)
print "%d fonts found\n" % totalFonts
i = 0
for font in fonts:
i += 1
folderPath, fontFileName = os.path.split(os.path.realpath(font))
styleName = os.path.basename(folderPath)
# Change current directory to the folder where the font is contained
os.chdir(folderPath)
exportMessage = 'Exporting mark files for %s...(%d/%d)' % (
styleName, i, totalFonts)
print '*' * len(exportMessage)
print exportMessage
ufoFont = Font(fontFileName)
WriteFeaturesMarkFDK.MarkDataClass(
ufoFont, folderPath, trimCasingTags,
genMkmkFeature, writeClassesFile,
indianScriptsFormat
)
# go back to the start
os.chdir(startpath)
def run():
# if a path is provided
if len(sys.argv[1:]):
baseFolderPath = os.path.normpath(sys.argv[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()
getFontPaths(baseFolderPath, baseFolderPath)
# the path from which the script is executed
startpath = os.path.abspath(os.path.curdir)
if len(fontsList):
doTask(fontsList, startpath)
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()