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__ = """
1427Copyright (c) 2014 Adobe Systems Incorporated. All rights reserved.
1528
1629Permission is hereby granted, free of charge, to any person obtaining a
2942AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3043LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3144FROM, 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
4456libraryNotFound = False
4557
46- import sys , os , time
4758try :
4859 from defcon import Font
4960except :
6071
6172fontsList = []
6273
74+
6375def 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
94115def 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
0 commit comments