diff --git a/README.md b/README.md index ab92e22..b68b305 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Base on `Jetbrains Mono` and **much "Opinioned"** ![](https://github.com/subframe7536/maple-font/assets/78338239/19383849-6be1-4cfc-9b34-7b33fc047ecf) - generated by [CodeImg](https://github.com/subframe7536/vscode-codeimg) +- Theme: [Maple](https://github.com/subframe7536/vscode-theme-maple) ## Features @@ -50,7 +51,7 @@ WIP run it in your local machine. -You can change config in `build.py` +You can change config in `config.json` Make sure you have `python3` and `pip` installed diff --git a/build.py b/build.py index bbe0460..fad3f15 100644 --- a/build.py +++ b/build.py @@ -19,13 +19,18 @@ release_mode = True # whether to clean built fonts clean_cache = True # build process pool size -pool_size = 4 if not getenv("CODESPACE_NAME") else 2 build_config = { + # the number of parallel tasks + # when run in codespace, this will be 1 + "pool_size": 4 if not getenv("CODESPACE_NAME") else 1, + # font family name "family_name": "Maple Mono", # whether to use hinted ttf as base font "use_hinted": True, + # nerd font settings "nerd_font": { + # whether to enable Nerd Font "enable": True, # target version of Nerd Font if font-patcher not exists "version": "3.2.1", @@ -34,7 +39,7 @@ build_config = { # prefer to use Font Patcher instead of using prebuild NerdFont base font # if you want to custom build nerd font using font-patcher, you need to set this to True "use_font_patcher": False, - # Symbol Fonts settings. + # symbol Fonts settings. # default args: ["--complete"] # if not, will use font-patcher to generate fonts # full args: https://github.com/ryanoasis/nerd-fonts?tab=readme-ov-file#font-patcher @@ -45,7 +50,10 @@ build_config = { # full args: https://github.com/ryanoasis/nerd-fonts?tab=readme-ov-file#font-patcher "extra_args": [], }, + # chinese font settings "cn": { + # whether to build Chinese fonts + # skip if Chinese base fonts are not founded "enable": True, # whether to patch Nerd Font "with_nerd_font": True, @@ -56,6 +64,15 @@ build_config = { }, } +try: + with open("config.json", "r") as f: + data = json.load(f) + if "$schema" in data: + del data["$schema"] + build_config = {**build_config, **data} +except: + print("config.json is not found. Use default config.") + package_name = "foundryToolsCLI" package_installed = importlib.util.find_spec(package_name) is not None @@ -465,7 +482,7 @@ def main(): run(f"ftcli ttf fix-contours {output_ttf}") run(f"ftcli ttf remove-overlaps {output_ttf}") - with Pool(pool_size) as p: + with Pool(build_config["pool_size"]) as p: p.map(build_mono, listdir(output_ttf)) # ========================================================================================= @@ -488,13 +505,11 @@ def main(): ) use_font_patcher = False - with Pool(pool_size) as p: + with Pool(build_config["pool_size"]) as p: _build_fn = partial(build_nf, use_font_patcher=use_font_patcher) _version = build_config["nerd_font"]["version"] _name = ( - f"FontPatcher v{_version}" - if use_font_patcher - else "prebuild Nerd Font" + f"FontPatcher v{_version}" if use_font_patcher else "prebuild Nerd Font" ) print("========================================") print(f"patch Nerd Font using {_name}") @@ -521,7 +536,7 @@ def main(): makedirs(output_nf_cn, exist_ok=True) - with Pool(pool_size) as p: + with Pool(build_config["pool_size"]) as p: p.map(build_cn, listdir(cn_base_font_dir)) run(f"ftcli name del-mac-names -r {output_dir}") @@ -531,7 +546,9 @@ def main(): # ========================================================================================= # write config to output path - with open(path.join(output_dir, "build-config.json"), "w", encoding="utf-8") as config_file: + with open( + path.join(output_dir, "build-config.json"), "w", encoding="utf-8" + ) as config_file: config_file.write(conf) if release_mode: @@ -551,7 +568,9 @@ def main(): print(f"archieve: {f}") # write sha1 - with open(path.join(release_dir, "sha1.json"), "w", encoding="utf-8") as hash_file: + with open( + path.join(release_dir, "sha1.json"), "w", encoding="utf-8" + ) as hash_file: hash_file.write(json.dumps(hash_map, indent=4)) # copy woff2 to root diff --git a/config.json b/config.json new file mode 100644 index 0000000..606a52e --- /dev/null +++ b/config.json @@ -0,0 +1,21 @@ +{ + "$schema": "./source/schema.json", + "family_name": "Maple Mono", + "use_hinted": true, + "nerd_font": { + "enable": true, + "version": "3.2.1", + "mono": false, + "use_font_patcher": false, + "glyphs": [ + "--complete" + ], + "extra_args": [] + }, + "cn": { + "enable": true, + "with_nerd_font": true, + "fix_meta_table": true, + "clean_cache": false + } +} \ No newline at end of file diff --git a/source/schema.json b/source/schema.json new file mode 100644 index 0000000..1510ab1 --- /dev/null +++ b/source/schema.json @@ -0,0 +1,108 @@ +{ + "title": "Build Configuration Schema", + "description": "Schema for the build configuration of a font project", + "type": "object", + "properties": { + "pool_size": { + "type": "number", + "description": "The number of parallel tasks. When run in codespace, this will be 1", + "default": 4 + }, + "family_name": { + "type": "string", + "description": "The font family name", + "default": "Maple Mono" + }, + "use_hinted": { + "type": "boolean", + "description": "Whether to use hinted TTF as base font", + "default": true + }, + "nerd_font": { + "type": "object", + "properties": { + "enable": { + "type": "boolean", + "description": "Whether to enable Nerd Font", + "default": true + }, + "version": { + "type": "string", + "description": "Target version of Nerd Font. If font-patcher not exists when need to use it or there is no prebuild font for current version, will download from Github", + "default": "3.2.1" + }, + "mono": { + "type": "boolean", + "description": "Whether to make icon width fixed", + "default": false + }, + "use_font_patcher": { + "type": "boolean", + "description": "Prefer to use Font Patcher instead of using prebuilt NerdFont base font. If you want to custom build nerd font using font-patcher, you need to set this to True", + "default": false + }, + "glyphs": { + "type": "array", + "items": { + "type": "string" + }, + "default": ["--complete"], + "description": "Symbol Fonts settings. if is not [\"--complete\"], will use font-patcher to generate fonts. Full args: https://github.com/ryanoasis/nerd-fonts?tab=readme-ov-file#font-patcher" + }, + "extra_args": { + "type": "array", + "items": { + "type": "string" + }, + "default": [], + "description": "Extra arguments for font-patcher, default args: [\"-l\", \"--careful\", \"--outputdir\", output_nf], if \"mono\" is set to true, \"--mono\" will be added, full args: https://github.com/ryanoasis/nerd-fonts?tab=readme-ov-file#font-patcher" + } + }, + "required": [ + "enable", + "version", + "mono", + "use_font_patcher", + "glyphs", + "extra_args" + ] + }, + "cn": { + "type": "object", + "properties": { + "enable": { + "type": "boolean", + "description": "Whether to build Chinese fonts. Skip if Chinese base fonts are not founded", + "default": true + }, + "with_nerd_font": { + "type": "boolean", + "description": "Whether to patch Nerd Font", + "default": true + }, + "fix_meta_table": { + "type": "boolean", + "description": "Fix design language and supported languages in META table", + "default": true + }, + "clean_cache": { + "type": "boolean", + "description": "Whether to clean instantiated base CN fonts", + "default": false + } + }, + "required": [ + "enable", + "with_nerd_font", + "fix_meta_table", + "clean_cache" + ] + } + }, + "required": [ + "family_name", + "use_hinted", + "nerd_font", + "cn" + ] +} \ No newline at end of file