-
Notifications
You must be signed in to change notification settings - Fork 52
/
generateSingleMarkFiles.py
106 lines (80 loc) · 2.71 KB
/
generateSingleMarkFiles.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
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
#!/usr/bin/env 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 ImportError:
print(
"ERROR: This script requires defcon. "
"It can be downloaded from https://github.com/typesupply/defcon")
libraryNotFound = True
try:
import WriteFeaturesMarkFDK
except ImportError:
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()
def generateMarkFiles(font):
folderPath, fontFileName = os.path.split(font)
# path to the folder where the font is contained and the font's file name
os.chdir(folderPath)
ufoFont = Font(fontFileName)
styleName = ufoFont.info.styleName
print('*******************************')
print('Exporting mark files for %s...' % (styleName))
WriteFeaturesMarkFDK.MarkDataClass(
ufoFont, folderPath, trimCasingTags,
genMkmkFeature, writeClassesFile, indianScriptsFormat
)
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()
fontPath = os.path.abspath(sys.argv[-1])
print(fontPath)
if os.path.exists(fontPath) and fontPath.lower().endswith('.ufo'):
generateMarkFiles(fontPath)
else:
print("No fonts found")
return
t2 = time.time()
elapsedSeconds = t2 - t1
elapsedMinutes = elapsedSeconds / 60
if elapsedMinutes < 1:
print(('Completed in %.1f seconds.' % elapsedSeconds))
else:
print(('Completed in %.1f minutes.' % elapsedMinutes))
if __name__ == '__main__':
run()