#(re-type.com) Generate and execute the code to batch process a bunch of fonts with TTFAutohint #IMPORTANT: You must name your fonts this way: fontname-weight.ttf import os font_name = raw_input("Write the font name: ") font_family = [] number_of_weights = int(raw_input("Write the number of weights: ")) while True: weight = raw_input ("Enter the name of your font weights one by one: ") font_family.append(weight) if len(font_family) == number_of_weights: break input_directory = raw_input("Write the directory where your input fonts are located: ") for n in font_family: run_ttfautohint = "ttfautohint -v -f latn -n -w gGD "+input_directory+font_name+"-"+n+".ttf"+" "+input_directory+font_name+"-"+n+"-HINTED"+".ttf" os.system(run_ttfautohint)
Comments
1. Copy-paste the code in a text editor.
2. Save the file with a .py suffix.
3. Open Terminal
4. Type "python" and DO NOT press "Enter".
5. Drop the .py file on the Terminal window and press "Enter".
6. Follow the instructions of the program. The new hinted files should show up in the same directory with the word "HINTED" added to their names.
TIP: You can easily get the exact directory where your input files are located by dropping one of the files in a new Terminal window.
TIP2: It is very easy to find the TTFAutohint parameters in the code (just in case: line 17). You can modify them to fit your needs.
Instead of letting the user input every filename one by one, you could also use the os module in Python to get access to the filesystem. Here is an example of a function that will collect all files with a ‘.ttf’ extension in a pre-defined directory .
- Have the user cd to the directory containing the TTFs before running and rewrite the script to assume that the TTFs are in the current working directory.
- Or, rewrite it so that it assumes the TTFs are in the same folder as the Python script. That way, there's nothing to input and no need to modify in the script. Just copy or move the script to the folder containing the TTFs and run it.
IMHO shell scripts are a very convenient alternative, irrespective the platform. Because reproducibility is a key factor for font production –especially with tools like ttfautohint that are constantly updated– it must be easy to repeat the process. If WOFF, EOT, SVG, and SVGZ have to be generated, subsequently shell scripts can be applied too, of course.
---------------------------------------------------
#!/bin/bash
TTFA -f -i -v /Volumes/FontProduction/TrueType/Web/West/Argo/Base/A057012T.ttf /Volumes/FontProduction/Web/West/TTFA_output/Argo/West/A057012T.ttf
TTFA -f -i -v /Volumes/FontProduction/TrueType/Web/West/Argo/Base/A057013T.ttf /Volumes/FontProduction/Web/West/TTFA_output/Argo/West/A057013T.ttf
et cetera
---------------------------------------------------
For this a fixed directory system makes sense. Because we use an eight-character file-naming system throughout the production (like URW[++] did already in the 1970s) the scripts are easy to duplicate and rename for the different typefaces. At the ATypI 2008 conference in St. Petersburg I gave a brief talk about this and the slides can be found here as PDF. The file-naming part starts at page 65.
For instance:
newRoot = root+"/hinted/"
Would be better written as:
newRoot = os.path.join(root, 'hinted')
format
function and/or%
operator for strings, which would allow thettfautohint
command to be rewritten in a more readable way: Or perhaps more maintainably:getFiles
can be rewritten simply: I've found that this makes my Python a lot more succinct, maintainable, and easy to understand (after I got the syntax). Here's a brief overview for those so inclined: http://carlgroner.me/Python/2011/11/09/An-Introduction-to-List-Comprehensions-in-Python.html