Write documentation of script.py
[pyff3.git] / script.py
blob9cce21a7ed8f6898f91494cf20fcf7a980d8f3e3
1 #!/usr/bin/env python
3 from optparse import OptionParser
4 import os
6 import lib
8 def handle_options(my_options):
9 """Process optparse options with the InterpolateFonts class in mind.
11 One flag is passed directly from the command line to my_options.
13 The x, y, z flags correspond to the `parameter' attribute of the
14 InterpolateFonts class, cf its docstring
16 http://fontforge.sourceforge.net/elementmenu.html#Interpolate
17 Examples: If you are interpolating from a light font to a bold one, then a
18 medium font might be 50% between the two, an extra-bold font might be 200%
19 and a thin one -100%.
21 """
22 if my_options.x:
23 my_parameter = "x"
24 elif my_options.y:
25 my_parameter = "y"
26 elif my_options.z:
27 my_parameter = "z"
29 return my_parameter
31 if __name__ == "__main__":
33 usage = "%prog [-xyz] -o number font_path1 font_path2"
34 epi = """Interpolate between two font paths and generate a number of ttf
35 files along the way. For permutations, the font paths may be directories.
36 Fontforge defines three types of interpolation. We call them x, y, and z. This
37 software produces crashes, freezes, segmentation faults and fonts."""
39 gui = OptionParser(usage, epilog=epi)
40 gui.add_option("-o", "--output", action="store", type="int",
41 dest="output_files", help="positive integer related to amount of font production")
42 gui.add_option("-x", action="store_true", dest="x", help="interpolation 100%")
43 gui.add_option("-y", action="store_true", dest="y", help="interpolation -100%")
44 gui.add_option("-z", action="store_true", dest="z", help="interpolation 200%")
45 (options, paths) = gui.parse_args()
47 a_parameter = handle_options(options)
49 wrap_interpolation_paths = lib.InterpolationPathsWrapper(paths[0], paths[1], a_parameter, options.output_files)
50 wrap_interpolation_paths.interpolate()