Files
lishanpi/tools/fix_font.py
T
hm 97f7d200a2 refactor: 将工具类文件迁移到 tools/ 目录
- 移动 10 个 Python 字体工具脚本到 tools/
- 移动 5 个 C 字体测试文件到 tools/
- 更新脚本路径引用适配新目录结构
- 清理 vue/vue3 前端模板文件
2026-05-07 17:10:39 +08:00

40 lines
1.5 KiB
Python

import re, os, glob
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
font_files = glob.glob(os.path.join(project_root, 'app/tasks/custom_cjk_*.c'))
for filepath in font_files:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
def fix_adv_w(match):
full_line = match.group(0)
adv_w = int(match.group(1))
box_w = int(match.group(2))
ofs_x = int(match.group(3)) if match.group(3) else 0
if adv_w >= 250 and box_w >= 10 and adv_w % 16 == 0:
new_adv_w = (box_w + ofs_x) * 16
return full_line.replace(f'adv_w = {adv_w}', f'adv_w = {new_adv_w}')
return full_line
pattern = r'\.adv_w = (\d+), \.box_w = (\d+)(?:, \.box_h = \d+)?(?:, \.ofs_x = (\d+))?'
fixed_content = re.sub(pattern, fix_adv_w, content)
with open(filepath, 'w', encoding='utf-8') as f:
f.write(fixed_content)
print(f"=== {os.path.basename(filepath)} ===")
original = content
changed_lines = []
for line_num, (orig_line, fix_line) in enumerate(zip(original.split('\n'), fixed_content.split('\n')), 1):
if orig_line != fix_line and 'adv_w' in fix_line:
orig_adv = re.search(r'adv_w = (\d+)', orig_line)
fix_adv = re.search(r'adv_w = (\d+)', fix_line)
if orig_adv and fix_adv:
changed_lines.append(f" L{line_num}: {orig_adv.group(1)} -> {fix_adv.group(1)}")
for l in changed_lines[:5]:
print(l)
print(f" Total changed: {len(changed_lines)}")
print()