mirror of
https://github.com/Shu-Ying/main_plugin_farm.git
synced 2026-10-29 13:40:00 +08:00
add # 新增使用开源字体
This commit is contained in:
+15
-11
@@ -1,21 +1,25 @@
|
||||
"""为CI选择现有字体;部署仍须显式配置中文字体。"""
|
||||
"""预览与CI复用 service 字体缓存,不将大字体打入插件。"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
|
||||
def choose_font():
|
||||
configured = os.environ.get("FARM_TEST_FONT")
|
||||
candidates = ([configured] if configured else []) + [
|
||||
"C:/Windows/Fonts/msyh.ttc", "C:/Windows/Fonts/simsun.ttc",
|
||||
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
"C:/Windows/Fonts/arial.ttf",
|
||||
]
|
||||
for name in candidates:
|
||||
if Path(name).is_file():
|
||||
return name
|
||||
raise RuntimeError("Set FARM_TEST_FONT to an existing font")
|
||||
if configured:
|
||||
if not Path(configured).is_file():
|
||||
raise RuntimeError("FARM_TEST_FONT does not exist")
|
||||
return configured
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(root / "src"))
|
||||
from farm_render.font_bundle import FILES, _valid, ensure_font
|
||||
local = root.parent / "farm_service/fonts/Xiaolai-Regular.ttf"
|
||||
if _valid(local, *FILES[local.name]):
|
||||
return str(local)
|
||||
cache = Path(tempfile.gettempdir()) / "farm-preview-resources"
|
||||
return str(ensure_font(cache))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user