From 29995a64fd227064a6f79422b2acee69668ff23f Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 19 Jul 2026 22:56:21 +0800 Subject: [PATCH] fix(transcode): add fontName to Linux TTC fonts, Windows CJK paths, and Droid fallback --- AGENTS.md | 3 +- packages/core/src/transcode/transcode.ts | 40 +++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 54525bab..da343a30 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -141,8 +141,7 @@ We follow Bun's monorepo conventions for dependency management: 3. **Local DevDependencies**: Tools specific to a single package (e.g., `@vitejs/plugin-react` for `webui`) should be declared in that package's local `package.json`. 4. **Workspace Imports**: Use `workspace:*` for internal package dependencies. 5. **Clean Root**: The root `package.json` must not contain runtime `dependencies`. It is reserved for shared `devDependencies` and workspace-wide `scripts`. -6. **Installation**: Always run `bun install` from the root. Use the `--filter` flag if you only want to update a specific package (e.g., `bun install --filter @shumai/webui`). -7. **Adding Packages**: Never edit `package.json` manually to add new dependencies. Always use `bun add` (e.g., `bun add --filter `) without specifying an explicit version, letting Bun resolve the correct version. +6. **Adding Packages**: Never edit `package.json` manually to add new dependencies. Always use `bun add` (e.g., `bun add --filter `) from the root without specifying an explicit version, letting Bun resolve the correct version. ## TypeScript Configuration diff --git a/packages/core/src/transcode/transcode.ts b/packages/core/src/transcode/transcode.ts index 0261da03..a1059da6 100644 --- a/packages/core/src/transcode/transcode.ts +++ b/packages/core/src/transcode/transcode.ts @@ -21,18 +21,44 @@ export interface CjkFontConfig { } export function findCjkFontPath(): CjkFontConfig | undefined { - if (process.env.PDF_CJK_FONT_PATH && fs.existsSync(process.env.PDF_CJK_FONT_PATH)) { - return { fontPath: process.env.PDF_CJK_FONT_PATH } - } const candidates: { fontPath: string; fontName?: string }[] = [ + // Custom env override + ...(process.env.PDF_CJK_FONT_PATH + ? [ + { + fontPath: process.env.PDF_CJK_FONT_PATH, + fontName: process.env.PDF_CJK_FONT_NAME, + }, + ] + : []), + // macOS { fontPath: '/System/Library/Fonts/Supplemental/Arial Unicode.ttf' }, { fontPath: '/Library/Fonts/Arial Unicode.ttf' }, { fontPath: '/System/Library/Fonts/PingFang.ttc', fontName: 'PingFangSC-Regular' }, { fontPath: '/System/Library/Fonts/STHeiti Light.ttc', fontName: 'STHeitiSC-Light' }, - { fontPath: '/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc' }, - { fontPath: '/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc' }, - { fontPath: '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc' }, - { fontPath: '/usr/share/fonts/truetype/arphic/ukai.ttc' }, + // Linux / Ubuntu / Debian Noto & WenQuanYi CJK + { + fontPath: '/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc', + fontName: 'NotoSansCJKsc-Regular', + }, + { + fontPath: '/usr/share/fonts/truetype/noto/NotoSansCJK-Regular.ttc', + fontName: 'NotoSansCJKsc-Regular', + }, + { fontPath: '/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc', fontName: 'WenQuanYiZenHei' }, + { fontPath: '/usr/share/fonts/truetype/arphic/ukai.ttc', fontName: 'AR-PL-UKai-CN' }, + { + fontPath: '/usr/share/fonts/noto/NotoSansCJK-Regular.ttc', + fontName: 'Noto Sans CJK SC', + }, + // Lightweight Linux / Docker Droid Fallbacks + { fontPath: '/usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf' }, + { fontPath: '/usr/share/fonts/truetype/droid/DroidSansFallback.ttf' }, + { fontPath: '/usr/share/fonts/google-droid/DroidSansFallback.ttf' }, + // Windows CJK Fonts + { fontPath: 'C:\\Windows\\Fonts\\msyh.ttc', fontName: 'MicrosoftYaHei' }, + { fontPath: 'C:\\Windows\\Fonts\\simsun.ttc', fontName: 'SimSun' }, + { fontPath: 'C:\\Windows\\Fonts\\simhei.ttf' }, ] for (const item of candidates) { if (fs.existsSync(item.fontPath)) {