|
7 | 7 | import ufo2ft
|
8 | 8 | import ufoLib2
|
9 | 9 | import vttLib
|
| 10 | +import sys |
| 11 | +import subprocess |
10 | 12 |
|
11 | 13 | INPUT_DIR = Path("sources")
|
12 | 14 | OUTPUT_DIR = Path("build")
|
@@ -44,42 +46,49 @@ def _set(instance):
|
44 | 46 |
|
45 | 47 |
|
46 | 48 | def build_font_instance(generator, instance_descriptor, *steps):
|
47 |
| - instance = generator.generate_instance(instance_descriptor) |
48 |
| - |
49 |
| - for step in steps: |
50 |
| - step(instance) |
51 |
| - |
52 |
| - setattr(instance.info, "openTypeOS2Panose", [2, 11, 6, 9, 2, 0, 0, 2, 0, 4]) |
53 |
| - |
54 |
| - instance.info.openTypeGaspRangeRecords =[ |
55 |
| - { |
56 |
| - "rangeMaxPPEM" : 9, |
57 |
| - "rangeGaspBehavior" : [1,3] |
58 |
| - }, |
59 |
| - { |
60 |
| - "rangeMaxPPEM" : 50, |
61 |
| - "rangeGaspBehavior" : [0,1,2,3] |
62 |
| - }, |
63 |
| - { |
64 |
| - "rangeMaxPPEM" : 65535, |
65 |
| - "rangeGaspBehavior" : [1,3] |
66 |
| - }, |
67 |
| - ] |
| 49 | + for format in ["ttf","otf"]: |
| 50 | + instance = generator.generate_instance(instance_descriptor) |
| 51 | + |
| 52 | + for step in steps: |
| 53 | + step(instance) |
| 54 | + |
| 55 | + instance.info.openTypeOS2Panose = [2, 11, 6, 9, 2, 0, 0, 2, 0, 4] |
| 56 | + |
| 57 | + if format == "ttf": |
| 58 | + instance.info.openTypeGaspRangeRecords =[ |
| 59 | + { |
| 60 | + "rangeMaxPPEM" : 9, |
| 61 | + "rangeGaspBehavior" : [1,3] |
| 62 | + }, |
| 63 | + { |
| 64 | + "rangeMaxPPEM" : 50, |
| 65 | + "rangeGaspBehavior" : [0,1,2,3] |
| 66 | + }, |
| 67 | + { |
| 68 | + "rangeMaxPPEM" : 65535, |
| 69 | + "rangeGaspBehavior" : [1,3] |
| 70 | + }, |
| 71 | + ] |
68 | 72 |
|
69 |
| - familyName = instance.info.familyName |
70 |
| - file_name = f"{familyName}.ttf".replace(" ", "") |
71 |
| - file_path = OUTPUT_DIR / file_name |
| 73 | + familyName = instance.info.familyName |
72 | 74 |
|
73 |
| - print(f"[{familyName}] Compiling") |
74 |
| - instance_font = ufo2ft.compileTTF(instance, removeOverlaps=True, inplace=True) |
| 75 | + file_stem = instance.info.familyName.replace(" ", "") |
| 76 | + file_path = (OUTPUT_DIR / file_stem).with_suffix(f".{format}") |
75 | 77 |
|
76 |
| - print(f"[{familyName}] Merging VTT") |
77 |
| - vttLib.transfer.merge_from_file(instance_font, VTT_DATA_FILE) |
| 78 | + print(f"[{familyName}] Compiling") |
| 79 | + if format == "ttf": |
| 80 | + instance_font = ufo2ft.compileTTF(instance, removeOverlaps=True, inplace=True) |
| 81 | + else: |
| 82 | + instance_font = ufo2ft.compileOTF(instance, removeOverlaps=True, inplace=True) |
78 | 83 |
|
79 |
| - print(f"[{familyName}] Saving") |
80 |
| - instance_font.save(file_path) |
| 84 | + if format == "ttf": |
| 85 | + print(f"[{familyName}] Merging VTT") |
| 86 | + vttLib.transfer.merge_from_file(instance_font, VTT_DATA_FILE) |
81 | 87 |
|
82 |
| - print(f"[{familyName}] Done: {file_path}") |
| 88 | + print(f"[{familyName}] Saving") |
| 89 | + instance_font.save(file_path) |
| 90 | + |
| 91 | + print(f"[{familyName}] Done: {file_path}") |
83 | 92 |
|
84 | 93 |
|
85 | 94 | if __name__ == "__main__":
|
@@ -167,5 +176,10 @@ def build_font_instance(generator, instance_descriptor, *steps):
|
167 | 176 | step_merge_nf,
|
168 | 177 | )
|
169 | 178 |
|
170 |
| - print("All done") |
171 |
| - print("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***") |
| 179 | + print("Autohinting OTFs") |
| 180 | + |
| 181 | + for file in Path("build").glob("*.otf"): |
| 182 | + subprocess.run(['psautohint --log "build/log.txt" '+str(file)], shell=True) |
| 183 | + |
| 184 | + print("All done") |
| 185 | + print("*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***") |
0 commit comments