-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
83 lines (67 loc) · 2.65 KB
/
build.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# import sys
# sys.path.insert(0, "C:\dev\Python311\Lib\site-packages")
# import yaml
# from scfbuild.scfbuild.builder import Builder
# f = open("scfbuild.yml")
# conf = yaml.safe_load(f)
# f.close()
# builder = Builder(conf)
# builder.run()
from __future__ import annotations
import os
import toml
import subprocess
import typing as t
from preprocess import Preprocess
TConfig: t.TypeAlias = t.Dict[str, t.Union[str, int, t.List[t.Union[str, int]]]]
class Builder:
def __init__(self, config_file: str) -> None:
self.proc = Preprocess(config_file)
# return the path of the toml file
def __make_toml_config(self, srcs: t.List[str], format: t.Optional[str] = None) -> str:
toml_cfg = {
"family": self.proc.config["family"],
"output_file": os.path.join(self.proc.config["dist_directory"], f'{self.proc.config["family"]}.ttf'),
"version_major": self.proc.config["version_major"],
"version_minor": self.proc.config["version_minor"],
"color_format": self.proc.config["color_format"],
"clipbox_quantization": 32,
"axis": {
"wght": {
"name": "Weight",
"default": 400
}
},
"master": {
"regular": {
"style_name": "Regular",
"srcs": srcs,
"position":{
"wght": 400
}
}
}
}
if (format):
toml_cfg["output_file"] = os.path.join(self.proc.config["dist_directory"], f'{self.proc.config["family"]}-{format}.ttf')
toml_cfg["color_format"] = format
toml_cfg["output_file"] = os.path.abspath(toml_cfg["output_file"])
tomlcfg_directory = self.proc.config["tomlcfg_directory"]
tomlcfg_file = self.proc.config["tomlcfg_prefix"] + toml_cfg["color_format"] + ".toml"
path = os.path.abspath(os.path.join(tomlcfg_directory, tomlcfg_file))
with open(path, "w") as f:
f.write(toml.dumps(toml_cfg))
return path
def run(self):
svgs = self.proc.run()
configs: t.List[str] = []
configs.append(self.__make_toml_config(svgs))
if "additional_color_formats" in self.proc.config:
for format in self.proc.config["additional_color_formats"]:
configs.append(self.__make_toml_config(svgs, format))
for config in configs:
subprocess.run(f"nanoemoji \"{config}\"")
builder = Builder("config/config_dark.json")
builder.run()
builder = Builder("config/config_light.json")
builder.run()