Skip to content

Commit

Permalink
调整错误文案
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 10, 2024
1 parent 60531ce commit f0239a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions tools/services/check_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
def check_font_config(font_config: FontConfig):
for width_mode, layout_param in font_config.layout_params.items():
if width_mode == 'monospaced':
assert layout_param.line_height == font_config.font_size, f"[{font_config.font_size}px] Font config illegal 'monospaced.line_height': {layout_param.line_height}"
assert layout_param.line_height == font_config.font_size, f"[{font_config.font_size}px] font config illegal 'monospaced.line_height': {layout_param.line_height}"
else:
assert width_mode == 'proportional', f"[{font_config.font_size}px] Font config illegal 'width_mode': {width_mode}"
assert (layout_param.line_height - font_config.font_size) % 2 == 0, f"[{font_config.font_size}px] Font config illegal 'proportional.line_height': {layout_param.line_height}"
assert width_mode == 'proportional', f"[{font_config.font_size}px] font config illegal 'width_mode': {width_mode}"
assert (layout_param.line_height - font_config.font_size) % 2 == 0, f"[{font_config.font_size}px] font config illegal 'proportional.line_height': {layout_param.line_height}"


def check_glyph_files(font_config: FontConfig):
for width_mode_dir_name in itertools.chain(['common'], configs.width_modes):
width_mode_dir = path_define.glyphs_dir.joinpath(str(font_config.font_size), width_mode_dir_name)
context = glyph_file_util.load_context(width_mode_dir)
for code_point, flavor_group in context.items():
assert '' in flavor_group, f'[{font_config.font_size}px] Missing default flavor: {width_mode_dir_name} {code_point:04X}'
assert '' in flavor_group, f'[{font_config.font_size}px] missing default flavor: {width_mode_dir_name} {code_point:04X}'

if code_point == -1:
code_name = 'notdef'
Expand All @@ -45,29 +45,29 @@ def check_glyph_files(font_config: FontConfig):
else:
file_name = f'{code_name}.png'
file_path = file_dir.joinpath(file_name)
assert glyph_file.file_path == file_path, f"[{font_config.font_size}px] Glyph file path is not standardized: '{glyph_file.file_path}' -> '{file_path}'"
assert glyph_file.file_path == file_path, f"[{font_config.font_size}px] glyph file path is not standardized: '{glyph_file.file_path}' -> '{file_path}'"

if width_mode_dir_name == 'common' or width_mode_dir_name == 'monospaced':
assert glyph_file.height == font_config.font_size, f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert glyph_file.height == font_config.font_size, f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"

# H/Halfwidth or Na/Narrow
if east_asian_width == 'H' or east_asian_width == 'Na':
assert glyph_file.width == font_config.font_size / 2, f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert glyph_file.width == font_config.font_size / 2, f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"
# F/Fullwidth or W/Wide
elif east_asian_width == 'F' or east_asian_width == 'W':
assert glyph_file.width == font_config.font_size, f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert glyph_file.width == font_config.font_size, f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"
# A/Ambiguous or N/Neutral
else:
assert glyph_file.width == font_config.font_size / 2 or glyph_file.width == font_config.font_size, f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert glyph_file.width == font_config.font_size / 2 or glyph_file.width == font_config.font_size, f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"

if block is not None:
if 'CJK Unified Ideographs' in block.name:
assert all(alpha == 0 for alpha in glyph_file.bitmap[0]), f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert all(glyph_file.bitmap[i][-1] == 0 for i in range(0, len(glyph_file.bitmap))), f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert all(alpha == 0 for alpha in glyph_file.bitmap[0]), f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"
assert all(glyph_file.bitmap[i][-1] == 0 for i in range(0, len(glyph_file.bitmap))), f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"

if width_mode_dir_name == 'proportional':
assert glyph_file.height == font_config.line_height, f"[{font_config.font_size}px] Glyph data error: '{glyph_file.file_path}'"
assert glyph_file.height == font_config.line_height, f"[{font_config.font_size}px] glyph data error: '{glyph_file.file_path}'"

glyph_bytes = BytesIO()
glyph_file.bitmap.dump_png(glyph_bytes)
assert glyph_file.file_path.read_bytes() == glyph_bytes.getvalue(), f"[{font_config.font_size}px] Glyph file data is not standardized: '{glyph_file.file_path}'"
assert glyph_file.file_path.read_bytes() == glyph_bytes.getvalue(), f"[{font_config.font_size}px] glyph file data is not standardized: '{glyph_file.file_path}'"
2 changes: 1 addition & 1 deletion tools/services/format_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def format_glyph_files(font_config: FontConfig):
file_name = f'{code_name}.png'
file_path = file_dir.joinpath(file_name)
if glyph_file.file_path != file_path:
assert not file_path.exists(), f"[{font_config.font_size}px] Glyph file duplication: '{glyph_file.file_path}' -> '{file_path}'"
assert not file_path.exists(), f"[{font_config.font_size}px] glyph file duplication: '{glyph_file.file_path}' -> '{file_path}'"
file_dir.mkdir(parents=True, exist_ok=True)
glyph_file.file_path.rename(file_path)
logger.info("Format glyph file path: '{}' -> '{}'", glyph_file.file_path, file_path)
Expand Down

0 comments on commit f0239a6

Please sign in to comment.