Skip to content

Commit

Permalink
fix: 修復默認改動縮放比後,渲染位置識別出現問題
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoKam committed Sep 5, 2023
1 parent a826114 commit 691dbed
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
6 changes: 6 additions & 0 deletions packages/pdf-viewer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @orca-fe/pdf-viewer

## 1.19.2

### Patch Changes

- fix: 修復默認改動縮放比後,渲染位置識別出現問題

## 1.19.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/pdf-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@orca-fe/pdf-viewer",
"version": "1.19.1",
"version": "1.19.2",
"description": "PDF Viewer",
"keywords": [
"react",
Expand Down
8 changes: 5 additions & 3 deletions packages/pdf-viewer/src/PDFViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ const PDFViewer = React.forwardRef<PDFViewerHandle, PDFViewerProps>((props, pRef
let maxWidth = 0;
let pageMaxWidth = 0;
let pageMaxHeight = 0;
const topArr = viewports.map(({ height, width }) => {
const topArr = viewports.map(({ height: _height, width: _width }) => {
const width = _width * PixelsPerInch.PDF_TO_CSS_UNITS;
const height = _height * PixelsPerInch.PDF_TO_CSS_UNITS;
const _top = top;
top += Math.floor(height + pageGap) * scale;
maxWidth = Math.max(width * scale, maxWidth);
Expand All @@ -240,9 +242,9 @@ const PDFViewer = React.forwardRef<PDFViewerHandle, PDFViewerProps>((props, pRef
if (zoomMode && _this.size && maxWidth && pageMaxHeight) {
if (zoomMode === 'autoWidth') {
// 调整缩放级别,使其与容器宽度匹配
newZoom = Math.log2((_this.size.width - 32) / PixelsPerInch.PDF_TO_CSS_UNITS / pageMaxWidth);
newZoom = Math.log2((_this.size.width - 32) / pageMaxWidth);
} else if (zoomMode === 'autoHeight') {
newZoom = Math.log2((_this.size.height - 32) / PixelsPerInch.PDF_TO_CSS_UNITS / pageMaxHeight);
newZoom = Math.log2((_this.size.height - 32) / pageMaxHeight);
}
}

Expand Down
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 comment on commit 691dbed

@vercel
Copy link

@vercel vercel bot commented on 691dbed Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.