github mirror support
This commit is contained in:
parent
877965ff95
commit
5df402f566
3 changed files with 27 additions and 7 deletions
|
@ -51,6 +51,10 @@ You can change build config in `config.json`
|
|||
2. Put them into `./source/cn`
|
||||
3. Run `build.py` and **BE PATIENT**, instantiation will take about 30 minutes
|
||||
|
||||
#### Notice
|
||||
|
||||
If you have trouble downloading `Font Patcher`, setup `nerd_font.github_mirror` in `config.json` or setup `$GITHUB` to your environment variable.
|
||||
|
||||
### Release Build
|
||||
|
||||
```sh
|
||||
|
|
25
build.py
25
build.py
|
@ -6,7 +6,7 @@ import shutil
|
|||
import time
|
||||
from functools import partial
|
||||
from multiprocessing import Pool
|
||||
from os import listdir, makedirs, path, remove, walk, getenv
|
||||
from os import environ, listdir, makedirs, path, remove, walk, getenv
|
||||
from urllib.request import urlopen
|
||||
from zipfile import ZIP_DEFLATED, ZipFile
|
||||
from fontTools.ttLib import TTFont, newTable
|
||||
|
@ -28,6 +28,7 @@ def check_ftcli():
|
|||
|
||||
# =========================================================================================
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(description="Optimizer and builder for Maple Mono")
|
||||
parser.add_argument(
|
||||
|
@ -68,6 +69,7 @@ def parse_args():
|
|||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
# =========================================================================================
|
||||
|
||||
|
||||
|
@ -167,6 +169,9 @@ class FontConfig:
|
|||
if "font_forge_bin" not in self.nerd_font:
|
||||
self.nerd_font["font_forge_bin"] = get_font_forge_bin()
|
||||
|
||||
if "github_mirror" not in self.nerd_font:
|
||||
self.nerd_font["github_mirror"] = "github.com"
|
||||
|
||||
if args.hinted is not None:
|
||||
self.use_hinted = True
|
||||
|
||||
|
@ -188,9 +193,10 @@ class FontConfig:
|
|||
):
|
||||
return False
|
||||
|
||||
if check_font_patcher(version=self.nerd_font["version"]) and not path.exists(
|
||||
self.nerd_font["font_forge_bin"]
|
||||
):
|
||||
if check_font_patcher(
|
||||
version=self.nerd_font["version"],
|
||||
github_mirror=self.nerd_font["github_mirror"],
|
||||
) and not path.exists(self.nerd_font["font_forge_bin"]):
|
||||
print(
|
||||
f"FontForge bin({self.nerd_font['font_forge_bin']}) not found. Use prebuild Nerd Font instead."
|
||||
)
|
||||
|
@ -263,7 +269,7 @@ def freeze(font: TTFont, freeze_config: dict[str, str]):
|
|||
)
|
||||
|
||||
|
||||
def check_font_patcher(version: str) -> bool:
|
||||
def check_font_patcher(version: str, github_mirror: str) -> bool:
|
||||
if path.exists("FontPatcher"):
|
||||
with open("FontPatcher/font-patcher", "r", encoding="utf-8") as f:
|
||||
if f"# Nerd Fonts Version: {version}" in f.read():
|
||||
|
@ -274,7 +280,10 @@ def check_font_patcher(version: str) -> bool:
|
|||
|
||||
zip_path = "FontPatcher.zip"
|
||||
if not path.exists(zip_path):
|
||||
url = f"https://github.com/ryanoasis/nerd-fonts/releases/download/v{version}/FontPatcher.zip"
|
||||
github = environ.get("GITHUB") # custom github mirror, for CN users
|
||||
if not github:
|
||||
github = github_mirror
|
||||
url = f"https://{github}/ryanoasis/nerd-fonts/releases/download/v{version}/FontPatcher.zip"
|
||||
try:
|
||||
print(f"NerdFont Patcher does not exist, download from {url}")
|
||||
with urlopen(url) as response, open(zip_path, "wb") as out_file:
|
||||
|
@ -423,7 +432,9 @@ def build_mono(f: str, font_config: FontConfig, build_option: BuildOption):
|
|||
font.save(_path)
|
||||
font.close()
|
||||
|
||||
run(f"ftcli ttf autohint {_path} -out {build_option.output_ttf_hinted}/{font_config.family_name_compact}-AutoHint-{style_compact}.ttf")
|
||||
run(
|
||||
f"ftcli ttf autohint {_path} -out {build_option.output_ttf_hinted}/{font_config.family_name_compact}-AutoHint-{style_compact}.ttf"
|
||||
)
|
||||
run(f"ftcli converter ttf2otf {_path} -out {build_option.output_otf}")
|
||||
run(f"ftcli converter ft2wf {_path} -out {build_option.output_woff2} -f woff2")
|
||||
|
||||
|
|
|
@ -213,6 +213,11 @@
|
|||
"description": "Whether to enable Nerd Font",
|
||||
"default": true
|
||||
},
|
||||
"github_mirror": {
|
||||
"type": "string",
|
||||
"description": "Github mirror for Nerd Font, will download from https://{github_mirror}/ryanoasis/nerd-fonts/releases/download/v{version}/FontPatcher.zip",
|
||||
"default": "github.com"
|
||||
},
|
||||
"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",
|
||||
|
|
Loading…
Reference in a new issue