Repository navigation
fix: 打包版 pdf.js 的 CMap 和标准字体路径不再依赖 cwd (#85) - #92
Merged
Merged
Conversation
pdf-to-png-converter builds the pdf.js asset paths from process.cwd() when it loads, with no option to change them. Outside `npm run dev` pdf.js could not load predefined CMaps (UniGB-UCS2-H, GBK-EUC-H, Adobe-GB1-UCS2, ...) and silently drew no text for those fonts; standard fonts fell back to the canvas. - Add PDFPageRenderer as the only way into the converter. It points pdf.js at the installed pdfjs-dist, and fails loudly if the files are missing. - Turn pdf.js warnings on, so a font it can't load shows up in the logs. - Pin pdf-to-png-converter: the override relies on a non-public file, and npx installs without our lock file. - verify:package renders a CJK sample through the packaged renderer, from an empty cwd. From the repo root the check would pass with the fix reverted. Fixes #85
haywolf
added a commit
that referenced
this pull request
Nov 5, 2026
Removing sharp also removed the re-encoding it did on the way out: uploads reached the model provider byte for byte, with their GPS position and device details, and much larger (a 4000x3000 JPEG: 8.48 MB, was 3.29 MB). - ImageSplitter re-encodes uploads through @napi-rs/canvas at sharp's default quality, and fails rather than fall back to the original. The Exif orientation is applied to the pixels, so photos stay upright. - ModelService re-encodes any page file that may still hold metadata. Retrying a task reuses its page files, and those of older versions are plain copies. - Reject truncated images. Unlike sharp, the decoder draws what's there and leaves the rest blank, so a page would silently lose its text. - Pin @napi-rs/canvas to 1.0.11. Up to 1.0.3 it segfaults on damaged images, which would crash the app on each start, and 1.0.12 and 1.0.13 segfault in Electron as soon as they load. The load check now covers both. - Mount all of scripts/ in the distro containers: the load check requires fixtures/count-dark-pixels.cjs, which the PDF rendering check of #92 can share instead of its use of sharp.
haywolf
added a commit
that referenced
this pull request
Nov 5, 2026
…-engines Brings in #91 and #92, both of which still relied on sharp. - pdf-render-check.cjs and the PDF rendering test count pixels through count-dark-pixels.cjs and @napi-rs/canvas. - package-load-check.cjs: no checkSharp, and both checkPdfRendering and the Prisma engine it reports. - ModelService: no sharp, keeping providerSuffix from #91 and the re-encoding. - ProviderEndpoint.test: drop its mock of sharp.
haywolf
added a commit
that referenced
this pull request
Nov 5, 2026
* fix(db): apply migrations atomically and report init failures in the UI A failed database initialization was swallowed: the app kept running with every database feature broken and nothing telling the user why (#86). - initDatabase returns its outcome and runs once, and the renderer shows a persistent alert with the error through app:getDatabaseStatus. - Services that need the database don't start when it's unavailable. - runMigrations throws on the first failure instead of logging it and going on to apply later migrations on top of an incomplete schema. - Each migration runs in one transaction. Its statements could otherwise land on different pooled connections, whose stale schema cache made a RENAME after a DROP TABLE fail at random with "there is already another table", leaving the database half migrated: 19 of 640 replays failed before, 0 of 640 after. - The window opens after the migrations, so that no query sees them half done. * fix(linux): ship the Prisma engine of every distro and drop sharp Linux packages only held the engine of the Ubuntu build machine, while Prisma picks one from the distro family and libssl of the user's machine. On Fedora, RHEL, openSUSE and any OpenSSL 1.1 distro it found none (#86). - Generate debian/rhel x OpenSSL 1.1/3.0 engines on x64 and both OpenSSL arm64 engines on arm64. binaryTargets comes from PRISMA_BINARY_TARGETS, set by scripts/prisma-cli.mjs, so a package never holds engines of the other arch. - verify:package requires each of them, and verify:package:distros checks in containers that Fedora, Rocky 8 and Ubuntu 20.04 load the engine meant for them. Both CI and the release workflow run it. - Leave the unused engine copies of the Prisma CLI out of the package. - Remove sharp, which segfaults in Electron on Fedora 44: its libvips bundles glib while Electron links the system's. Conversion only used it to read the page image, so it now reads the file. EXIF is no longer stripped from uploaded images as a side effect. * fix(split): re-encode uploaded images to drop their metadata Removing sharp also removed the re-encoding it did on the way out: uploads reached the model provider byte for byte, with their GPS position and device details, and much larger (a 4000x3000 JPEG: 8.48 MB, was 3.29 MB). - ImageSplitter re-encodes uploads through @napi-rs/canvas at sharp's default quality, and fails rather than fall back to the original. The Exif orientation is applied to the pixels, so photos stay upright. - ModelService re-encodes any page file that may still hold metadata. Retrying a task reuses its page files, and those of older versions are plain copies. - Reject truncated images. Unlike sharp, the decoder draws what's there and leaves the rest blank, so a page would silently lose its text. - Pin @napi-rs/canvas to 1.0.11. Up to 1.0.3 it segfaults on damaged images, which would crash the app on each start, and 1.0.12 and 1.0.13 segfault in Electron as soon as they load. The load check now covers both. - Mount all of scripts/ in the distro containers: the load check requires fixtures/count-dark-pixels.cjs, which the PDF rendering check of #92 can share instead of its use of sharp. * fix(db): explain how to rebuild a database that can't be migrated A database left half migrated by an older version, or one that lost the record of a migration, fails on every start, while the alert only said to restart. initDatabase now also returns the database path when the file is what's failing, and the alert gives it with the steps to back it up and rebuild it. A missing engine keeps the old text, since a new database would fail as well. * docs: replace sharp and bare prisma commands
haywolf
added a commit
that referenced
this pull request
Nov 5, 2026
Conflicts in PDFSplitter.ts and its unit test. Batched rendering now goes through renderPdfPages (#92), which also decides the pdf.js log level, so the splitter's verbosityLevel: 0 is gone. PDFPageRenderer needed no change: pagesToProcess already passes through. strictPagesToProcess, which master still passed, is left out: PdfToPngOptions of the pinned converter has no such option and nothing reads it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #85(部分,见“未解决”)
复现
已在 Linux 上复现,包括真实打包应用:从无关目录启动 master 打包版,拆页时 pdf.js 报
Unable to load binary CMap,使用预定义 CMap(UniGB-UCS2-H、GBK-EUC-H)和 Identity-H/Adobe-GB1 的嵌入字体中文页,整行文字都没画出来(暗像素数为 0,开发模式为 12800)。改动
PDFPageRenderer.ts,作为访问pdf-to-png-converter的唯一入口:从转换库解析pdfjs-dist的实际位置,覆盖按process.cwd()拼出的 CMap 和标准字体路径;数据文件缺失时直接报错,不再静默丢字;打开 pdf.js 警告PDFSplitter改走PDFPageRenderer,去掉verbosityLevel: 0pdf-to-png-converter钉死为3.11.0,因为修复依赖它的非公开文件verify:package新增 CJK PDF 渲染检查(样例在scripts/fixtures/),并且所有检查前先切到空目录electron.vite.config.ts增加pdf-page-renderer入口,供打包检查调用测试
PDFPageRenderer.test.ts(6 个)和PDFPageRenderer.integration.test.ts(在没有node_modules的 cwd 下跑完整拆页)npm run test:unit:51 个文件,1033 个用例全部通过;npm run test:renderer:283 个用例通过npm run typecheck、npm run lint:通过npm run verify:package(Linux x64):通过,修复后打包版拆页 PNG 和开发模式逐字节一致verify:package都会失败未解决
@napi-rs/canvas不会按字符回退到系统 CJK 字体,和本次的路径问题无关。建议先在 macOS 和 Windows 上确认实际表现,再单独开 issue未验证项
verify:package时会覆盖--dir解包产物,没有测 AppImage 或安装器;npx 模式只模拟了目录布局