Skip to content

Commit 3f1ecc1

Browse files
Merge pull request #19915 from Snuffleupagus/OutputScale-capPixels
Reduce duplication when computing the maximum canvas pixels
2 parents ca05a0d + d5c534f commit 3f1ecc1

File tree

2 files changed

+12
-28
lines changed

2 files changed

+12
-28
lines changed

src/display/display_utils.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -665,13 +665,7 @@ class OutputScale {
665665
maxWidthScale = Infinity,
666666
maxHeightScale = Infinity;
667667

668-
if (capAreaFactor >= 0) {
669-
const cappedWindowArea = OutputScale.getCappedWindowArea(capAreaFactor);
670-
maxPixels =
671-
maxPixels > 0
672-
? Math.min(maxPixels, cappedWindowArea)
673-
: cappedWindowArea;
674-
}
668+
maxPixels = OutputScale.capPixels(maxPixels, capAreaFactor);
675669
if (maxPixels > 0) {
676670
maxAreaScale = Math.sqrt(maxPixels / (width * height));
677671
}
@@ -693,21 +687,18 @@ class OutputScale {
693687
return globalThis.devicePixelRatio || 1;
694688
}
695689

696-
static getCappedWindowArea(capAreaFactor) {
697-
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
698-
return Math.ceil(
699-
window.innerWidth *
700-
window.innerHeight *
690+
static capPixels(maxPixels, capAreaFactor) {
691+
if (capAreaFactor >= 0) {
692+
const winPixels = Math.ceil(
693+
(typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")
694+
? window.innerWidth * window.innerHeight
695+
: window.screen.availWidth * window.screen.availHeight) *
701696
this.pixelRatio ** 2 *
702697
(1 + capAreaFactor / 100)
703698
);
699+
return maxPixels > 0 ? Math.min(maxPixels, winPixels) : winPixels;
704700
}
705-
return Math.ceil(
706-
window.screen.availWidth *
707-
window.screen.availHeight *
708-
this.pixelRatio ** 2 *
709-
(1 + capAreaFactor / 100)
710-
);
701+
return maxPixels;
711702
}
712703
}
713704

web/pdf_page_detail_view.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,10 @@ class PDFPageDetailView extends BasePDFPageView {
140140
return;
141141
}
142142

143-
const { viewport, capCanvasAreaFactor } = this.pageView;
143+
const { viewport, maxCanvasPixels, capCanvasAreaFactor } = this.pageView;
144144

145145
const visibleWidth = visibleArea.maxX - visibleArea.minX;
146146
const visibleHeight = visibleArea.maxY - visibleArea.minY;
147-
let { maxCanvasPixels } = this.pageView;
148-
149-
if (capCanvasAreaFactor >= 0) {
150-
maxCanvasPixels = Math.min(
151-
maxCanvasPixels,
152-
OutputScale.getCappedWindowArea(capCanvasAreaFactor)
153-
);
154-
}
155147

156148
// "overflowScale" represents which percentage of the width and of the
157149
// height the detail area extends outside of the visible area. We want to
@@ -164,7 +156,8 @@ class PDFPageDetailView extends BasePDFPageView {
164156
const visiblePixels =
165157
visibleWidth * visibleHeight * OutputScale.pixelRatio ** 2;
166158
const maxDetailToVisibleLinearRatio = Math.sqrt(
167-
maxCanvasPixels / visiblePixels
159+
OutputScale.capPixels(maxCanvasPixels, capCanvasAreaFactor) /
160+
visiblePixels
168161
);
169162
const maxOverflowScale = (maxDetailToVisibleLinearRatio - 1) / 2;
170163
let overflowScale = Math.min(1, maxOverflowScale);

0 commit comments

Comments
 (0)