remove --forgive (#340)

This commit is contained in:
Song 2025-02-20 00:02:39 +08:00 committed by GitHub
parent ea1dcb4cfc
commit 97aa3c225d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 36 deletions

View file

@ -180,11 +180,6 @@ def parse_args():
action="store_true", action="store_true",
help="Build font archives with config and license. If has `--cache` flag, only archive Nerd-Font and CN formats", 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() return parser.parse_args()
@ -276,7 +271,6 @@ class FontConfig:
} }
self.glyph_width = 600 self.glyph_width = 600
self.glyph_width_cn_narrow = 1000 self.glyph_width_cn_narrow = 1000
self.forgive = False
self.__load_config(args.normal) self.__load_config(args.normal)
self.__load_args(args) self.__load_args(args)
@ -358,9 +352,6 @@ class FontConfig:
if args.apply_fea_file: if args.apply_fea_file:
self.apply_fea_file = True self.apply_fea_file = True
if args.forgive:
self.forgive = True
if args.cn_rebuild: if args.cn_rebuild:
self.cn["clean_cache"] = True self.cn["clean_cache"] = True
self.cn["use_static_base_font"] = False 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, 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) remove(source_path)
target_path = joinPaths(build_option.output_ttf, f"{postscript_name}.ttf") target_path = joinPaths(build_option.output_ttf, f"{postscript_name}.ttf")
font.save(target_path) font.save(target_path)
@ -928,10 +925,15 @@ def build_nf(
preferred_family_name=f"{font_config.family_name} NF", preferred_family_name=f"{font_config.family_name} NF",
preferred_style_name=style_in_17, 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( target_path = joinPaths(
build_option.output_nf, 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.save(target_path)
nf_font.close() nf_font.close()
@ -1012,10 +1014,14 @@ def build_cn(f: str, font_config: FontConfig, build_option: BuildOption):
"slng": "Latn, Hans, Hant, Jpan", "slng": "Latn, Hans, Hant, Jpan",
} }
cn_font["meta"] = meta 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( target_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"{postscript_name}.ttf",
) )
cn_font.save(target_path) cn_font.save(target_path)
cn_font.close() cn_font.close()
@ -1137,7 +1143,7 @@ def main():
verify_glyph_width( verify_glyph_width(
font=font, font=font,
expect_widths=font_config.get_valid_glyph_width_list(), expect_widths=font_config.get_valid_glyph_width_list(),
forgive=font_config.forgive, file_name=basename,
) )
add_gasp(font) add_gasp(font)
@ -1203,14 +1209,6 @@ def main():
drop_mac_names(build_option.output_ttf) drop_mac_names(build_option.output_ttf)
build_option.is_nf_built = True 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 ======================================= # ==================================== Build CN =======================================
# ========================================================================================= # =========================================================================================
@ -1240,14 +1238,6 @@ def main():
build_option.is_cn_built = True 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 ===================================== # ================================== Write Config =====================================
# ========================================================================================= # =========================================================================================

View file

@ -191,7 +191,7 @@ def match_unicode_names(file_path: str) -> dict[str, str]:
# https://github.com/subframe7536/maple-font/issues/314 # 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...") print("Verify glyph width...")
result: tuple[str, int] = [] result: tuple[str, int] = []
for name in font.getGlyphNames(): 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: for item in result:
print(f"{item[0]} => {item[1]}") print(f"{item[0]} => {item[1]}")
if forgive: raise Exception(
print("❗Forgive it") f"{file_name or 'The font'} may contain glyphs that width is not in {expect_widths}, which may broke monospace rule."
else: )
raise Exception(
f"The font may contain glyphs that width is not in {expect_widths}, which may broke monospace rule."
)
def compress_folder( def compress_folder(