feat: 添加古风官职特殊字符 + 优化字体子集化脚本

字符添加:
- 添加破折号(—)
- 添加庶、尉、谏、簿、丞
- 确保古风官职文本完整显示

脚本优化:
- 修改subset-font-safe.py,保留现有字符
- 合并新提取的字符,避免覆盖手动添加的字符
- 字体大小:740.7 KB(减少39.6%)
This commit is contained in:
Vaica committed 2026-06-03 14:53:56 +08:00
1 parent 5eee9e5753
commit 80940b0316
6 files changed
+144 -11

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
"""
添加古风官职缺失字符到字体子集
"""
import os
# 缺失的字符
missing_chars = ['—', '庶', '尉', '谏', '簿', '丞']
print("🔧 添加古风官职缺失字符")
print("=" * 60)
# 读取现有字符
chars_file = "themes/Ying/static/font/used_chars.txt"
with open(chars_file, 'r', encoding='utf-8') as f:
existing_chars = set(f.read())
print(f"📊 现有字符数: {len(existing_chars)}")
# 检查哪些字符真正缺失
chars_to_add = []
for char in missing_chars:
if char not in existing_chars:
chars_to_add.append(char)
print(f"➕ 需要添加: '{char}'")
else:
print(f"✅ 已存在: '{char}'")
# 添加缺失字符
if chars_to_add:
# 添加到字符集合
all_chars = existing_chars | set(chars_to_add)
# 保存更新后的字符列表
with open(chars_file, 'w', encoding='utf-8') as f:
f.write(''.join(sorted(all_chars)))
print(f"\n✅ 已添加 {len(chars_to_add)} 个字符")
print(f"📊 更新后字符数: {len(all_chars)}")
print(f"\n📝 添加的字符: {''.join(chars_to_add)}")
else:
print("\n✅ 所有字符都已存在,无需添加")
print(f"\n✅ 字符列表已更新: {chars_file}")
+23 -10
View File
@@ -139,6 +139,7 @@ def main():
# 配置路径
font_dir = "themes/Ying/static/font"
input_font = os.path.join(font_dir, "zql-v2.woff2")
chars_file = os.path.join(font_dir, "used_chars.txt")
# 检查输入文件
if not os.path.exists(input_font):
@@ -146,7 +147,16 @@ def main():
print(f" 请确保在博客根目录运行此脚本")
sys.exit(1)
# 扫描目录(只扫描实际使用的目录)
# 读取现有的字符列表(如果存在)
existing_chars = set()
if os.path.exists(chars_file):
with open(chars_file, 'r', encoding='utf-8') as f:
existing_chars = set(f.read())
print(f"📖 读取现有字符: {len(existing_chars)} 个")
else:
print(f"⚠️ 现有字符文件不存在,将创建新文件")
# 扫描目录
scan_dirs = ["content", "layouts"]
# 检查public目录是否存在
@@ -160,35 +170,38 @@ def main():
print(f"\n🔍 扫描目录: {', '.join(scan_dirs)}")
# 提取字符
chars = extract_chars_from_files(scan_dirs)
print(f"\n📝 提取了 {len(chars)} 个唯一字符")
new_chars = extract_chars_from_files(scan_dirs)
print(f"\n📝 从文件中提取了 {len(new_chars)} 个唯一字符")
if len(chars) == 0:
# 合并字符(保留现有字符 + 新提取的字符)
all_chars = existing_chars | new_chars
print(f"📊 合并后字符数: {len(all_chars)}")
if len(all_chars) == 0:
print("❌ 未找到任何字符,请检查扫描目录")
sys.exit(1)
# 保存字符列表(用于调试)
chars_file = os.path.join(font_dir, "used_chars.txt")
# 保存合并后的字符列表
with open(chars_file, 'w', encoding='utf-8') as f:
sorted_chars = sorted(chars)
sorted_chars = sorted(all_chars)
f.write(''.join(sorted_chars))
print(f"💾 字符列表已保存到: {chars_file}")
# 显示部分字符(用于验证)
sample_chars = sorted(list(chars))[:50]
sample_chars = sorted(list(all_chars))[:50]
print(f"📋 前50个字符: {''.join(sample_chars)}")
# 生成woff2子集字体
output_woff2 = os.path.join(font_dir, "zql-v2-subset.woff2")
print(f"\n{'='*50}")
print(f"🎯 生成 woff2 子集字体...")
success_woff2 = subset_font(input_font, output_woff2, chars)
success_woff2 = subset_font(input_font, output_woff2, all_chars)
# 生成woff子集字体
output_woff = os.path.join(font_dir, "zql-v2-subset.woff")
print(f"\n{'='*50}")
print(f"🎯 生成 woff 子集字体...")
success_woff = subset_font(input_font, output_woff, chars)
success_woff = subset_font(input_font, output_woff, all_chars)
# 总结
print(f"\n{'='*50}")
+75
View File
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
"""
验证古风官职字符是否在字体子集中
"""
# 需要验证的古风官职字符
ancient_chars = [
'—', # 破折号
'庶', # 庶民
'民', # 庶民
'太', # 太师、太尉
'尉', # 太尉
'谏', # 谏议大夫
'给', # 给事中
'簿', # 主簿
'司', # 司户参军
'户', # 司户参军
'录', # 录事参军
'丞', # 御史中丞
'判', # 通判
'殿', # 殿中侍御史
]
# 读取字符列表
with open("themes/Ying/static/font/used_chars.txt", 'r', encoding='utf-8') as f:
existing_chars = set(f.read())
print("🔍 验证古风官职字符是否在字体子集中")
print("=" * 60)
# 检查每个字符
found_chars = []
missing_chars = []
for char in ancient_chars:
if char in existing_chars:
found_chars.append(char)
print(f"✅ '{char}' - 已存在")
else:
missing_chars.append(char)
print(f"❌ '{char}' - 缺失")
print("\n" + "=" * 60)
print(f"📊 验证结果:")
print(f" ✅ 已存在: {len(found_chars)} 个字符")
print(f" ❌ 缺失: {len(missing_chars)} 个字符")
if missing_chars:
print(f"\n⚠️ 缺失的字符: {''.join(missing_chars)}")
print(f"\n💡 需要将这些字符添加到 used_chars.txt")
else:
print(f"\n🎉 所有古风官职字符都已存在!")
# 显示完整的古风官职文本
print("\n" + "=" * 60)
print("📜 古风官职文本:")
print("正一品 太师 2000")
print("从一品 太尉 1400")
print("正二品 参知政事 1050")
print("从二品 节度使 800")
print("正三品 御史中丞 600")
print("从三品 秘书监 480")
print("正四品 谏议大夫 380")
print("从四品 侍读学士 300")
print("正五品 给事中 240")
print("从五品 知州 190")
print("正六品 侍御史 150")
print("从六品 通判 115")
print("正七品 知县 85")
print("从七品 殿中侍御史 60")
print("正八品 大理评事 40")
print("从八品 录事参军 25")
print("正九品 主簿 15")
print("从九品 司户参军 5")
print("— 庶民 0")