From dc026835b7d7b5d4b5cee7d616367682a6415e5d Mon Sep 17 00:00:00 2001 From: SkyJourney Date: Fri, 31 Jul 2026 23:42:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=B2=BE=E7=A1=AE?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=94=BE=E5=A4=A7=E5=90=8E=E5=8F=B3=E4=BE=A7?= =?UTF-8?q?=E7=95=99=E7=99=BD=E4=B8=A2=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/src/PrecisePdfPreview.tsx | 16 ++++++++++++++-- apps/web/src/pdf-page-geometry.ts | 19 +++++++++++++++++++ apps/web/tests/pdf-page-geometry.test.ts | 23 +++++++++++++++++++++++ docs/PROGRESS.md | 7 +++++++ 4 files changed, 63 insertions(+), 2 deletions(-) diff --git a/apps/web/src/PrecisePdfPreview.tsx b/apps/web/src/PrecisePdfPreview.tsx index e29745a..328ef09 100644 --- a/apps/web/src/PrecisePdfPreview.tsx +++ b/apps/web/src/PrecisePdfPreview.tsx @@ -19,13 +19,16 @@ import { import pdfWorkerUrl from "pdfjs-dist/build/pdf.worker.min.mjs?url"; import { getPdfCanvasRenderScale, - getPdfPageCssDimensions + getPdfPageCssDimensions, + getPrecisePdfDocumentWidth } from "./pdf-page-geometry"; import { createPdfAnnotationLinkService } from "./pdf-annotation-links"; import { PdfPageRenderQueue } from "./pdf-render-queue"; GlobalWorkerOptions.workerSrc = pdfWorkerUrl; +const PRECISE_PDF_INLINE_GUTTER = 30; + type PdfJsAnnotationLinkService = Parameters< AnnotationLayer["render"] >[0]["linkService"]; @@ -455,8 +458,17 @@ export function PrecisePdfPreview({ return
正在读取精确预览…
; } + const documentWidth = getPrecisePdfDocumentWidth( + pages.map((page) => page.width), + zoomPercent / 100, + PRECISE_PDF_INLINE_GUTTER + ); + return ( -
+
{pages.map((page) => ( { ); expect(getPdfCanvasRenderScale(0, 800, 2)).toBe(0); }); + + it.each([ + [50, 457], + [100, 854], + [120, 1013], + [400, 3235] + ])("在 %i%% 缩放下把双侧固定留白计入滚动宽度", (zoom, expected) => { + expect( + getPrecisePdfDocumentWidth( + [595.275591], + zoom / 100, + 30 + ) + ).toBe(expected); + }); + + it("按混合纸张中最宽页面计算精确预览滚动宽度", () => { + expect( + getPrecisePdfDocumentWidth([595.275591, 792], 1.2, 30) + ).toBe(1328); + expect(getPrecisePdfDocumentWidth([], 1.2, 30)).toBe(0); + }); }); diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md index dfae03e..8ece731 100644 --- a/docs/PROGRESS.md +++ b/docs/PROGRESS.md @@ -346,6 +346,13 @@ SHA-256;交互模式仅在文件存在且哈希正确时显示默认勾选项 本阶段按版本策略未提前修改应用的 `0.5.1` 版本号;正式 `v0.6.0` 发布 提交升级版本后,字体包才满足其 `minimumAppVersion=0.6.0` 运行时门禁。 +已修复 `v0.5.1` 遗留的精确预览放大后右侧留白丢失问题。精确 PDF 文档 +容器现在按当前缩放下最宽页面加左右各 30px 显式计算自身宽度,页面较小 +时仍由 `min-width: 100%` 居中,页面溢出时双侧留白则稳定进入横向 +`scrollWidth`。真实 Chromium 在 100%、120% 和 400% 下滚动到最右端, +文档右侧留白分别约为 30.38px、30.05px 和 30.45px;120% 与 400% +均准确到达各自最大横向滚动值,快速和连续预览结构未改变。 + ## 2. 已完成 ### 2.1 项目骨架