路径跨平台兼容优化 - 修改相对路径,兼容Windows/Linux/Mac
This commit is contained in:
16
config.py
16
config.py
@@ -123,14 +123,21 @@ DB_CONNECTION_STRING = os.getenv("DB_CONNECTION_STRING", f"sqlite:///{BASE_DIR}/
|
||||
# ============================================================
|
||||
# 优先检测系统字体,防止乱码
|
||||
SYSTEM_FONTS = [
|
||||
str(FONTS_DIR / "SmileySans-Oblique.otf"),
|
||||
# 项目内置字体 (跨平台通用,优先使用)
|
||||
str(FONTS_DIR / "NotoSansSC-Regular.otf"),
|
||||
str(FONTS_DIR / "HarmonyOS-Sans-SC-Regular.ttf"),
|
||||
str(FONTS_DIR / "HarmonyOS-Sans-SC-Bold.ttf"),
|
||||
str(FONTS_DIR / "NotoSansSC-Regular.otf"),
|
||||
str(FONTS_DIR / "NotoSansSC-Bold.otf"),
|
||||
str(FONTS_DIR / "SmileySans-Oblique.otf"),
|
||||
# Linux 系统字体
|
||||
"/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf",
|
||||
"/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc",
|
||||
# macOS 系统字体
|
||||
"/System/Library/Fonts/PingFang.ttc",
|
||||
"/System/Library/Fonts/STHeiti Medium.ttc",
|
||||
"/System/Library/Fonts/Supplemental/Arial Unicode.ttf",
|
||||
# Windows 系统字体
|
||||
"C:/Windows/Fonts/msyh.ttc",
|
||||
"C:/Windows/Fonts/simhei.ttf",
|
||||
]
|
||||
|
||||
DEFAULT_FONT = str(FONTS_DIR / "NotoSansSC-Regular.otf")
|
||||
@@ -141,7 +148,8 @@ def pick_font():
|
||||
for f in SYSTEM_FONTS:
|
||||
if os.path.exists(f) and os.path.getsize(f) > 1000:
|
||||
return f
|
||||
return "/System/Library/Fonts/PingFang.ttc"
|
||||
# 极端情况回退到 Arial (所有平台都有)
|
||||
return "Arial"
|
||||
|
||||
DEFAULT_FONT = pick_font()
|
||||
DEFAULT_FONT_BOLD = DEFAULT_FONT
|
||||
|
||||
Reference in New Issue
Block a user