fix: 优化配置、修复测试和 temp_pdf 中文字体支持
- 优化 config.py,为所有依赖添加版本号,为所有文件类型添加 Darwin-x86_64 配置 - 修改 run_tests.py,添加平台相关 TEST_FIXTURE_DEPENDENCIES,简化 cli 和 all 测试逻辑 - 修复 tests/conftest.py 中 temp_pdf 的中文字体支持,使用 macOS 系统字体 - 更新 tests/test_core/test_advice_generator.py 以适应 Python 3.12 的默认配置 - 更新 openspec 相关规格文档
This commit is contained in:
@@ -105,11 +105,29 @@ def temp_pdf(tmp_path):
|
||||
c = canvas.Canvas(str(file_path), pagesize=letter)
|
||||
|
||||
# 尝试注册中文字体(如果可用)
|
||||
font_loaded = False
|
||||
try:
|
||||
# 使用系统字体
|
||||
pdfmetrics.registerFont(TTFont('SimSun', 'simsun.ttc'))
|
||||
c.setFont('SimSun', 12)
|
||||
# 尝试 macOS 中文字体
|
||||
for font_name, font_path, font_index in [
|
||||
('PingFangSC', '/System/Library/Fonts/PingFang.ttc', 0),
|
||||
('STHeiti', '/System/Library/Fonts/STHeiti Light.ttc', 0),
|
||||
('STHeitiMedium', '/System/Library/Fonts/STHeiti Medium.ttc', 0),
|
||||
]:
|
||||
try:
|
||||
from reportlab.pdfbase.ttfonts import TTFont
|
||||
import os
|
||||
if os.path.exists(font_path):
|
||||
# For TTC files, we need to specify the font index
|
||||
pdfmetrics.registerFont(TTFont(font_name, font_path, subfontIndex=font_index))
|
||||
c.setFont(font_name, 12)
|
||||
font_loaded = True
|
||||
break
|
||||
except Exception as e:
|
||||
continue
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not font_loaded:
|
||||
# 回退到默认字体
|
||||
c.setFont('Helvetica', 12)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user