rewrite generator script to do sfd -> ttf conversions, allowing manual sfd edits
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
diff --git a/convert.py b/convert.py
index 1a85bb4..a31a4f8 100755
--- a/convert.py
+++ b/convert.py
@@ -3,101 +3,34 @@
import fontforge
import os
-from datetime import datetime
-
-now = datetime.now()
-os.environ['SOURCE_DATE_EPOCH'] = now.strftime('%s')
-if os.environ['USER'] == 'dembry' or os.environ['USER'] == 'dse':
- os.environ['USER'] = 'Darren Embry'
-
-MACSTYLE_BOLD = 1
-MACSTYLE_ITALIC = 2
-MACSTYLE_UNDERLINE = 4
-MACSTYLE_OUTLINE = 8
-MACSTYLE_SHADOW = 16
-MACSTYLE_CONDENSED = 32
-MACSTYLE_EXTENDED = 64
-
-extensions = ['ttf', 'otf', 'svg', 'woff', 'woff2']
-
-def roman():
- print('==> sources/cour.pfa <==')
- font = fontforge.open('sources/cour.pfa')
- font.fontname = 'IBMCourier'
- font.fullname = 'IBM Courier'
- font.familyname = 'IBM Courier'
- font.italicangle = 0.0
- font.weight = 'Book'
-
- print("{}".format(font.sfnt_names))
- font.sfnt_names = (
- ('English (US)', 'Family', 'IBM Courier'),
- ('English (US)', 'SubFamily', 'Regular'),
- ('English (US)', 'Fullname', 'IBM Courier'),
- ('English (US)', 'PostScriptName', 'IBMCourier'),
- ) + font.sfnt_names
- print("{}".format(font.sfnt_names))
-
- font.save('sfd/IBM-Courier.sfd')
- for extension in extensions:
- font.generate('fonts/IBM-Courier.' + extension)
-def bold():
- print('==> sources/courb.pfa <==')
- font = fontforge.open('sources/courb.pfa')
- font.fontname = 'IBMCourier-Bold'
- font.fullname = 'IBM Courier Bold'
- font.familyname = 'IBM Courier'
- font.italicangle = 0.0
-
- font.sfnt_names = (
- ('English (US)', 'Family', 'IBM Courier'),
- ('English (US)', 'SubFamily', 'Bold'),
- ('English (US)', 'Fullname', 'IBM Courier Bold'),
- ('English (US)', 'PostScriptName', 'IBMCourier-Bold'),
- ) + font.sfnt_names
-
- font.save('sfd/IBM-Courier-Bold.sfd')
- for extension in extensions:
- font.generate('fonts/IBM-Courier-Bold.' + extension)
-def italic():
- print('==> sources/couri.pfa <==')
- font = fontforge.open('sources/couri.pfa')
- font.fontname = 'IBMCourier-Italic'
- font.fullname = 'IBM Courier Italic'
- font.familyname = 'IBM Courier'
- font.italicangle = -12.0
- font.weight = 'Book'
-
- font.sfnt_names = (
- ('English (US)', 'Family', 'IBM Courier'),
- ('English (US)', 'SubFamily', 'Italic'),
- ('English (US)', 'Fullname', 'IBM Courier Italic'),
- ('English (US)', 'PostScriptName', 'IBMCourier-Italic'),
- ) + font.sfnt_names
-
- font.save('sfd/IBM-Courier-Italic.sfd')
- for extension in extensions:
- font.generate('fonts/IBM-Courier-Italic.' + extension)
-def boldItalic():
- print('==> sources/courbi.pfa <==')
- font = fontforge.open('sources/courbi.pfa')
- font.fontname = 'IBMCourier-BoldItalic'
- font.fullname = 'IBM Courier Bold Italic'
- font.familyname = 'IBM Courier'
- font.italicangle = -12.0
-
- font.sfnt_names = (
- ('English (US)', 'Family', 'IBM Courier'),
- ('English (US)', 'SubFamily', 'Bold Italic'),
- ('English (US)', 'Fullname', 'IBM Courier Bold Italic'),
- ('English (US)', 'PostScriptName', 'IBMCourier-BoldItalic'),
- ) + font.sfnt_names
-
- font.save('sfd/IBM-Courier-Bold-Italic.sfd')
- for extension in extensions:
- font.generate('fonts/IBM-Courier-Bold-Italic.' + extension)
-
-roman()
-bold()
-italic()
-boldItalic()
+import re
+import string
+
+def convert(source, dests):
+ 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
+
+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"])