diff --git a/backend/app.ts b/backend/app.ts index ab23543..1f5fe2a 100644 --- a/backend/app.ts +++ b/backend/app.ts @@ -199,14 +199,12 @@ async function handleListFonts(req: Request, res: Response) { /** GET /api/config — 返回公开配置 */ async function handleGetConfig(req: Request, res: Response) { - const isLlrt = release_name === "llrt"; return { req, res: jsonResponse({ enableTempUpload, adminUploadEnabled: !!adminApiKey, - /** LLRT 不支持 wasm,无法输出 woff2 */ - supportedOutTypes: isLlrt ? ["ttf"] : ["woff2", "ttf"], + supportedOutTypes: ["woff2", "ttf"], }), }; } @@ -314,12 +312,9 @@ async function handleFontSubset(req: Request, res: Response) { }; } - /** 默认 ttf(兼容性最好);LLRT 不支持 wasm 只能用 ttf */ - const isLlrt = release_name === "llrt"; + /** 默认 ttf(兼容性最好) */ const outTypeParam = params.get("outType") || ""; - const outType = (outTypeParam === "woff2" || outTypeParam === "ttf") - ? (isLlrt && outTypeParam === "woff2" ? "ttf" : outTypeParam) - : "ttf"; + const outType = (outTypeParam === "woff2" || outTypeParam === "ttf") ? outTypeParam : "ttf"; const newFont = await fontSubset(oldFontBuffer, text, { outType: outType, diff --git a/scripts/build-backend.ts b/scripts/build-backend.ts index a6a3b7c..2dd0a1d 100644 --- a/scripts/build-backend.ts +++ b/scripts/build-backend.ts @@ -6,7 +6,7 @@ */ import { execSync } from "node:child_process"; import { existsSync } from "node:fs"; -import { copyFile, mkdir, writeFile, rm } from "node:fs/promises"; +import { mkdir, writeFile, rm } from "node:fs/promises"; import { arch, platform } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -100,13 +100,7 @@ function runTsup() { execSync("pnpm tsup", { stdio: "inherit", cwd: ROOT_DIR }); } -/** 复制 woff2.wasm 到 tsup 输出目录(打包后 __dirname 指向此处) */ -async function copyWoff2Wasm() { - const src = join(ROOT_DIR, "vendor/fonteditor-core/woff2/woff2.wasm"); - const dst = join(ROOT_DIR, "dist_backend/backend/woff2.wasm"); - await copyFile(src, dst); - console.log("Copied woff2.wasm to dist_backend/backend/"); -} +/** woff2 已使用纯 JS 实现(vendor/fonteditor-core/woff2/index.js),无需复制 wasm */ /** 使用 LLRT compile 生成 .lrt 文件 */ function runLlrtCompile() { @@ -126,7 +120,6 @@ function runLlrtCompile() { async function main() { await ensureLlrt(); runTsup(); - await copyWoff2Wasm(); runLlrtCompile(); } diff --git a/vendor/fonteditor-core/woff2/woff2-encode.js b/vendor/fonteditor-core/woff2/woff2-encode.js index 9d59e4f..12d984f 100644 --- a/vendor/fonteditor-core/woff2/woff2-encode.js +++ b/vendor/fonteditor-core/woff2/woff2-encode.js @@ -14,14 +14,17 @@ try { zlib = require("zlib"); } const brotliCompressSync = zlib.brotliCompressSync; -const constants = zlib.constants; + +/** LLRT 的 zlib 没有 constants,直接使用数值常量(与 Node.js zlib.constants 一致) */ +const BROTLI_PARAM_QUALITY = zlib.constants?.BROTLI_PARAM_QUALITY ?? 3; +const BROTLI_PARAM_SIZE_HINT = zlib.constants?.BROTLI_PARAM_SIZE_HINT ?? 4; /** * Brotli 压缩参数:quality 8 * 测试表明 FONT 模式对小数据集(<200KB)无速度优势且增加 0.14% 体积,保持 GENERIC */ const BROTLI_OPTIONS_BASE = { - params: { [constants.BROTLI_PARAM_QUALITY]: 8 }, + params: { [BROTLI_PARAM_QUALITY]: 8 }, }; /* ======== Known Table Tags 索引表 ======== */ @@ -757,8 +760,8 @@ function encodeTTFToWOFF2(ttfBuffer) { /* Brotli 压缩,传入 SIZE_HINT 帮助预分配内部缓冲区 */ const brotliOptions = totalTableDataSize > 0 ? { params: { - [constants.BROTLI_PARAM_QUALITY]: 8, - [constants.BROTLI_PARAM_SIZE_HINT]: totalTableDataSize, + [BROTLI_PARAM_QUALITY]: 8, + [BROTLI_PARAM_SIZE_HINT]: totalTableDataSize, }} : BROTLI_OPTIONS_BASE; const compressedData = brotliCompressSync(uncompressedData, brotliOptions);