From 86c0df18c8d068b82d181e64dc05dc2234002755 Mon Sep 17 00:00:00 2001 From: TakWolf Date: Wed, 13 Nov 2024 02:34:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20format=5Fglyphs()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/{format.py => format_glyphs.py} | 2 +- tools/services/format_service.py | 30 ++------------------------- 2 files changed, 3 insertions(+), 29 deletions(-) rename tools/{format.py => format_glyphs.py} (82%) diff --git a/tools/format.py b/tools/format_glyphs.py similarity index 82% rename from tools/format.py rename to tools/format_glyphs.py index ead1f0b..48dd8fb 100644 --- a/tools/format.py +++ b/tools/format_glyphs.py @@ -6,7 +6,7 @@ def main(): for font_size in configs.font_sizes: font_config = FontConfig.load(font_size) - format_service.format_glyph_files(font_config) + format_service.format_glyphs(font_config) if __name__ == '__main__': diff --git a/tools/services/format_service.py b/tools/services/format_service.py index 2564e9d..a838e6a 100644 --- a/tools/services/format_service.py +++ b/tools/services/format_service.py @@ -2,8 +2,6 @@ import shutil from pathlib import Path -import unidata_blocks -from loguru import logger from pixel_font_knife import glyph_file_util from tools import configs @@ -19,35 +17,11 @@ def _is_empty_dir(path: Path) -> bool: return True -def format_glyph_files(font_config: FontConfig): +def format_glyphs(font_config: FontConfig): for width_mode_dir_name in itertools.chain(['common'], configs.width_modes): width_mode_dir = path_define.patch_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(): - if code_point == -1: - code_name = 'notdef' - file_dir = width_mode_dir - else: - code_name = f'{code_point:04X}' - block = unidata_blocks.get_block_by_code_point(code_point) - file_dir = width_mode_dir.joinpath(f'{block.code_start:04X}-{block.code_end:04X} {block.name}') - if block.code_start == 0x4E00: - file_dir = file_dir.joinpath(f'{code_name[0:-2]}-') - - for glyph_file in set(flavor_group.values()): - if len(glyph_file.flavors) > 0: - file_name = f'{code_name} {','.join(sorted(glyph_file.flavors, key=lambda x: configs.language_file_flavors.index(x)))}.png' - else: - 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] duplicate glyph files: '{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) - glyph_file.file_path = file_path - - glyph_file.bitmap.save_png(glyph_file.file_path) + glyph_file_util.normalize_context(context, width_mode_dir, configs.language_file_flavors) for file_dir, _, _ in width_mode_dir.walk(top_down=False): if _is_empty_dir(file_dir):