diff --git a/assets/mappings/0180-024F-Latin-Extended-B.yml b/assets/mappings/0180-024F-Latin-Extended-B.yml new file mode 100644 index 000000000..21a5e1328 --- /dev/null +++ b/assets/mappings/0180-024F-Latin-Extended-B.yml @@ -0,0 +1,4 @@ + +# 0x0000 <- 0x0000 +0x0000: + ~: 0x0000 diff --git a/assets/mappings/0370-03FF-Greek-and-Coptic.yml b/assets/mappings/0370-03FF-Greek-and-Coptic.yml new file mode 100644 index 000000000..21a5e1328 --- /dev/null +++ b/assets/mappings/0370-03FF-Greek-and-Coptic.yml @@ -0,0 +1,4 @@ + +# 0x0000 <- 0x0000 +0x0000: + ~: 0x0000 diff --git a/assets/mappings/0400-04FF-Cyrillic.yml b/assets/mappings/0400-04FF-Cyrillic.yml new file mode 100644 index 000000000..21a5e1328 --- /dev/null +++ b/assets/mappings/0400-04FF-Cyrillic.yml @@ -0,0 +1,4 @@ + +# 0x0000 <- 0x0000 +0x0000: + ~: 0x0000 diff --git a/assets/cjk-radicals-supplement-mapping.yml b/assets/mappings/2E80-2EFF-CJK-Radicals-Supplement.yml similarity index 100% rename from assets/cjk-radicals-supplement-mapping.yml rename to assets/mappings/2E80-2EFF-CJK-Radicals-Supplement.yml diff --git a/assets/kangxi-radicals-mapping.yml b/assets/mappings/2F00-2FDF-Kangxi-Radicals.yml similarity index 100% rename from assets/kangxi-radicals-mapping.yml rename to assets/mappings/2F00-2FDF-Kangxi-Radicals.yml diff --git a/assets/mappings/Other.yml b/assets/mappings/Other.yml new file mode 100644 index 000000000..11a920a5b --- /dev/null +++ b/assets/mappings/Other.yml @@ -0,0 +1,4 @@ + +# 0x0000 +0x0000: + ~: 0x0000 diff --git a/tools/cli.py b/tools/cli.py index 75b37fe98..0165d272c 100644 --- a/tools/cli.py +++ b/tools/cli.py @@ -56,8 +56,12 @@ def main( logger.info("Delete dir: '{}'", path_define.build_dir) mappings = [ - glyph_mapping_util.load_mapping(path_define.assets_dir.joinpath('cjk-radicals-supplement-mapping.yml')), - glyph_mapping_util.load_mapping(path_define.assets_dir.joinpath('kangxi-radicals-mapping.yml')), + glyph_mapping_util.load_mapping(path_define.mappings_dir.joinpath('0180-024F-Latin-Extended-B.yml')), + glyph_mapping_util.load_mapping(path_define.mappings_dir.joinpath('0370-03FF-Greek-and-Coptic.yml')), + glyph_mapping_util.load_mapping(path_define.mappings_dir.joinpath('0400-04FF-Cyrillic.yml')), + glyph_mapping_util.load_mapping(path_define.mappings_dir.joinpath('2E80-2EFF-CJK-Radicals-Supplement.yml')), + glyph_mapping_util.load_mapping(path_define.mappings_dir.joinpath('2F00-2FDF-Kangxi-Radicals.yml')), + glyph_mapping_util.load_mapping(path_define.mappings_dir.joinpath('Other.yml')), ] font_configs = {} design_contexts = {} diff --git a/tools/configs/path_define.py b/tools/configs/path_define.py index f764780a8..71953c3e6 100644 --- a/tools/configs/path_define.py +++ b/tools/configs/path_define.py @@ -4,6 +4,7 @@ assets_dir = project_root_dir.joinpath('assets') glyphs_dir = assets_dir.joinpath('glyphs') +mappings_dir = assets_dir.joinpath('mappings') templates_dir = assets_dir.joinpath('templates') images_dir = assets_dir.joinpath('images') diff --git a/tools/format_mapping.py b/tools/format_mapping.py deleted file mode 100644 index a413e4d73..000000000 --- a/tools/format_mapping.py +++ /dev/null @@ -1,11 +0,0 @@ -from tools.configs import path_define -from tools.services import format_service - - -def main(): - format_service.format_mapping(path_define.assets_dir.joinpath('cjk-radicals-supplement-mapping.yml')) - format_service.format_mapping(path_define.assets_dir.joinpath('kangxi-radicals-mapping.yml')) - - -if __name__ == '__main__': - main() diff --git a/tools/format_mappings.py b/tools/format_mappings.py new file mode 100644 index 000000000..298d9f86c --- /dev/null +++ b/tools/format_mappings.py @@ -0,0 +1,14 @@ +from tools.configs import path_define +from tools.services import format_service + + +def main(): + for file_path in path_define.mappings_dir.iterdir(): + if file_path.suffix != '.yml': + continue + is_special = file_path.stem in ('0180-024F-Latin-Extended-B', '0370-03FF-Greek-and-Coptic', '0400-04FF-Cyrillic') + format_service.format_mapping(file_path, is_special) + + +if __name__ == '__main__': + main() diff --git a/tools/services/font_service.py b/tools/services/font_service.py index 14c737951..0b1499c06 100644 --- a/tools/services/font_service.py +++ b/tools/services/font_service.py @@ -23,9 +23,8 @@ def load(font_config: FontConfig, mappings: list[dict[int, SourceFlavorGroup]]) context = glyph_file_util.load_context(path_define.glyphs_dir.joinpath(str(font_config.font_size), width_mode_dir_name)) contexts[width_mode_dir_name] = context - if width_mode_dir_name == 'common': - for mapping in mappings: - glyph_mapping_util.apply_mapping(context, mapping) + for mapping in mappings: + glyph_mapping_util.apply_mapping(context, mapping) glyph_files = {} for width_mode in configs.width_modes: diff --git a/tools/services/format_service.py b/tools/services/format_service.py index 1d0bbce46..626198a61 100644 --- a/tools/services/format_service.py +++ b/tools/services/format_service.py @@ -1,5 +1,6 @@ import itertools import shutil +from io import StringIO from pathlib import Path from pixel_font_knife import glyph_file_util, glyph_mapping_util @@ -28,6 +29,22 @@ def format_glyphs(font_config: FontConfig): shutil.rmtree(file_dir) -def format_mapping(file_path: Path): +def format_mapping(file_path: Path, is_special: bool): mapping = glyph_mapping_util.load_mapping(file_path) - glyph_mapping_util.save_mapping(mapping, file_path, configs.language_flavors) + if is_special: + buffer = StringIO() + for code_point, source_group in sorted(mapping.items()): + c = chr(code_point) + if not c.isprintable(): + c = f'0x{code_point:04X}' + source_code_point = source_group[None].code_point + source_c = chr(source_code_point) + if not source_c.isprintable(): + source_c = f'0x{source_code_point:04X}' + buffer.write('\n') + buffer.write(f'# {c} <- {source_c}\n') + buffer.write(f'0x{code_point:04X}:\n') + buffer.write(f' ~: 0x{source_code_point:04X}\n') + file_path.write_text(buffer.getvalue(), 'utf-8') + else: + glyph_mapping_util.save_mapping(mapping, file_path, configs.language_flavors)