extract glyph width prop

This commit is contained in:
subframe7536 2025-02-19 11:13:15 +08:00
parent 66359f7442
commit d4f897f230
2 changed files with 28 additions and 10 deletions

View file

@ -201,8 +201,8 @@ Feature Options:
zero,cv01,ss07,ss08`). No effect on variable format
--apply-fea-file Load feature file from `source/features/{regular,italic}.fea` to
variable font
--hinted Use hinted font as base font
--no-hinted Use unhinted font as base font
--hinted Use hinted font as base font in NF / CN / NF-CN
--no-hinted Use unhinted font as base font in NF / CN / NF-CN
--liga Preserve all the ligatures
--no-liga Remove all the ligatures
--cn-narrow Make CN characters narrow (experimental)
@ -214,7 +214,7 @@ Build Options:
--no-cn Do not build Chinese version
--cn-both Build both `Maple Mono CN` and `Maple Mono NF CN`. Nerd-Font version
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
--cn-rebuild Reinstantiate CN base font
--archive Build font archives with config and license. If has `--cache` flag,

View file

@ -93,7 +93,7 @@ def parse_args():
dest="hinted",
default=None,
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(
"--no-hinted",
@ -268,6 +268,8 @@ class FontConfig:
# whether to use pre-instantiated static CN font as base font
"use_static_base_font": True,
}
self.glyph_width = 600
self.glyph_width_cn_narrow = 1000
self.__load_config(args.normal)
self.__load_args(args)
@ -375,6 +377,18 @@ class FontConfig:
self.cn["with_nerd_font"] = not self.cn["with_nerd_font"]
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:
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"]:
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
# already removed at merge time
@ -972,8 +990,6 @@ def main():
build_option = BuildOption(font_config)
build_option.load_cn_dir_and_suffix(font_config.should_build_nf_cn())
glyph_width = 600
if parsed_args.dry:
print("font_config:", json.dumps(font_config.__dict__, indent=4))
if not is_ci():
@ -1039,7 +1055,9 @@ def main():
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)
@ -1146,10 +1164,10 @@ def main():
build_option.is_cn_built = True
verify_glyph_width(
TTFont(
font=TTFont(
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),
)
# =========================================================================================