fix(fonts): FONT_NAME_MAP改为Noto Sans SC适配容器实际字体 #1514

Merged
xiaoxia merged 1 commits from fix/font-name-map-noto-sans-sc into develop 2026-08-27 00:35:49 +08:00
6 changed files with 37 additions and 31 deletions
+25 -18
View File
@@ -26,13 +26,13 @@ TITLE_MARGIN_SIDE = 40
# 字体名称映射:前端中文字体名 → 服务器实际注册名(ffmpeg/ASS 通过注册名匹配字体)
FONT_NAME_MAP: dict[str, str] = {
"思源黑体": "Noto Sans CJK SC",
"思源黑体": "Noto Sans SC",
"思源宋体": "Noto Serif CJK SC",
"苹方": "Noto Sans CJK SC",
"PingFang": "Noto Sans CJK SC",
"微软雅黑": "Noto Sans CJK SC",
"苹方": "Noto Sans SC",
"PingFang": "Noto Sans SC",
"微软雅黑": "Noto Sans SC",
"楷体": "Noto Serif CJK SC",
"华康俪金黑": "Noto Sans CJK SC",
"华康俪金黑": "Noto Sans SC",
}
@@ -191,7 +191,6 @@ def format_ass_time(seconds: float) -> str:
# ── 完整 ASS 内容生成 ─────────────────────────────────────────────────────────
def _wrap_title_text(
text: str,
video_width: int,
@@ -282,20 +281,28 @@ def build_ass_content(
if title_config:
_stroke_val = title_config.get("stroke")
if isinstance(_stroke_val, bool):
title_config["stroke"] = {
"enabled": _stroke_val,
"color": "#000000",
"width": 2,
} if _stroke_val else {"enabled": False}
title_config["stroke"] = (
{
"enabled": _stroke_val,
"color": "#000000",
"width": 2,
}
if _stroke_val
else {"enabled": False}
)
_shadow_val = title_config.get("shadow")
if isinstance(_shadow_val, bool):
title_config["shadow"] = {
"enabled": _shadow_val,
"color": "#000000",
"blur": 4,
"offset_x": 2,
"offset_y": 2,
} if _shadow_val else {"enabled": False}
title_config["shadow"] = (
{
"enabled": _shadow_val,
"color": "#000000",
"blur": 4,
"offset_x": 2,
"offset_y": 2,
}
if _shadow_val
else {"enabled": False}
)
title_enabled = title_config.get("enabled", True) and bool(title_text.strip())
subtitle_enabled = subtitle_config.get("enabled", True) and bool(subtitle_text.strip())
+1
View File
@@ -15,6 +15,7 @@ logger = logging.getLogger(__name__)
# 按优先级查找 CJK 字体(Debian/Ubuntu fonts-noto-cjk 安装路径)
_FONT_CANDIDATES = (
"/usr/share/fonts/opentype/noto/NotoSansSC-VF.ttf",
"/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc",
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
"/usr/share/fonts/truetype/noto/NotoSansCJK-Bold.ttc",
+8 -10
View File
@@ -79,7 +79,7 @@ class TestBuildAssStyle:
def test_minimal_style(self):
result = build_ass_style("TestStyle")
assert result.startswith("Style: TestStyle,")
assert "Noto Sans CJK SC" in result
assert "Noto Sans SC" in result
assert ",48," in result
def test_custom_font_size(self):
@@ -152,21 +152,20 @@ class TestBuildAssStyle:
# Style: 行有 23 个字段(去掉 "Style: " 前缀后)
assert len(parts) == 23
def test_font_name_mapping_siyuan(self):
"""思源黑体 → Noto Sans CJK SC"""
"""思源黑体 → Noto Sans SC"""
result = build_ass_style("Test", font_name="思源黑体")
assert "Noto Sans CJK SC" in result
assert "Noto Sans SC" in result
def test_font_name_mapping_apple(self):
"""苹方 → Noto Sans CJK SC"""
"""苹方 → Noto Sans SC"""
result = build_ass_style("Test", font_name="苹方")
assert "Noto Sans CJK SC" in result
assert "Noto Sans SC" in result
def test_font_name_mapping_msyh(self):
"""微软雅黑 → Noto Sans CJK SC"""
"""微软雅黑 → Noto Sans SC"""
result = build_ass_style("Test", font_name="微软雅黑")
assert "Noto Sans CJK SC" in result
assert "Noto Sans SC" in result
def test_font_name_mapping_unknown_passthrough(self):
"""未映射字体原样使用"""
@@ -174,7 +173,6 @@ class TestBuildAssStyle:
assert "CustomFont" in result
# ── 文本转义 ──────────────────────────────────────────────────────────────────
@@ -483,6 +481,7 @@ class TestConstants:
def test_title_margin_side(self):
assert TITLE_MARGIN_SIDE == 40
# ── 标题自动换行 ──────────────────────────────────────────────────────────────
@@ -554,7 +553,6 @@ class TestWrapTitleText:
assert result == text
assert result.count("\\N") == 2
def test_build_ass_content_integration(self):
"""集成测试:build_ass_content 中的标题应该自动换行。"""
long_title = "这是一段非常长的标题文字用于测试自动换行功能是否正常工作"
+1 -1
View File
@@ -80,7 +80,7 @@ class TestBuildAssStyle:
def test_basic_style(self):
style = _build_ass_style("Default")
assert style.startswith("Style: Default,")
assert "Noto Sans CJK SC" in style
assert "Noto Sans SC" in style
assert "48" in style # font_size
def test_custom_font(self):
+1 -1
View File
@@ -84,7 +84,7 @@ class TestBuildAssStyle:
"""基本样式行包含关键字段."""
line = _build_ass_style("Default")
assert line.startswith("Style: Default,")
assert "Noto Sans CJK SC" in line
assert "Noto Sans SC" in line
assert "48" in line # font_size
def test_bold_enabled(self):
+1 -1
View File
@@ -230,7 +230,7 @@ class TestFullStyleConsistency:
fields = [f.strip() for f in style_line.split(",")]
# Fontname
assert fields[1] == "Noto Sans CJK SC"
assert fields[1] == "Noto Sans SC"
# Fontsize = 28
assert fields[2] == "28"
# Bold = -1 (True)