extract glyph width prop
This commit is contained in:
parent
66359f7442
commit
d4f897f230
2 changed files with 28 additions and 10 deletions
|
@ -201,8 +201,8 @@ Feature Options:
|
||||||
zero,cv01,ss07,ss08`). No effect on variable format
|
zero,cv01,ss07,ss08`). No effect on variable format
|
||||||
--apply-fea-file Load feature file from `source/features/{regular,italic}.fea` to
|
--apply-fea-file Load feature file from `source/features/{regular,italic}.fea` to
|
||||||
variable font
|
variable font
|
||||||
--hinted Use hinted font as base font
|
--hinted Use hinted font as base font in NF / CN / NF-CN
|
||||||
--no-hinted Use unhinted font as base font
|
--no-hinted Use unhinted font as base font in NF / CN / NF-CN
|
||||||
--liga Preserve all the ligatures
|
--liga Preserve all the ligatures
|
||||||
--no-liga Remove all the ligatures
|
--no-liga Remove all the ligatures
|
||||||
--cn-narrow Make CN characters narrow (experimental)
|
--cn-narrow Make CN characters narrow (experimental)
|
||||||
|
@ -214,7 +214,7 @@ Build Options:
|
||||||
--no-cn Do not build Chinese version
|
--no-cn Do not build Chinese version
|
||||||
--cn-both Build both `Maple Mono CN` and `Maple Mono NF CN`. Nerd-Font version
|
--cn-both Build both `Maple Mono CN` and `Maple Mono NF CN`. Nerd-Font version
|
||||||
must be enabled
|
must be enabled
|
||||||
--ttf-only Only build unhinted TTF format
|
--ttf-only Only build TTF format
|
||||||
--cache Reuse font cache of TTF, OTF and Woff2 formats
|
--cache Reuse font cache of TTF, OTF and Woff2 formats
|
||||||
--cn-rebuild Reinstantiate CN base font
|
--cn-rebuild Reinstantiate CN base font
|
||||||
--archive Build font archives with config and license. If has `--cache` flag,
|
--archive Build font archives with config and license. If has `--cache` flag,
|
||||||
|
|
32
build.py
32
build.py
|
@ -93,7 +93,7 @@ def parse_args():
|
||||||
dest="hinted",
|
dest="hinted",
|
||||||
default=None,
|
default=None,
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Use hinted font as base font",
|
help="Use hinted font as base font in NF / CN / NF-CN",
|
||||||
)
|
)
|
||||||
hint_group.add_argument(
|
hint_group.add_argument(
|
||||||
"--no-hinted",
|
"--no-hinted",
|
||||||
|
@ -268,6 +268,8 @@ class FontConfig:
|
||||||
# whether to use pre-instantiated static CN font as base font
|
# whether to use pre-instantiated static CN font as base font
|
||||||
"use_static_base_font": True,
|
"use_static_base_font": True,
|
||||||
}
|
}
|
||||||
|
self.glyph_width = 600
|
||||||
|
self.glyph_width_cn_narrow = 1000
|
||||||
self.__load_config(args.normal)
|
self.__load_config(args.normal)
|
||||||
self.__load_args(args)
|
self.__load_args(args)
|
||||||
|
|
||||||
|
@ -375,6 +377,18 @@ class FontConfig:
|
||||||
self.cn["with_nerd_font"] = not self.cn["with_nerd_font"]
|
self.cn["with_nerd_font"] = not self.cn["with_nerd_font"]
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_valid_glyph_width_list(self, cn=False):
|
||||||
|
if cn:
|
||||||
|
return [
|
||||||
|
0,
|
||||||
|
self.glyph_width,
|
||||||
|
self.glyph_width_cn_narrow
|
||||||
|
if self.cn["narrow"]
|
||||||
|
else 2 * self.glyph_width,
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
return [0, self.glyph_width]
|
||||||
|
|
||||||
|
|
||||||
class BuildOption:
|
class BuildOption:
|
||||||
def __init__(self, config: FontConfig):
|
def __init__(self, config: FontConfig):
|
||||||
|
@ -929,7 +943,11 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption):
|
||||||
)
|
)
|
||||||
|
|
||||||
if font_config.cn["narrow"]:
|
if font_config.cn["narrow"]:
|
||||||
change_glyph_width(font=cn_font, match_width=1200, target_width=1000)
|
change_glyph_width(
|
||||||
|
font=cn_font,
|
||||||
|
match_width=2 * font_config.glyph_width,
|
||||||
|
target_width=font_config.glyph_width_cn_narrow,
|
||||||
|
)
|
||||||
|
|
||||||
# https://github.com/subframe7536/maple-font/issues/239
|
# https://github.com/subframe7536/maple-font/issues/239
|
||||||
# already removed at merge time
|
# already removed at merge time
|
||||||
|
@ -972,8 +990,6 @@ def main():
|
||||||
build_option = BuildOption(font_config)
|
build_option = BuildOption(font_config)
|
||||||
build_option.load_cn_dir_and_suffix(font_config.should_build_nf_cn())
|
build_option.load_cn_dir_and_suffix(font_config.should_build_nf_cn())
|
||||||
|
|
||||||
glyph_width = 600
|
|
||||||
|
|
||||||
if parsed_args.dry:
|
if parsed_args.dry:
|
||||||
print("font_config:", json.dumps(font_config.__dict__, indent=4))
|
print("font_config:", json.dumps(font_config.__dict__, indent=4))
|
||||||
if not is_ci():
|
if not is_ci():
|
||||||
|
@ -1039,7 +1055,9 @@ def main():
|
||||||
3,
|
3,
|
||||||
)
|
)
|
||||||
|
|
||||||
verify_glyph_width(font, [0, glyph_width])
|
verify_glyph_width(
|
||||||
|
font=font, expect_widths=font_config.get_valid_glyph_width_list()
|
||||||
|
)
|
||||||
|
|
||||||
add_gasp(font)
|
add_gasp(font)
|
||||||
|
|
||||||
|
@ -1146,10 +1164,10 @@ def main():
|
||||||
build_option.is_cn_built = True
|
build_option.is_cn_built = True
|
||||||
|
|
||||||
verify_glyph_width(
|
verify_glyph_width(
|
||||||
TTFont(
|
font=TTFont(
|
||||||
joinPaths(build_option.output_cn, listdir(build_option.output_cn)[0])
|
joinPaths(build_option.output_cn, listdir(build_option.output_cn)[0])
|
||||||
),
|
),
|
||||||
[0, glyph_width, 1000 if font_config.cn['narrow'] else glyph_width * 2],
|
expect_widths=font_config.get_valid_glyph_width_list(True),
|
||||||
)
|
)
|
||||||
|
|
||||||
# =========================================================================================
|
# =========================================================================================
|
||||||
|
|
Loading…
Reference in a new issue