|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 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 | +# ---------------------------------------------- |
| 13 | + |
| 14 | +libraryNotFound = False |
| 15 | + |
| 16 | +import sys, os, time |
| 17 | +try: |
| 18 | + from defcon import Font |
| 19 | +except: |
| 20 | + print "ERROR: This script requires defcon. It can be downloaded from https://github.com/typesupply/defcon" |
| 21 | + libraryNotFound = True |
| 22 | +try: |
| 23 | + import WriteFeaturesMarkFDK |
| 24 | +except: |
| 25 | + print "ERROR: This script requires WriteFeaturesMarkFDK.py. It can be downloaded from https://github.com/adobe-type-tools/python-modules" |
| 26 | + libraryNotFound = True |
| 27 | + |
| 28 | +if libraryNotFound: |
| 29 | + sys.exit() |
| 30 | + |
| 31 | +fontsList = [] |
| 32 | + |
| 33 | +def getFontPaths(path, startpath): |
| 34 | +# print "Searching in path...", path |
| 35 | + files = os.listdir(path) |
| 36 | + for file in files: |
| 37 | + if file[-4:].lower() in [".ufo"]: |
| 38 | + fontsList.append(os.path.join(path, file)) #[len(startpath)+1:]) |
| 39 | + else: |
| 40 | + if os.path.isdir(os.path.join(path, file)): |
| 41 | + getFontPaths(os.path.join(path, file), startpath) |
| 42 | + |
| 43 | + |
| 44 | +def doTask(fonts): |
| 45 | + totalFonts = len(fonts) |
| 46 | + print "%d fonts found\n" % totalFonts |
| 47 | + i = 0 |
| 48 | + |
| 49 | + for font in fonts: |
| 50 | + i += 1 |
| 51 | + folderPath, fontFileName = os.path.split(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 |
| 53 | + |
| 54 | + # Change current directory to the folder where the font is contained |
| 55 | + os.chdir(folderPath) |
| 56 | + |
| 57 | + print '*******************************' |
| 58 | + print 'Exporting mark files for %s...(%d/%d)' % (styleName, i, totalFonts) |
| 59 | + |
| 60 | + ufoFont = Font(fontFileName) |
| 61 | + WriteFeaturesMarkFDK.MarkDataClass(ufoFont, folderPath, trimCasingTags, genMkmkFeature, writeClassesFile, indianScriptsFormat) |
| 62 | + |
| 63 | + |
| 64 | +def run(): |
| 65 | + # if a path is provided |
| 66 | + if len(sys.argv[1:]): |
| 67 | + baseFolderPath = sys.argv[1] |
| 68 | + |
| 69 | + if baseFolderPath[-1] == '/': # remove last slash if present |
| 70 | + baseFolderPath = baseFolderPath[:-1] |
| 71 | + |
| 72 | + # make sure the path is valid |
| 73 | + if not os.path.isdir(baseFolderPath): |
| 74 | + print 'Invalid directory.' |
| 75 | + return |
| 76 | + |
| 77 | + # if a path is not provided, use the current directory |
| 78 | + else: |
| 79 | + baseFolderPath = os.getcwd() |
| 80 | + |
| 81 | + t1 = time.time() |
| 82 | + |
| 83 | + getFontPaths(baseFolderPath, baseFolderPath) |
| 84 | + |
| 85 | + if len(fontsList): |
| 86 | + doTask(fontsList) |
| 87 | + else: |
| 88 | + print "No fonts found" |
| 89 | + return |
| 90 | + |
| 91 | + t2 = time.time() |
| 92 | + elapsedSeconds = t2-t1 |
| 93 | + |
| 94 | + if (elapsedSeconds/60) < 1: |
| 95 | + print 'Completed in %.1f seconds.' % elapsedSeconds |
| 96 | + else: |
| 97 | + print 'Completed in %.1f minutes.' % (elapsedSeconds/60) |
| 98 | + |
| 99 | + |
| 100 | +if __name__=='__main__': |
| 101 | + run() |
0 commit comments