diff --git a/Dockerfile b/Dockerfile index bbf2327f..89229657 100644 --- a/Dockerfile +++ b/Dockerfile @@ -74,9 +74,19 @@ RUN apt-get update && apt-get install -y \ texlive-latex-extra \ texlive-latex-recommended \ texlive-xetex \ + texlive-lang-chinese \ + fonts-noto-cjk \ + fonts-wqy-zenhei \ + fonts-wqy-microhei \ + fonts-arphic-ukai \ + fonts-arphic-uming \ --no-install-recommends \ && rm -rf /var/lib/apt/lists/* +RUN mkdir -p /usr/share/fonts/truetype/chinese && \ + ln -sf /usr/share/fonts/opentype/noto /usr/share/fonts/truetype/chinese/noto && \ + fc-cache -f -v + # Install VTracer binary RUN ARCH=$(uname -m) && \ if [ "$ARCH" = "aarch64" ]; then \ @@ -101,4 +111,6 @@ EXPOSE 3000/tcp # used for calibre ENV QTWEBENGINE_CHROMIUM_FLAGS="--no-sandbox" ENV NODE_ENV=production +ENV LANG=zh_CN.UTF-8 +ENV LC_ALL=zh_CN.UTF-8 ENTRYPOINT [ "bun", "run", "dist/src/index.js" ] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml index 5b26ff8e..209e4ca6 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 in container (mount fonts via volumes above) + # - 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 c14c98b9..6efcdd1d 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 4c8c067e..7b6ed750 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";