rewrite to just do one font conversion.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/bin/convert.py b/bin/convert.py
index a31a4f8..7a0b65d 100755
--- a/bin/convert.py
+++ b/bin/convert.py
@@ -5,32 +5,21 @@ import fontforge
import os
import re
import string
+import argparse
-def convert(source, dests):
+def convertFont(source, dest):
print("Reading %s" % source)
font = fontforge.open(source)
- lastDest = None
- for dest in dests:
- print("< dest = %s" % dest)
- if re.fullmatch(r'^\.[A-Za-z0-9]+$', dest):
- if lastDest is None:
- raise Exception("first filename cannot be an extension: %s" % dest)
- else:
- dest = os.path.splitext(lastDest)[0] + dest
- print("> dest = %s" % dest)
- if os.path.splitext(dest)[1] == ".sfd":
- print("Writing %s using font.save()" % dest)
- font.save(dest)
- else:
- print("Writing %s using font.generate()" % dest)
- font.generate(dest)
- lastDest = dest
+ if os.path.splitext(dest)[1] == ".sfd":
+ print("Writing %s using font.save()" % dest)
+ font.save(dest)
+ else:
+ print("Writing %s using font.generate()" % dest)
+ font.generate(dest)
-convert("sfd/IBM-Courier-Bold-Italic.sfd", ["fonts/IBM-Courier-Bold-Italic.ttf",
- ".otf", ".svg", ".woff", ".woff2"])
-convert("sfd/IBM-Courier.sfd", ["fonts/IBM-Courier.ttf",
- ".otf", ".svg", ".woff", ".woff2"])
-convert("sfd/IBM-Courier-Italic.sfd", ["fonts/IBM-Courier-Italic.ttf",
- ".otf", ".svg", ".woff", ".woff2"])
-convert("sfd/IBM-Courier-Bold.sfd", ["fonts/IBM-Courier-Bold.ttf",
- ".otf", ".svg", ".woff", ".woff2"])
+parser = argparse.ArgumentParser(prog="convert", description="font converter")
+parser.add_argument("source", help="source font file")
+parser.add_argument("dest", help="destination font file (extension determines format)")
+
+args = parser.parse_args()
+convertFont(args.source, args.dest)