optimize version string
This commit is contained in:
parent
15d3b4f08a
commit
43a0e910bd
2 changed files with 72 additions and 32 deletions
90
build.py
90
build.py
|
@ -22,7 +22,7 @@ from source.py.utils import (
|
||||||
)
|
)
|
||||||
from source.py.feature import freeze_feature, get_freeze_config_str
|
from source.py.feature import freeze_feature, get_freeze_config_str
|
||||||
|
|
||||||
FONT_VERSION = "7.000 beta31"
|
FONT_VERSION = "v7.0-beta31"
|
||||||
# =========================================================================================
|
# =========================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,6 +250,14 @@ class FontConfig:
|
||||||
}
|
}
|
||||||
self.__load_external(args)
|
self.__load_external(args)
|
||||||
|
|
||||||
|
ver = FONT_VERSION
|
||||||
|
if "-" in FONT_VERSION:
|
||||||
|
ver, beta = FONT_VERSION.split("-")
|
||||||
|
self.beta = beta
|
||||||
|
|
||||||
|
major, minor = ver.split(".")
|
||||||
|
self.version_str = f"Version {major}.{minor:03}"
|
||||||
|
|
||||||
def __load_external(self, args):
|
def __load_external(self, args):
|
||||||
self.archive = args.archive
|
self.archive = args.archive
|
||||||
self.use_cn_both = args.cn_both
|
self.use_cn_both = args.cn_both
|
||||||
|
@ -520,7 +528,12 @@ def drop_mac_names(dir: str):
|
||||||
run(f"ftcli name del-mac-names -r {dir}")
|
run(f"ftcli name del-mac-names -r {dir}")
|
||||||
|
|
||||||
|
|
||||||
def rename_glyph_name(font: TTFont, old_glyph_name: str, new_glyph_name: str, post_extra_names: bool = True):
|
def rename_glyph_name(
|
||||||
|
font: TTFont,
|
||||||
|
old_glyph_name: str,
|
||||||
|
new_glyph_name: str,
|
||||||
|
post_extra_names: bool = True,
|
||||||
|
):
|
||||||
glyph_names = font.getGlyphOrder()
|
glyph_names = font.getGlyphOrder()
|
||||||
modified = False
|
modified = False
|
||||||
for i, _ in enumerate(glyph_names):
|
for i, _ in enumerate(glyph_names):
|
||||||
|
@ -532,20 +545,26 @@ def rename_glyph_name(font: TTFont, old_glyph_name: str, new_glyph_name: str, po
|
||||||
font.setGlyphOrder(glyph_names)
|
font.setGlyphOrder(glyph_names)
|
||||||
|
|
||||||
if post_extra_names:
|
if post_extra_names:
|
||||||
index = font['post'].extraNames.index(old_glyph_name)
|
index = font["post"].extraNames.index(old_glyph_name)
|
||||||
if index != -1:
|
if index != -1:
|
||||||
font['post'].extraNames[index] = new_glyph_name
|
font["post"].extraNames[index] = new_glyph_name
|
||||||
|
|
||||||
|
|
||||||
def get_unique_identifier(
|
def get_unique_identifier(
|
||||||
|
font_config: FontConfig,
|
||||||
postscript_name: str,
|
postscript_name: str,
|
||||||
freeze_config_str: str,
|
|
||||||
narrow: bool = False,
|
narrow: bool = False,
|
||||||
) -> str:
|
) -> str:
|
||||||
|
suffix = font_config.freeze_config_str
|
||||||
if "CN" in postscript_name and narrow:
|
if "CN" in postscript_name and narrow:
|
||||||
freeze_config_str += "Narrow;"
|
suffix += "Narrow;"
|
||||||
|
|
||||||
return f"Version {FONT_VERSION};SUBF;{postscript_name};2024;FL830;{freeze_config_str}"
|
if "NF" in postscript_name:
|
||||||
|
nf_ver = font_config.nerd_font["version"]
|
||||||
|
suffix = f"NF{nf_ver};{suffix}"
|
||||||
|
|
||||||
|
beta_str = f'-{font_config.beta}' if font_config.beta else ''
|
||||||
|
return f"{font_config.version_str}{beta_str};SUBF;{postscript_name};2024;FL830;{suffix}"
|
||||||
|
|
||||||
|
|
||||||
def change_char_width(font: TTFont, match_width: int, target_width: int):
|
def change_char_width(font: TTFont, match_width: int, target_width: int):
|
||||||
|
@ -590,13 +609,18 @@ def build_mono(f: str, font_config: FontConfig, build_option: BuildOption):
|
||||||
f"{font_config.family_name} {style}",
|
f"{font_config.family_name} {style}",
|
||||||
4,
|
4,
|
||||||
)
|
)
|
||||||
|
set_font_name(
|
||||||
|
font,
|
||||||
|
font_config.version_str,
|
||||||
|
5,
|
||||||
|
)
|
||||||
postscript_name = f"{font_config.family_name_compact}-{style_compact}"
|
postscript_name = f"{font_config.family_name_compact}-{style_compact}"
|
||||||
set_font_name(font, postscript_name, 6)
|
set_font_name(font, postscript_name, 6)
|
||||||
set_font_name(
|
set_font_name(
|
||||||
font,
|
font,
|
||||||
get_unique_identifier(
|
get_unique_identifier(
|
||||||
|
font_config=font_config,
|
||||||
postscript_name=postscript_name,
|
postscript_name=postscript_name,
|
||||||
freeze_config_str=font_config.freeze_config_str,
|
|
||||||
),
|
),
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
|
@ -714,13 +738,18 @@ def build_nf(
|
||||||
f"{font_config.family_name} NF {style_nf}",
|
f"{font_config.family_name} NF {style_nf}",
|
||||||
4,
|
4,
|
||||||
)
|
)
|
||||||
|
set_font_name(
|
||||||
|
nf_font,
|
||||||
|
font_config.version_str,
|
||||||
|
5,
|
||||||
|
)
|
||||||
postscript_name = f"{font_config.family_name_compact}-NF-{style_compact_nf}"
|
postscript_name = f"{font_config.family_name_compact}-NF-{style_compact_nf}"
|
||||||
set_font_name(nf_font, postscript_name, 6)
|
set_font_name(nf_font, postscript_name, 6)
|
||||||
set_font_name(
|
set_font_name(
|
||||||
nf_font,
|
nf_font,
|
||||||
get_unique_identifier(
|
get_unique_identifier(
|
||||||
|
font_config=font_config,
|
||||||
postscript_name=postscript_name,
|
postscript_name=postscript_name,
|
||||||
freeze_config_str=font_config.feature_freeze,
|
|
||||||
),
|
),
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
|
@ -743,7 +772,7 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption):
|
||||||
print(f"👉 {build_option.cn_suffix_compact} version for {f}")
|
print(f"👉 {build_option.cn_suffix_compact} version for {f}")
|
||||||
|
|
||||||
merger = Merger()
|
merger = Merger()
|
||||||
font = merger.merge(
|
cn_font = merger.merge(
|
||||||
[
|
[
|
||||||
joinPaths(build_option.cn_base_font_dir, f),
|
joinPaths(build_option.cn_base_font_dir, f),
|
||||||
joinPaths(
|
joinPaths(
|
||||||
|
@ -758,52 +787,59 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption):
|
||||||
)
|
)
|
||||||
|
|
||||||
set_font_name(
|
set_font_name(
|
||||||
font,
|
cn_font,
|
||||||
f"{font_config.family_name} {build_option.cn_suffix}{style_cn_with_prefix_space}",
|
f"{font_config.family_name} {build_option.cn_suffix}{style_cn_with_prefix_space}",
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
set_font_name(font, style_cn_in_2, 2)
|
set_font_name(cn_font, style_cn_in_2, 2)
|
||||||
set_font_name(
|
set_font_name(
|
||||||
font,
|
cn_font,
|
||||||
f"{font_config.family_name} {build_option.cn_suffix} {style_cn}",
|
f"{font_config.family_name} {build_option.cn_suffix} {style_cn}",
|
||||||
4,
|
4,
|
||||||
)
|
)
|
||||||
postscript_name = f"{font_config.family_name_compact}-{build_option.cn_suffix_compact}-{style_compact_cn}"
|
|
||||||
set_font_name(font, postscript_name, 6)
|
|
||||||
set_font_name(
|
set_font_name(
|
||||||
font,
|
cn_font,
|
||||||
|
font_config.version_str,
|
||||||
|
5,
|
||||||
|
)
|
||||||
|
postscript_name = f"{font_config.family_name_compact}-{build_option.cn_suffix_compact}-{style_compact_cn}"
|
||||||
|
set_font_name(cn_font, postscript_name, 6)
|
||||||
|
set_font_name(
|
||||||
|
cn_font,
|
||||||
get_unique_identifier(
|
get_unique_identifier(
|
||||||
|
font_config=font_config,
|
||||||
postscript_name=postscript_name,
|
postscript_name=postscript_name,
|
||||||
freeze_config_str=font_config.freeze_config_str,
|
|
||||||
narrow=font_config.cn["narrow"],
|
narrow=font_config.cn["narrow"],
|
||||||
),
|
),
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
|
|
||||||
if style_compact_cn not in build_option.skip_subfamily_list:
|
if style_compact_cn not in build_option.skip_subfamily_list:
|
||||||
set_font_name(font, f"{font_config.family_name} {build_option.cn_suffix}", 16)
|
set_font_name(
|
||||||
set_font_name(font, style_cn, 17)
|
cn_font, f"{font_config.family_name} {build_option.cn_suffix}", 16
|
||||||
|
)
|
||||||
|
set_font_name(cn_font, style_cn, 17)
|
||||||
|
|
||||||
font["OS/2"].xAvgCharWidth = 600
|
cn_font["OS/2"].xAvgCharWidth = 600
|
||||||
|
|
||||||
# https://github.com/subframe7536/maple-font/issues/188
|
# https://github.com/subframe7536/maple-font/issues/188
|
||||||
fix_cv98(font)
|
fix_cv98(cn_font)
|
||||||
|
|
||||||
handle_ligatures(
|
handle_ligatures(
|
||||||
font=font,
|
font=cn_font,
|
||||||
enable_ligature=font_config.enable_liga,
|
enable_ligature=font_config.enable_liga,
|
||||||
freeze_config=font_config.feature_freeze,
|
freeze_config=font_config.feature_freeze,
|
||||||
)
|
)
|
||||||
|
|
||||||
if font_config.cn["narrow"]:
|
if font_config.cn["narrow"]:
|
||||||
change_char_width(font=font, match_width=1200, target_width=1000)
|
change_char_width(font=cn_font, match_width=1200, target_width=1000)
|
||||||
|
|
||||||
# https://github.com/subframe7536/maple-font/issues/239
|
# https://github.com/subframe7536/maple-font/issues/239
|
||||||
# remove_locl(font)
|
# remove_locl(font)
|
||||||
|
|
||||||
if font_config.cn["fix_meta_table"]:
|
if font_config.cn["fix_meta_table"]:
|
||||||
# add code page, Latin / Japanese / Simplify Chinese / Traditional Chinese
|
# add code page, Latin / Japanese / Simplify Chinese / Traditional Chinese
|
||||||
font["OS/2"].ulCodePageRange1 = 1 << 0 | 1 << 17 | 1 << 18 | 1 << 20
|
cn_font["OS/2"].ulCodePageRange1 = 1 << 0 | 1 << 17 | 1 << 18 | 1 << 20
|
||||||
|
|
||||||
# fix meta table, https://learn.microsoft.com/en-us/typography/opentype/spec/meta
|
# fix meta table, https://learn.microsoft.com/en-us/typography/opentype/spec/meta
|
||||||
meta = newTable("meta")
|
meta = newTable("meta")
|
||||||
|
@ -811,15 +847,15 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption):
|
||||||
"dlng": "Latn, Hans, Hant, Jpan",
|
"dlng": "Latn, Hans, Hant, Jpan",
|
||||||
"slng": "Latn, Hans, Hant, Jpan",
|
"slng": "Latn, Hans, Hant, Jpan",
|
||||||
}
|
}
|
||||||
font["meta"] = meta
|
cn_font["meta"] = meta
|
||||||
|
|
||||||
_path = joinPaths(
|
_path = joinPaths(
|
||||||
build_option.output_cn,
|
build_option.output_cn,
|
||||||
f"{font_config.family_name_compact}-{build_option.cn_suffix_compact}-{style_compact_cn}.ttf",
|
f"{font_config.family_name_compact}-{build_option.cn_suffix_compact}-{style_compact_cn}.ttf",
|
||||||
)
|
)
|
||||||
|
|
||||||
font.save(_path)
|
cn_font.save(_path)
|
||||||
font.close()
|
cn_font.close()
|
||||||
|
|
||||||
|
|
||||||
def run_build(pool_size: int, fn: Callable, dir: str):
|
def run_build(pool_size: int, fn: Callable, dir: str):
|
||||||
|
|
14
release.py
14
release.py
|
@ -47,15 +47,19 @@ def rename_files(dir: str):
|
||||||
def parse_tag(args):
|
def parse_tag(args):
|
||||||
"""
|
"""
|
||||||
Parse the tag from the command line arguments.
|
Parse the tag from the command line arguments.
|
||||||
Format: v7.000[-beta31]
|
Format: v7.0[-beta3]
|
||||||
"""
|
"""
|
||||||
tag = args.tag
|
tag = args.tag
|
||||||
|
|
||||||
if not tag.startswith("v"):
|
if not tag.startswith("v"):
|
||||||
tag = f"v{tag}"
|
tag = f"v{tag}"
|
||||||
if not re.match(r"^v\d+\.\d{3}$", tag):
|
|
||||||
raise ValueError(f"Tag must end with 3 numbers following a '.', input is {tag}")
|
if not re.match(r"^v\d+\.\d+$", tag):
|
||||||
|
raise ValueError(f"Invalide tag: {tag}, format: v7.0")
|
||||||
|
|
||||||
if args.beta:
|
if args.beta:
|
||||||
tag += "-" if args.beta.startswith("beta") else "-beta" + args.beta
|
tag += "-" if args.beta.startswith("beta") else "-beta" + args.beta
|
||||||
|
|
||||||
return tag
|
return tag
|
||||||
|
|
||||||
def update_build_script_version(tag):
|
def update_build_script_version(tag):
|
||||||
|
@ -70,7 +74,7 @@ def update_build_script_version(tag):
|
||||||
|
|
||||||
def git_commit(tag):
|
def git_commit(tag):
|
||||||
run("git add woff2/var build.py")
|
run("git add woff2/var build.py")
|
||||||
run(f"git commit -m 'Release {tag}'")
|
run(["git", "commit", "-m", f"Release {tag}"])
|
||||||
run(f"git tag {tag}")
|
run(f"git tag {tag}")
|
||||||
print("Committed and tagged")
|
print("Committed and tagged")
|
||||||
|
|
||||||
|
@ -84,7 +88,7 @@ def main():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"tag",
|
"tag",
|
||||||
type=str,
|
type=str,
|
||||||
help="The tag to build the release for, format: v7.000",
|
help="The tag to build the release for, format: 7.0 or v7.0",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"beta",
|
"beta",
|
||||||
|
|
Loading…
Reference in a new issue