import * as fs from 'fs';
-import { PDFDocument , RGB, rgb} from 'pdf-lib';
-import fontkit from 'pdf-fontkit'; // for pdflib usage
-import * as fontkitOrig from 'fontkit'; // for ttc converting to ttf
-import {memfs} from 'memfs';
+import { PDFDocument , RGB, rgb, StandardFonts} from 'pdf-lib';
+import fontkit from '@pdf-lib/fontkit';
import { Token } from "typescript-parsec";
import {
buildLexer,
hb = hb(wsm.instance);
let fontName = spawnSync('fc-match', ['--format=%{file}', fontFamily]);
- let fontPath = fontName.stdout.toString();
-
-
-
+ const fontPath = fontName.stdout.toString();
let fontdata = fs.readFileSync(fontPath);
const fcMatch = await spawnSync('fc-match', ['--format=%{file}', fontFamily]);
const path = fcMatch.stdout.toString();
pdfDoc.registerFontkit(fontkit);
- let fontBytes;
- // workaround for ttc
- if (path.match(/[.]ttc$/)){
- let tmpfs = memfs();
- let psName = await spawnSync('fc-match',
- ['--format=%{postscriptname}',
- fontFamily])
- .stdout.toString();
- console.log("===", psName);
-
- let buffer = await fs.readFileSync("/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc");
- let coll = fontkit.create(buffer, "NotoSansCJKtc-Regular");
- //let collection = await (<any>fontkitOrig.openSync(path, psName));
-
- fontBytes = coll;
- // fs.writeFileSync("/tmp/a.ttf", fontBytes);
-}else{
- fontBytes = fs.readFileSync(path);
-}
+ const fontBytes = fs.readFileSync(path);
- const customFont = await pdfDoc.embedFont((<any>fontBytes).stream.buffer, {subset:true});
+ const customFont = await pdfDoc.embedFont(fontBytes);
const rgbColor = await hexColorToRGB(color);
import readline = require("node:readline");
import { exit } from "node:process";
import { spawnSync } from 'child_process';
-import { match } from 'assert';
const rl = readline.createInterface({
input: process.stdin,