This commit is contained in:
949036910@qq.com
2026-06-02 22:48:18 +08:00
parent f091e17ca4
commit f9bccba872
21 changed files with 2386 additions and 68 deletions

View File

@@ -693,12 +693,13 @@ class AdvancedCoverGenerator:
print(f"Converted text position from string to dict: {text_position}", file=sys.stderr)
# 加载字体
font_path = self._get_font_path(font_family)
from modules.chinese_font import load_cjk_font
try:
font = ImageFont.truetype(font_path, font_size)
except:
print(f"Warning: Failed to load font {font_path}, using default", file=sys.stderr)
font = ImageFont.load_default()
font = load_cjk_font(font_family, font_size, font_weight)
except Exception as e:
print(f"Warning: Failed to load title font: {e}", file=sys.stderr)
font = load_cjk_font("SimHei", font_size, font_weight)
# ✅ 关键修复支持多行文字使用anchor='mm'实现中心对齐
# 计算文字中心点位置(百分比转像素)
@@ -949,8 +950,8 @@ class AdvancedCoverGenerator:
font_size = font_size_from_config
# 重新加载字体
try:
font = ImageFont.truetype(font_path, font_size)
except:
font = load_cjk_font(font_family, font_size, font_weight)
except Exception:
pass
# 获取排版参数 - 优先使用 titles.main 中的值,否则使用顶级配置,最后使用默认值
@@ -1391,12 +1392,15 @@ class AdvancedCoverGenerator:
print(f"Converted subtitle position from string to dict: {subtitle_position}", file=sys.stderr)
# 加载副标题字体
subtitle_font_path = self._get_font_path(subtitle_font_family)
from modules.chinese_font import load_cjk_font
try:
subtitle_font = ImageFont.truetype(subtitle_font_path, subtitle_font_size)
except:
print(f"Warning: Failed to load subtitle font {subtitle_font_path}, using default", file=sys.stderr)
subtitle_font = ImageFont.load_default()
subtitle_font = load_cjk_font(
subtitle_font_family, subtitle_font_size, subtitle_font_weight
)
except Exception as e:
print(f"Warning: Failed to load subtitle font: {e}", file=sys.stderr)
subtitle_font = load_cjk_font("SimHei", subtitle_font_size, subtitle_font_weight)
# 计算副标题中心点位置(百分比转像素)
# ✅ 修复旋转坐标问题有旋转时Y轴需要反转无旋转时不需要
@@ -1442,8 +1446,14 @@ class AdvancedCoverGenerator:
subtitle_font_size = subtitle_font_size_from_config
# 重新加载字体
try:
subtitle_font = ImageFont.truetype(subtitle_font_path, subtitle_font_size)
except:
from modules.chinese_font import load_cjk_font
subtitle_font = load_cjk_font(
subtitle_font_family,
subtitle_font_size,
subtitle_font_weight,
)
except Exception:
pass
# 获取排版参数 - 优先使用 titles.sub 中的值,否则使用顶级配置,最后使用默认值
@@ -1937,13 +1947,13 @@ class AdvancedCoverGenerator:
break
# 如果还是找不到,使用默认字体
if not font_path or not os.path.exists(font_path):
print(f"Warning: Font file not found for '{font_family}', using fallback", file=sys.stderr)
if font_path:
print(f" Attempted path: {font_path}", file=sys.stderr)
return 'C:\\Windows\\Fonts\\msyh.ttc'
return font_path
try:
from modules.chinese_font import resolve_cjk_font_path
return resolve_cjk_font_path(font_family, 400)
except Exception as e:
print(f"Warning: _get_font_path fallback: {e}", file=sys.stderr)
return str(Path(os.environ.get("WINDIR", "C:/Windows")) / "Fonts" / "simhei.ttf")
# ✅ 标准封面尺寸 3:4 比例(与前端 CoverCustomEditor.vue 一致)
COVER_WIDTH = 1080