This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathmakefnt.py
65 lines (44 loc) · 1.68 KB
/
makefnt.py
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
import argparse
import os
import fontforge
from fontTools.ttLib import TTFont
def postProcess(args):
font = TTFont(args.output)
os2 = font["OS/2"]
# FontForge sets this to ord(' ') for OTF fonts, 0 for TTF fonts, we want
# to keep things consistent.
os2.usDefaultChar = 0
# Filter-out useless Macintosh names
font["name"].names = [n for n in font["name"].names if n.platformID != 1]
# https://github.com/fontforge/fontforge/pull/3235
# fontDirectionHint is deprecated and must be set to 2
font["head"].fontDirectionHint = 2
# unset bits 6..10
font["head"].flags &= ~0x7e0
# Drop useless table with timestamp
if "FFTM" in font:
del font["FFTM"]
font.save(args.output)
def makeFont(args):
font = fontforge.open(args.input)
for glyph in font.glyphs():
glyph.unlinkRmOvrlpSave = True
if args.features:
font.mergeFeature(args.features)
if os.environ.get("SOURCE_DATE_EPOCH") is None:
os.environ["SOURCE_DATE_EPOCH"] = "0"
font.appendSFNTName("English (US)", "UniqueID", "%s;%s;%s" % (args.version,
font.os2_vendor, font.fontname))
font.version = args.version
font.generate(args.output, flags=("round", "opentype"))
postProcess(args)
def main():
parser = argparse.ArgumentParser(description="Create web fonts.")
parser.add_argument("input", help="input font file name")
parser.add_argument("output", help="output font file name")
parser.add_argument("--version", help="font version", required=True)
parser.add_argument("--features", help="font features file name")
args = parser.parse_args()
makeFont(args)
if __name__ == "__main__":
main()