新增 fonts 目錄:字體隨專案打包,LibreOffice 轉換時自動載入
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
BIN
fonts/全真楷書.ttf
Normal file
BIN
fonts/全真楷書.ttf
Normal file
Binary file not shown.
@@ -7,6 +7,7 @@ const { pathToFileURL } = require('node:url');
|
|||||||
const JSZip = require('jszip');
|
const JSZip = require('jszip');
|
||||||
|
|
||||||
const TEMPLATE_DIR = path.resolve(process.env.TEMPLATE_DIR || path.join(process.cwd(), 'templates'));
|
const TEMPLATE_DIR = path.resolve(process.env.TEMPLATE_DIR || path.join(process.cwd(), 'templates'));
|
||||||
|
const FONTS_DIR = path.resolve(process.env.FONTS_DIR || path.join(process.cwd(), 'fonts'));
|
||||||
const TEMP_DIR = path.resolve(process.env.TEMP_DIR || path.join(os.tmpdir(), 'rental-contracts'));
|
const TEMP_DIR = path.resolve(process.env.TEMP_DIR || path.join(os.tmpdir(), 'rental-contracts'));
|
||||||
const SOFFICE_BIN = process.env.SOFFICE_BIN || (
|
const SOFFICE_BIN = process.env.SOFFICE_BIN || (
|
||||||
process.platform === 'win32'
|
process.platform === 'win32'
|
||||||
@@ -205,9 +206,26 @@ function assertAllPlaceholdersWereFound(replacementCounts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function copyFontsToProfile(profileDir) {
|
||||||
|
let fontFiles;
|
||||||
|
try {
|
||||||
|
fontFiles = await fs.readdir(FONTS_DIR);
|
||||||
|
} catch {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const profileFontsDir = path.join(profileDir, 'user', 'fonts');
|
||||||
|
await fs.mkdir(profileFontsDir, { recursive: true });
|
||||||
|
await Promise.all(
|
||||||
|
fontFiles
|
||||||
|
.filter((f) => /\.(ttf|otf|ttc)$/i.test(f))
|
||||||
|
.map((f) => fs.copyFile(path.join(FONTS_DIR, f), path.join(profileFontsDir, f))),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async function convertToPdf(inputPath, outputDir) {
|
async function convertToPdf(inputPath, outputDir) {
|
||||||
const libreOfficeProfileDir = path.join(outputDir, 'lo-profile');
|
const libreOfficeProfileDir = path.join(outputDir, 'lo-profile');
|
||||||
await fs.mkdir(libreOfficeProfileDir, { recursive: true });
|
await fs.mkdir(libreOfficeProfileDir, { recursive: true });
|
||||||
|
await copyFontsToProfile(libreOfficeProfileDir);
|
||||||
|
|
||||||
const args = [
|
const args = [
|
||||||
`-env:UserInstallation=${pathToFileURL(libreOfficeProfileDir).href}`,
|
`-env:UserInstallation=${pathToFileURL(libreOfficeProfileDir).href}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user