From: Tan Kian-ting Date: Sun, 21 Apr 2024 17:44:02 +0000 (+0800) Subject: revert the modification for simplicity X-Git-Url: https://git.kianting.info/?a=commitdiff_plain;h=6995639988599a8d77faf7023592e829d38afd94;p=anotherTypesetter revert the modification for simplicity --- diff --git a/README.md b/README.md index 4412207..f169113 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ## Just another interpretation of typesetting ## TODO **現在問題:需要遷移到PDFKit,以及使用標準的fontkit,避免ttc無法支援的問題。PDF-lib試過了,不能用。需要整理package-denendent** + - [v] apply - 240403 - [v] letrec - 240405 - [v] car - 240403 diff --git a/src/index.ts b/src/index.ts index 0c9d535..cfb1c1d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,6 @@ 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, @@ -282,10 +280,7 @@ async function measureWidthPx(inputString: string, fontFamily : string, fontSize 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); @@ -535,27 +530,9 @@ async function drawText(pageIndex : number, 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 (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((fontBytes).stream.buffer, {subset:true}); + const customFont = await pdfDoc.embedFont(fontBytes); const rgbColor = await hexColorToRGB(color); @@ -1126,7 +1103,6 @@ async function evaluate(expr: string): Promise { 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,