Skip to content

Commit d48eaaf

Browse files
committed
Fix a bug so it is possible to pass folders (other than the current folder) as an argument.
Reformatting work.
1 parent 72394d2 commit d48eaaf

2 files changed

Lines changed: 94 additions & 60 deletions

File tree

generateAllKernFiles.py

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

3-
###################################################
4-
### THE VALUES BELOW CAN BE EDITED AS NEEDED ######
5-
###################################################
6-
7-
minKern = 3 # inclusive; this means that pairs which EQUAL this ABSOLUTE value will NOT be ignored/trimmed. Anything below WILL.
8-
writeTrimmed = False # If 'False', trimmed pairs will not be processed and, therefore, will not be written to the kerning feature file.
9-
writeSubtables = True # Sometimes the kerning feature file needs to have explicit subtable breaks, otherwise the OTF won't compile due to a subtable overflow.
10-
11-
###################################################
12-
13-
__copyright__ = __license__ = """
3+
import os
4+
import sys
5+
import time
6+
7+
############################################
8+
# THE VALUES BELOW CAN BE EDITED AS NEEDED #
9+
############################################
10+
11+
minKern = 3
12+
# This value is inclusive; this means that pairs which EQUAL this ABSOLUTE
13+
# value will NOT be ignored/trimmed. Anything kerning pair that falls below
14+
# will be ignored.
15+
writeTrimmed = False
16+
# If 'False', trimmed pairs will not be processed and therefore will not be
17+
# written to the kerning feature file.
18+
# If 'True', trimmed pairs will be written, but commented out.
19+
writeSubtables = False
20+
# Sometimes the kerning feature file needs to have explicit subtable breaks,
21+
# otherwise the OTF won't compile due to a subtable overflow.
22+
23+
24+
############################################
25+
26+
__copyright__ = __license__ = """
1427
Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
1528
1629
Permission is hereby granted, free of charge, to any person obtaining a
@@ -29,21 +42,19 @@
2942
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3043
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3144
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32-
DEALINGS IN THE SOFTWARE.
33-
"""
45+
DEALINGS IN THE SOFTWARE."""
3446

35-
__doc__ = """
36-
This script takes a path to a folder as input, finds all the UFOs inside that folder
37-
and its subdirectories, and outputs each font's kerning in feature file syntax.
38-
If a path is not provided, the script uses the current path as the top-most directory.
39-
The name of the resulting kerning FEA file is managed by the WriteFeaturesKernFDK module.
40-
"""
47+
__doc__ = """ This script takes a path to a folder as input, finds all
48+
the UFOs inside that folder and its subdirectories, and outputs each
49+
font's kerning in feature file syntax. If a path is not provided, the
50+
script uses the current path as the top-most directory. The name of
51+
the resulting kerning FEA file is managed by the WriteFeaturesKernFDK
52+
module. """
4153

4254
# ----------------------------------------------
4355

4456
libraryNotFound = False
4557

46-
import sys, os, time
4758
try:
4859
from defcon import Font
4960
except:
@@ -60,44 +71,51 @@
6071

6172
fontsList = []
6273

74+
6375
def getFontPaths(path, startpath):
64-
# print "Searching in path...", path
6576
files = os.listdir(path)
6677
for file in files:
6778
if file[-4:].lower() in [".ufo"]:
68-
fontsList.append(os.path.join(path, file)) #[len(startpath)+1:])
79+
fontsList.append(os.path.join(path, file))
6980
else:
7081
if os.path.isdir(os.path.join(path, file)):
7182
getFontPaths(os.path.join(path, file), startpath)
7283

7384

74-
def doTask(fonts):
85+
def doTask(fonts, startpath):
7586
totalFonts = len(fonts)
7687
print "%d fonts found\n" % totalFonts
7788
i = 0
7889

7990
for font in fonts:
8091
i += 1
81-
folderPath, fontFileName = os.path.split(os.path.realpath(font)) # path to the folder where the font is contained and the font's file name
82-
styleName = os.path.basename(folderPath) # name of the folder where the font is contained
92+
folderPath, fontFileName = os.path.split(font)
93+
# path to the folder where the font is contained and the font's file name
94+
styleName = os.path.basename(folderPath)
95+
folderPath = os.path.abspath(folderPath)
96+
# name of the folder where the font is contained
8397

8498
# Change current directory to the folder where the font is contained
8599
os.chdir(folderPath)
86100

87-
print '*******************************'
88-
print 'Kerning for %s...(%d/%d)' % (styleName, i, totalFonts)
101+
exportMessage = 'Exporting kern files for %s...(%d/%d)' % (
102+
styleName, i, totalFonts)
103+
print '*' * len(exportMessage)
104+
print exportMessage
89105

90106
ufoFont = Font(fontFileName)
91-
WriteFeaturesKernFDK.KernDataClass(ufoFont, folderPath, minKern, writeTrimmed, writeSubtables)
107+
WriteFeaturesKernFDK.KernDataClass(
108+
ufoFont, folderPath, minKern,
109+
writeTrimmed, writeSubtables
110+
)
111+
112+
os.chdir(startpath)
92113

93114

94115
def run():
95116
# if a path is provided
96117
if len(sys.argv[1:]):
97-
baseFolderPath = sys.argv[1]
98-
99-
if baseFolderPath[-1] == '/': # remove last slash if present
100-
baseFolderPath = baseFolderPath[:-1]
118+
baseFolderPath = os.path.normpath(sys.argv[1])
101119

102120
# make sure the path is valid
103121
if not os.path.isdir(baseFolderPath):
@@ -109,11 +127,10 @@ def run():
109127
baseFolderPath = os.getcwd()
110128

111129
t1 = time.time()
112-
113130
getFontPaths(baseFolderPath, baseFolderPath)
114-
131+
startpath = os.path.abspath(os.path.curdir)
115132
if len(fontsList):
116-
doTask(fontsList)
133+
doTask(fontsList, startpath)
117134
else:
118135
print "No fonts found"
119136
return

generateAllMarkFiles.py

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
#!/usr/bin/python
22

3-
###################################################
4-
### THE VALUES BELOW CAN BE EDITED AS NEEDED ######
5-
###################################################
6-
7-
writeClassesFile = True # TRUE: Writes mark classes to external file. FALSE: Writes mark classes as part of mark.fea file.
8-
genMkmkFeature = True # TRUE: Writes mkmk.fea file. FALSE: Ignores mark-to-mark placement.
9-
indianScriptsFormat = True # TRUE: Writes abvm.fea and blwm.fea files. FALSE: Writes simple mark.fea file.
10-
trimCasingTags = True # TRUE: Trims casing tags so that all marks can be applied to UC/LC. FALSE: Leaves casing tags as is.
11-
12-
# ----------------------------------------------
3+
import os
4+
import sys
5+
import time
6+
7+
############################################
8+
# THE VALUES BELOW CAN BE EDITED AS NEEDED #
9+
############################################
10+
11+
writeClassesFile = True
12+
# TRUE: Writes mark classes to external file.
13+
# FALSE: Writes mark classes as part of mark.fea file.
14+
genMkmkFeature = True
15+
# TRUE: Writes mkmk.fea file.
16+
# FALSE: Ignores mark-to-mark placement.
17+
indianScriptsFormat = True
18+
# TRUE: Writes abvm.fea and blwm.fea files.
19+
# FALSE: Writes simple mark.fea file.
20+
trimCasingTags = True
21+
# TRUE: Trims casing tags so that all marks can be applied to UC/LC.
22+
# FALSE: Leaves casing tags as is.
23+
24+
# ------------------------------------------
1325

1426
libraryNotFound = False
1527

16-
import sys, os, time
1728
try:
1829
from defcon import Font
1930
except:
@@ -30,44 +41,48 @@
3041

3142
fontsList = []
3243

44+
3345
def getFontPaths(path, startpath):
34-
# print "Searching in path...", path
3546
files = os.listdir(path)
3647
for file in files:
3748
if file[-4:].lower() in [".ufo"]:
38-
fontsList.append(os.path.join(path, file)) #[len(startpath)+1:])
49+
fontsList.append(os.path.join(path, file))
3950
else:
4051
if os.path.isdir(os.path.join(path, file)):
4152
getFontPaths(os.path.join(path, file), startpath)
4253

4354

44-
def doTask(fonts):
55+
def doTask(fonts, startpath):
4556
totalFonts = len(fonts)
4657
print "%d fonts found\n" % totalFonts
4758
i = 0
4859

4960
for font in fonts:
5061
i += 1
51-
folderPath, fontFileName = os.path.split(os.path.realpath(font)) # path to the folder where the font is contained and the font's file name
52-
styleName = os.path.basename(folderPath) # name of the folder where the font is contained
62+
folderPath, fontFileName = os.path.split(os.path.realpath(font))
63+
styleName = os.path.basename(folderPath)
5364

5465
# Change current directory to the folder where the font is contained
5566
os.chdir(folderPath)
56-
57-
print '*******************************'
58-
print 'Exporting mark files for %s...(%d/%d)' % (styleName, i, totalFonts)
67+
exportMessage = 'Exporting mark files for %s...(%d/%d)' % (
68+
styleName, i, totalFonts)
69+
print '*' * len(exportMessage)
70+
print exportMessage
5971

6072
ufoFont = Font(fontFileName)
61-
WriteFeaturesMarkFDK.MarkDataClass(ufoFont, folderPath, trimCasingTags, genMkmkFeature, writeClassesFile, indianScriptsFormat)
73+
WriteFeaturesMarkFDK.MarkDataClass(
74+
ufoFont, folderPath, trimCasingTags,
75+
genMkmkFeature, writeClassesFile,
76+
indianScriptsFormat
77+
)
78+
# go back to the start
79+
os.chdir(startpath)
6280

6381

6482
def run():
6583
# if a path is provided
6684
if len(sys.argv[1:]):
67-
baseFolderPath = sys.argv[1]
68-
69-
if baseFolderPath[-1] == '/': # remove last slash if present
70-
baseFolderPath = baseFolderPath[:-1]
85+
baseFolderPath = os.path.normpath(sys.argv[1])
7186

7287
# make sure the path is valid
7388
if not os.path.isdir(baseFolderPath):
@@ -82,8 +97,10 @@ def run():
8297

8398
getFontPaths(baseFolderPath, baseFolderPath)
8499

100+
# the path from which the script is executed
101+
startpath = os.path.abspath(os.path.curdir)
85102
if len(fontsList):
86-
doTask(fontsList)
103+
doTask(fontsList, startpath)
87104
else:
88105
print "No fonts found"
89106
return

0 commit comments

Comments
 (0)