feat: 拼音字母选择

This commit is contained in:
R524809
2026-05-19 18:24:43 +08:00
parent 39b8e01c23
commit b70e54d6b0
40 changed files with 1197 additions and 759 deletions
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
"""从 ToneOZ-Pinyin-WenKai-Regular.ttf 中提取拼音/字母/数字字符,生成新的字体文件。"""
from fontTools.ttLib import TTFont
from fontTools.subset import Subsetter
from pathlib import Path
BASE = Path(__file__).resolve().parent
INPUT = BASE / "input-fonts" / "ToneOZ-Pinyin-WenKai-Regular.ttf"
OUTPUT = BASE / "output-fonts" / "ToneOZ-Pinyin-Kai-Regular.ttf"
# Unicode 码点范围
RANGES = [
(0x0020, 0x007E), # 基本 ASCII(字母、数字、标点)
(0x00C0, 0x00FF), # 拉丁字母-1 补充
(0x0100, 0x017F), # 拉丁字母扩展 A
(0x01D6, 0x01DC), # ü 的四个声调变体
]
def build_unicodes():
codepoints = set()
for start, end in RANGES:
for cp in range(start, end + 1):
codepoints.add(cp)
return sorted(codepoints)
def main():
font = TTFont(INPUT)
unicodes = build_unicodes()
# 使用 fonttools Subsetter 提取指定字符
sub = Subsetter()
sub.populate(unicodes=unicodes)
sub.subset(font)
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
font.save(OUTPUT)
print(f"提取完成: {OUTPUT}")
print(f"包含 {len(unicodes)} 个码点")
# 输出范围统计
for start, end in RANGES:
name = f"U+{start:04X}-U+{end:04X}"
glyphs_in_range = sum(
1 for cp in range(start, end + 1) if cp in set(unicodes)
)
print(f" {name}: {glyphs_in_range} 个字符")
if __name__ == "__main__":
main()