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

+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}")