[go: nahoru, domu]

Skip to content

Commit

Permalink
Consistent page-width/fit scaling, disable pdf.js recovery scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Jun 23, 2024
1 parent 4e0a053 commit 299e786
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dev/editviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
.replace('''value: "../web/standard_fonts/"''', '''value: "../standard_fonts/"''')
.replace('''(this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor;''', '''(this.container.clientWidth - hPadding) / currentPage.width * currentPage.scale / this.#pageWidthScaleFactor * (1 / (1 - (viewerTrim ?? 0) / 100));''')
.replace('''(this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;''', '''(this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale * (1 / (1 - (viewerTrim ?? 0) / 100));''')
.replace('''parent.scrollLeft = offsetX;''', '''// parent.scrollLeft = offsetX;''')
.replace('''parent.scrollTop = offsetY;''', '''// parent.scrollTop = offsetY;''')
# .replace('''parent.document.dispatchEvent(event);''', '''parent.document.dispatchEvent(event); \n document.dispatchEvent(event);''')
)

Expand Down
1 change: 1 addition & 0 deletions viewer/components/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface IPDFViewerApplication {
},
getPagePoint(x: number, y: number): [number, number]
}[],
currentPageNumber: number,
currentScaleValue: string,
scrollMode: number,
spreadMode: number
Expand Down
5 changes: 5 additions & 0 deletions viewer/components/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare const PDFViewerApplication: IPDFViewerApplication
declare const PDFViewerApplicationOptions: IPDFViewerApplicationOptions

let prevState: {
page: number,
trim: number,
scale: string,
scrollMode: number,
Expand All @@ -20,6 +21,7 @@ let prevState: {
export async function refresh() {
// Fail-safe. For unknown reasons, the pack may have null values #4076
const currentState = {
page: PDFViewerApplication.pdfViewer.currentPageNumber ?? prevState?.page,
trim: getTrimValue(),
scale: PDFViewerApplication.pdfViewer.currentScaleValue ?? prevState?.scale,
scrollMode: PDFViewerApplication.pdfViewer.scrollMode ?? prevState?.scrollMode,
Expand Down Expand Up @@ -54,6 +56,9 @@ export async function restoreState() {
return
}

if (prevState.page !== undefined) {
PDFViewerApplication.pdfViewer.currentPageNumber = prevState.page
}
if (prevState.trim !== undefined) {
setTrimValue(prevState.trim)
}
Expand Down
4 changes: 2 additions & 2 deletions viewer/viewer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14521,10 +14521,10 @@ function scrollIntoView(element, spot, scrollMatches = false) {
}
if (spot.left !== undefined) {
offsetX += spot.left;
parent.scrollLeft = offsetX;
// parent.scrollLeft = offsetX;
}
}
parent.scrollTop = offsetY;
// parent.scrollTop = offsetY;
}
function watchScroll(viewAreaElement, callback) {
const debounceScroll = function (evt) {
Expand Down

0 comments on commit 299e786

Please sign in to comment.