Skip to content

Commit

Permalink
字形参数配置改为使用 yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
TakWolf committed Jul 3, 2024
1 parent af51821 commit 64ace6c
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 67 deletions.
8 changes: 4 additions & 4 deletions assets/fonts/ark-pixel/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sha": "e98678f4b5b03d99e1f00eb4d02e2dfba90e0b5a",
"version": "2024.05.12",
"version_url": "https://github.com/TakWolf/ark-pixel-font/tree/2024.05.12",
"asset_url": "https://github.com/TakWolf/ark-pixel-font/archive/e98678f4b5b03d99e1f00eb4d02e2dfba90e0b5a.zip"
"sha": "45e860d6fa8498a86c0b1fd1100c9655c5cc9a26",
"version": "develop",
"version_url": "https://github.com/TakWolf/ark-pixel-font/tree/develop",
"asset_url": "https://github.com/TakWolf/ark-pixel-font/archive/45e860d6fa8498a86c0b1fd1100c9655c5cc9a26.zip"
}
14 changes: 0 additions & 14 deletions assets/patch-glyphs/10/config.toml

This file was deleted.

11 changes: 11 additions & 0 deletions assets/patch-glyphs/10/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
monospaced:
ascent: 9
descent: -1
x-height: 5
cap-height: 7

proportional:
ascent: 12
descent: -4
x-height: 5
cap-height: 7
14 changes: 0 additions & 14 deletions assets/patch-glyphs/12/config.toml

This file was deleted.

11 changes: 11 additions & 0 deletions assets/patch-glyphs/12/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
monospaced:
ascent: 10
descent: -2
x-height: 6
cap-height: 8

proportional:
ascent: 14
descent: -4
x-height: 6
cap-height: 9
14 changes: 0 additions & 14 deletions assets/patch-glyphs/8/config.toml

This file was deleted.

11 changes: 11 additions & 0 deletions assets/patch-glyphs/8/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
monospaced:
ascent: 7
descent: -1
x-height: 4
cap-height: 6

proportional:
ascent: 9
descent: -3
x-height: 4
cap-height: 6
19 changes: 6 additions & 13 deletions tools/configs/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,17 @@ def load_all() -> dict[int, 'FontConfig']:

@staticmethod
def load(font_size: int) -> 'FontConfig':
file_path = path_define.patch_glyphs_dir.joinpath(str(font_size), 'config.toml')
config_data = fs_util.read_toml(file_path)['font']
assert font_size == config_data['size'], f"Config 'size' error: '{file_path}'"
file_path = path_define.patch_glyphs_dir.joinpath(str(font_size), 'config.yaml')
config_data = fs_util.read_yaml(file_path)

layout_params = {}
for width_mode in configs.width_modes:
layout_param_data = config_data[width_mode]
layout_param = LayoutParam(
for width_mode, layout_param_data in config_data.items():
layout_params[width_mode] = LayoutParam(
layout_param_data['ascent'],
layout_param_data['descent'],
layout_param_data['x_height'],
layout_param_data['cap_height'],
layout_param_data['x-height'],
layout_param_data['cap-height'],
)
if width_mode == 'monospaced':
assert layout_param.line_height == font_size, f"Config 'monospaced.line_height' error: '{file_path}'"
else:
assert (layout_param.line_height - font_size) % 2 == 0, f"Config 'proportional.line_height' error: '{file_path}'"
layout_params[width_mode] = layout_param

return FontConfig(font_size, layout_params)

Expand Down
8 changes: 5 additions & 3 deletions tools/services/update_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def setup_ark_pixel_glyphs():
continue
shutil.copytree(source_glyphs_dir_from, source_glyphs_dir_to)

config_file_path_from = path_define.ark_pixel_glyphs_dir.joinpath(str(font_size), 'config.toml')
config_file_path_to = path_define.patch_glyphs_dir.joinpath(str(font_size), 'config.toml')
os.remove(config_file_path_to)
config_file_path_from = path_define.ark_pixel_glyphs_dir.joinpath(str(font_size), 'config.yaml')
config_file_path_to = path_define.patch_glyphs_dir.joinpath(str(font_size), 'config.yaml')
if config_file_path_to.exists():
os.remove(config_file_path_to)
config_file_path_to.parent.mkdir(parents=True, exist_ok=True)
config_file_path_from.rename(config_file_path_to)

license_path_from = source_unzip_dir.joinpath('LICENSE-OFL')
Expand Down
5 changes: 0 additions & 5 deletions tools/utils/fs_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import shutil
import tomllib
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -28,9 +27,5 @@ def write_json(data: Any, path: Path):
path.write_text(f'{json.dumps(data, indent=2, ensure_ascii=False)}\n', 'utf-8')


def read_toml(path: Path) -> Any:
return tomllib.loads(path.read_text('utf-8'))


def read_yaml(path: Path) -> Any:
return yaml.safe_load(path.read_text('utf-8'))

0 comments on commit 64ace6c

Please sign in to comment.