Commit a01eebca604af6c4e52b030bcb0e5309243c9a53

Darren Embry 2023-11-17T21:12:16

rewrite to just do one font conversion.

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)