From 97aa3c225df2e69d8ccd496362b76bb321984228 Mon Sep 17 00:00:00 2001 From: Song <1667077010@qq.com> Date: Thu, 20 Feb 2025 00:02:39 +0800 Subject: [PATCH] remove `--forgive` (#340) --- build.py | 48 ++++++++++++++++++---------------------------- source/py/utils.py | 11 ++++------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/build.py b/build.py index 27f7ffd..1577e31 100755 --- a/build.py +++ b/build.py @@ -180,11 +180,6 @@ def parse_args(): action="store_true", help="Build font archives with config and license. If has `--cache` flag, only archive Nerd-Font and CN formats", ) - build_group.add_argument( - "--forgive", - action="store_true", - help="Forgive errors", - ) return parser.parse_args() @@ -276,7 +271,6 @@ class FontConfig: } self.glyph_width = 600 self.glyph_width_cn_narrow = 1000 - self.forgive = False self.__load_config(args.normal) self.__load_args(args) @@ -358,9 +352,6 @@ class FontConfig: if args.apply_fea_file: self.apply_fea_file = True - if args.forgive: - self.forgive = True - if args.cn_rebuild: self.cn["clean_cache"] = True self.cn["use_static_base_font"] = False @@ -815,6 +806,12 @@ def build_mono(f: str, font_config: FontConfig, build_option: BuildOption): freeze_config=font_config.feature_freeze, ) + verify_glyph_width( + font=font, + expect_widths=font_config.get_valid_glyph_width_list(), + file_name=postscript_name, + ) + remove(source_path) target_path = joinPaths(build_option.output_ttf, f"{postscript_name}.ttf") font.save(target_path) @@ -928,10 +925,15 @@ def build_nf( preferred_family_name=f"{font_config.family_name} NF", preferred_style_name=style_in_17, ) + verify_glyph_width( + font=nf_font, + expect_widths=font_config.get_valid_glyph_width_list(), + file_name=postscript_name, + ) target_path = joinPaths( build_option.output_nf, - f"{font_config.family_name_compact}-NF-{style_compact_nf}.ttf", + f"{postscript_name}.ttf", ) nf_font.save(target_path) nf_font.close() @@ -1012,10 +1014,14 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption): "slng": "Latn, Hans, Hant, Jpan", } cn_font["meta"] = meta - + verify_glyph_width( + font=cn_font, + expect_widths=font_config.get_valid_glyph_width_list(True), + file_name=postscript_name, + ) target_path = joinPaths( build_option.output_cn, - f"{font_config.family_name_compact}-{build_option.cn_suffix_compact}-{style_compact_cn}.ttf", + f"{postscript_name}.ttf", ) cn_font.save(target_path) cn_font.close() @@ -1137,7 +1143,7 @@ def main(): verify_glyph_width( font=font, expect_widths=font_config.get_valid_glyph_width_list(), - forgive=font_config.forgive, + file_name=basename, ) add_gasp(font) @@ -1203,14 +1209,6 @@ def main(): drop_mac_names(build_option.output_ttf) build_option.is_nf_built = True - verify_glyph_width( - font=TTFont( - joinPaths(build_option.output_nf, listdir(build_option.output_nf)[0]) - ), - expect_widths=font_config.get_valid_glyph_width_list(), - forgive=font_config.forgive, - ) - # ========================================================================================= # ==================================== Build CN ======================================= # ========================================================================================= @@ -1240,14 +1238,6 @@ def main(): build_option.is_cn_built = True - verify_glyph_width( - font=TTFont( - joinPaths(build_option.output_cn, listdir(build_option.output_cn)[0]) - ), - expect_widths=font_config.get_valid_glyph_width_list(True), - forgive=font_config.forgive, - ) - # ========================================================================================= # ================================== Write Config ===================================== # ========================================================================================= diff --git a/source/py/utils.py b/source/py/utils.py index 06d02bd..af73c98 100644 --- a/source/py/utils.py +++ b/source/py/utils.py @@ -191,7 +191,7 @@ def match_unicode_names(file_path: str) -> dict[str, str]: # https://github.com/subframe7536/maple-font/issues/314 -def verify_glyph_width(font: TTFont, expect_widths: list[int], forgive: bool): +def verify_glyph_width(font: TTFont, expect_widths: list[int], file_name: str = None): print("Verify glyph width...") result: tuple[str, int] = [] for name in font.getGlyphNames(): @@ -204,12 +204,9 @@ def verify_glyph_width(font: TTFont, expect_widths: list[int], forgive: bool): for item in result: print(f"{item[0]} => {item[1]}") - if forgive: - print("❗Forgive it") - else: - raise Exception( - f"The font may contain glyphs that width is not in {expect_widths}, which may broke monospace rule." - ) + raise Exception( + f"{file_name or 'The font'} may contain glyphs that width is not in {expect_widths}, which may broke monospace rule." + ) def compress_folder(