Skip to content

Commit

Permalink
调整 mapping 文件目录
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Nov 25, 2024
1 parent 3591159 commit 4b5b0e8
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 18 deletions.
4 changes: 4 additions & 0 deletions assets/mappings/0180-024F-Latin-Extended-B.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# 0x0000 <- 0x0000
0x0000:
~: 0x0000
4 changes: 4 additions & 0 deletions assets/mappings/0370-03FF-Greek-and-Coptic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# 0x0000 <- 0x0000
0x0000:
~: 0x0000
4 changes: 4 additions & 0 deletions assets/mappings/0400-04FF-Cyrillic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# 0x0000 <- 0x0000
0x0000:
~: 0x0000
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions assets/mappings/Other.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# 0x0000
0x0000:
~: 0x0000
8 changes: 6 additions & 2 deletions tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions tools/configs/path_define.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
11 changes: 0 additions & 11 deletions tools/format_mapping.py

This file was deleted.

14 changes: 14 additions & 0 deletions tools/format_mappings.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 2 additions & 3 deletions tools/services/font_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 19 additions & 2 deletions tools/services/format_service.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 4b5b0e8

Please sign in to comment.