Debian Codegraph @

scripts/fsSelection.py

raw symbols SCIP
1 import sys
2 from fontTools.ttLib import TTFont
3 from fontTools.misc.textTools import binary2num, num2binary
4
5 # https://github.com/Typefounding/setUseTypoMetricsFalse
6 def setUseTypoMetricsTrue(fontPath, outPath):
7 # Get Font object from path
8 font = TTFont(fontPath)
9
10 # Get the OS/2 Table
11 os2 = font["OS/2"]
12
13 # Make sure that we only fix fonts with an OS/2 table version
14 # that is 4 or greater
15 if os2.version >= 4:
16
17 # Get the binary representation of fsSelection
18 b = num2binary(os2.fsSelection, 16)
19
20 # Make a new binary representation of fsSelection that sets
21 # the Use Typo Metrics bit to false (0)
22 nb = b[:9] + '1' + b[10:]
23
24 # Give the font the new fsSelection
25 os2.fsSelection = binary2num(nb)
26
27 # Save font to new path
28 font.save(outPath)
29 else:
30 print(fontPath + " OS/2 table version is less than 4, nothing to fix.")
31
32 if __name__ == "__main__":
33 if len(sys.argv) < 3:
34 print(
35 "Args must be: <input-font> <output-font>")
36 sys.exit(1)
37
38 setUseTypoMetricsTrue(sys.argv[1], sys.argv[2])