mirror of
https://github.com/2234839/web-font.git
synced 2026-07-12 19:51:07 +08:00
新增 ttf 随机选择和提示
This commit is contained in:
parent
e2cc7c1144
commit
55aa492ce0
@ -111,8 +111,9 @@ function App() {
|
|||||||
set_outType(config.supportedOutTypes?.[0] || "ttf");
|
set_outType(config.supportedOutTypes?.[0] || "ttf");
|
||||||
}
|
}
|
||||||
if (fontList.length > 0) {
|
if (fontList.length > 0) {
|
||||||
/** 标语随机使用一个字体展示 */
|
/** 标语随机使用一个 TTF 字体展示(目前仅 TTF 格式兼容性最佳) */
|
||||||
const randomFont = fontList[Math.floor(Math.random() * fontList.length)];
|
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({
|
(globalThis as any).WebFont?.loadText({
|
||||||
fontName: randomFont.name,
|
fontName: randomFont.name,
|
||||||
text: SLOGAN,
|
text: SLOGAN,
|
||||||
|
|||||||
@ -3,6 +3,9 @@ import { uploadFont, type UploadResult, type ServerConfig } from "./api";
|
|||||||
|
|
||||||
const ACCEPT = ".ttf,.otf,.woff,.woff2";
|
const ACCEPT = ".ttf,.otf,.woff,.woff2";
|
||||||
|
|
||||||
|
/** 目前仅 TTF 格式兼容性最佳,上传其他格式可能无法正常使用 */
|
||||||
|
const UPLOAD_TIP = "当前仅 TTF 格式兼容性最佳,建议上传 .ttf 字体文件";
|
||||||
|
|
||||||
const btn = {
|
const btn = {
|
||||||
padding: "6px 20px",
|
padding: "6px 20px",
|
||||||
"font-size": "14px",
|
"font-size": "14px",
|
||||||
@ -173,6 +176,9 @@ export default function UploadSection(props: { config: ServerConfig; onUploaded:
|
|||||||
<Show when={canUpload()}>
|
<Show when={canUpload()}>
|
||||||
<section style={section}>
|
<section style={section}>
|
||||||
<label style={{ ...label, "font-size": "14px", "font-weight": 500, "margin-bottom": "12px" }}>上传字体</label>
|
<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()}>
|
<Show when={temp.msg()}>
|
||||||
{(m) => (
|
{(m) => (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user