fix: 修复精确预览放大后右侧留白丢失
This commit is contained in:
@@ -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 <div className="precise-pdf-status">正在读取精确预览…</div>;
|
||||
}
|
||||
|
||||
const documentWidth = getPrecisePdfDocumentWidth(
|
||||
pages.map((page) => page.width),
|
||||
zoomPercent / 100,
|
||||
PRECISE_PDF_INLINE_GUTTER
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="precise-pdf-document">
|
||||
<div
|
||||
className="precise-pdf-document"
|
||||
style={{ width: `${documentWidth}px` }}
|
||||
>
|
||||
{pages.map((page) => (
|
||||
<PrecisePdfPage
|
||||
key={page.pageNumber}
|
||||
|
||||
@@ -31,3 +31,22 @@ export function getPdfCanvasRenderScale(
|
||||
}
|
||||
return (displayWidthCssPixels / widthPoints) * devicePixelRatio;
|
||||
}
|
||||
|
||||
export function getPrecisePdfDocumentWidth(
|
||||
pageWidthsPoints: readonly number[],
|
||||
displayScale: number,
|
||||
inlineGutter: number
|
||||
) {
|
||||
const maximumPageWidth = Math.max(0, ...pageWidthsPoints);
|
||||
if (
|
||||
maximumPageWidth <= 0 ||
|
||||
displayScale <= 0 ||
|
||||
inlineGutter < 0
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
return Math.ceil(
|
||||
maximumPageWidth * PDF_PAGE_CSS_SCALE * displayScale +
|
||||
inlineGutter * 2
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user