diff --git a/compose.yaml b/compose.yaml index 5b26ff8..500e260 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,6 +5,7 @@ services: # dockerfile: Debian.Dockerfile volumes: - ./data:/app/data + # - /usr/share/fonts/truetype/chinese:/usr/share/fonts/truetype/chinese:ro # mount Chinese fonts from host (optional) environment: # Defaults are listed below. All are optional. - ACCOUNT_REGISTRATION=true # true or false, doesn't matter for the first account (e.g. keep this to false if you only want one account) - JWT_SECRET=aLongAndSecretStringUsedToSignTheJSONWebToken1234 # will use randomUUID() by default @@ -16,5 +17,8 @@ services: # - HIDE_HISTORY=true # hides the history tab in the web interface, defaults to false - TZ=Europe/Stockholm # set your timezone, defaults to UTC # - UNAUTHENTICATED_USER_SHARING=true # for use with ALLOW_UNAUTHENTICATED=true to share history with all unauthenticated users / devices + # - PANDOC_ENABLE_CHINESE_FONT=true # enable Chinese font support for Pandoc PDF/LaTeX conversion + # - PANDOC_CHINESE_FONT_PATH=/usr/share/fonts/truetype/chinese # path to Chinese font directory on host + # - PANDOC_CHINESE_FONT_FAMILY=NotoSansCJK # Chinese font family name ports: - 3000:3000 diff --git a/src/converters/pandoc.ts b/src/converters/pandoc.ts index c14c98b..6efcdd1 100644 --- a/src/converters/pandoc.ts +++ b/src/converters/pandoc.ts @@ -1,5 +1,10 @@ import { execFile as execFileOriginal } from "node:child_process"; import { ExecFileFn } from "./types"; +import { + PANDOC_ENABLE_CHINESE_FONT, + PANDOC_CHINESE_FONT_PATH, + PANDOC_CHINESE_FONT_FAMILY +} from "../helpers/env"; export const properties = { from: { @@ -136,6 +141,24 @@ export function convert( if (xelatex.includes(convertTo)) { args.push("--pdf-engine=xelatex"); + + // Add Chinese font support if enabled + if (PANDOC_ENABLE_CHINESE_FONT) { + // Create a custom LaTeX template for Chinese font support + const chineseFontArgs = [ + "-V", `mainfont=${PANDOC_CHINESE_FONT_FAMILY}`, + "-V", "CJKmainfont=" + PANDOC_CHINESE_FONT_FAMILY, + "--variable", "geometry:margin=1in", + "--variable", "fontsize=11pt" + ]; + + // Add font path if specified + if (PANDOC_CHINESE_FONT_PATH) { + chineseFontArgs.push("--variable", `fontdir:${PANDOC_CHINESE_FONT_PATH}`); + } + + args.push(...chineseFontArgs); + } } args.push(filePath); diff --git a/src/helpers/env.ts b/src/helpers/env.ts index 4c8c067..7b6ed75 100644 --- a/src/helpers/env.ts +++ b/src/helpers/env.ts @@ -23,3 +23,10 @@ export const MAX_CONVERT_PROCESS = export const UNAUTHENTICATED_USER_SHARING = process.env.UNAUTHENTICATED_USER_SHARING?.toLowerCase() === "true" || false; + +export const PANDOC_ENABLE_CHINESE_FONT = + process.env.PANDOC_ENABLE_CHINESE_FONT?.toLowerCase() === "true" || false; + +export const PANDOC_CHINESE_FONT_PATH = process.env.PANDOC_CHINESE_FONT_PATH || ""; + +export const PANDOC_CHINESE_FONT_FAMILY = process.env.PANDOC_CHINESE_FONT_FAMILY || "SimSun";