Skip to content

Commit

Permalink
Pixel perfect PDF viewer spread and hscroll width
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Oct 4, 2024
1 parent 399b270 commit 5c18051
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions dev/editviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
.replace('''(this.container.clientHeight - vPadding) / currentPage.height * currentPage.scale;''', '''(this.container.clientHeight - vPadding) / Math.max(...this._pages.map(p => p.height)) * currentPage.scale * (1 / (1 - (viewerTrim ?? 0) / 100));''') \
.replace('''setRotation(this.initialRotation);''', '''// setRotation(this.initialRotation);''') \
.replace('''this.pdfLinkService.setHash(this.initialBookmark);''', '''// this.pdfLinkService.setHash(this.initialBookmark);''') \
.replace('''hPadding = vPadding = 0;''', '''if (this._scrollMode === ScrollMode.HORIZONTAL || this._spreadMode === SpreadMode.NONE) { hPadding = vPadding = 0; } else { hPadding = 10; vPadding = 0; }''') \
# .replace('''parent.document.dispatchEvent(event);''', '''parent.document.dispatchEvent(event); \n document.dispatchEvent(event);''')
fout.write(line)

Expand Down
30 changes: 30 additions & 0 deletions viewer/latexworkshop.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ html[dir='rtl'] .findbar {

#synctex-indicator {
position: absolute;
top: 0;
left: 0;
z-index: 100000;
border: 0.2em solid red;
border-radius: 50%;
Expand Down Expand Up @@ -103,12 +105,40 @@ html[dir='rtl'] .findbar {
mask-image:var(--secondaryToolbarButton-spreadNone-icon);
}

.spread {
margin-inline: 0 !important;
}

.pdfViewer.removePageBorders .page {
border: none;
overflow: hidden;
box-shadow: 0px 0px 0px 1px lightgrey;
}

.pdfViewer.removePageBorders .spread .page:first-of-type {
margin-inline-start: 0px;
margin-inline-end: 5px;
}

.pdfViewer.removePageBorders .spread .page:last-of-type {
margin-inline-start: 5px;
margin-inline-end: 0px;
}

.pdfViewer.removePageBorders.scrollHorizontal .page {
margin-bottom: 0px;
}

.pdfViewer.removePageBorders.scrollHorizontal .page:first-of-type {
margin-inline-start: 0px;
margin-inline-end: 5px;
}

.pdfViewer.removePageBorders.scrollHorizontal .page:last-of-type {
margin-inline-start: 5px;
margin-inline-end: 0px;
}

.notransition {
transition: none !important;
}
Expand Down
4 changes: 2 additions & 2 deletions viewer/viewer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11452,7 +11452,7 @@ class PDFViewer {
hPadding *= 2;
}
} else if (this.removePageBorders) {
hPadding = vPadding = 0;
if (this._scrollMode === ScrollMode.HORIZONTAL || this._spreadMode === SpreadMode.NONE) { hPadding = vPadding = 0; } else { hPadding = 10; vPadding = 0; }
} else if (this._scrollMode === ScrollMode.HORIZONTAL) {
[hPadding, vPadding] = [vPadding, hPadding];
}
Expand Down Expand Up @@ -11568,7 +11568,7 @@ class PDFViewer {
let hPadding = SCROLLBAR_PADDING,
vPadding = VERTICAL_PADDING;
if (this.removePageBorders) {
hPadding = vPadding = 0;
if (this._scrollMode === ScrollMode.HORIZONTAL || this._spreadMode === SpreadMode.NONE) { hPadding = vPadding = 0; } else { hPadding = 10; vPadding = 0; }
}
widthScale = (this.container.clientWidth - hPadding) / width / PixelsPerInch.PDF_TO_CSS_UNITS;
heightScale = (this.container.clientHeight - vPadding) / height / PixelsPerInch.PDF_TO_CSS_UNITS;
Expand Down

0 comments on commit 5c18051

Please sign in to comment.