新增 ttf 随机选择和提示

This commit is contained in:
崮生(子虚) 2026-04-09 12:02:37 +08:00
parent e2cc7c1144
commit 55aa492ce0
2 changed files with 9 additions and 2 deletions

View File

@ -111,8 +111,9 @@ function App() {
set_outType(config.supportedOutTypes?.[0] || "ttf");
}
if (fontList.length > 0) {
/** 标语随机使用一个字体展示 */
const randomFont = fontList[Math.floor(Math.random() * fontList.length)];
/** 标语随机使用一个 TTF 字体展示(目前仅 TTF 格式兼容性最佳) */
const ttfFonts = fontList.filter((f) => /\.ttf$/i.test(f.name));
const randomFont = (ttfFonts.length > 0 ? ttfFonts : fontList)[Math.floor(Math.random() * (ttfFonts.length > 0 ? ttfFonts : fontList).length)];
(globalThis as any).WebFont?.loadText({
fontName: randomFont.name,
text: SLOGAN,

View File

@ -3,6 +3,9 @@ import { uploadFont, type UploadResult, type ServerConfig } from "./api";
const ACCEPT = ".ttf,.otf,.woff,.woff2";
/** 目前仅 TTF 格式兼容性最佳,上传其他格式可能无法正常使用 */
const UPLOAD_TIP = "当前仅 TTF 格式兼容性最佳,建议上传 .ttf 字体文件";
const btn = {
padding: "6px 20px",
"font-size": "14px",
@ -173,6 +176,9 @@ export default function UploadSection(props: { config: ServerConfig; onUploaded:
<Show when={canUpload()}>
<section style={section}>
<label style={{ ...label, "font-size": "14px", "font-weight": 500, "margin-bottom": "12px" }}></label>
<div style={{ "font-size": "12px", color: "#e6a700", "margin-bottom": "12px" }}>
{UPLOAD_TIP}
</div>
<Show when={temp.msg()}>
{(m) => (