diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index 5777d1042..386349ffb 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -40,7 +40,7 @@ import { import { approximateFraction, DEFAULT_SCALE, - getOutputScale, + OutputScale, RendererType, RenderingStates, roundToDivide, @@ -806,7 +806,7 @@ class PDFPageView { } const ctx = canvas.getContext("2d", { alpha: false }); - const outputScale = (this.outputScale = getOutputScale()); + const outputScale = (this.outputScale = new OutputScale()); if (this.useOnlyCssZoom) { const actualSizeViewport = viewport.clone({ diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js index 91895eff5..293bb6be0 100644 --- a/web/pdf_thumbnail_view.js +++ b/web/pdf_thumbnail_view.js @@ -19,7 +19,7 @@ // eslint-disable-next-line max-len /** @typedef {import("./pdf_rendering_queue").PDFRenderingQueue} PDFRenderingQueue */ -import { getOutputScale, RenderingStates } from "./ui_utils.js"; +import { OutputScale, RenderingStates } from "./ui_utils.js"; import { RenderingCancelledException } from "pdfjs-lib"; const DRAW_UPSCALE_FACTOR = 2; // See comment in `PDFThumbnailView.draw` below. @@ -233,7 +233,7 @@ class PDFThumbnailView { canvas.mozOpaque = true; } const ctx = canvas.getContext("2d", { alpha: false }); - const outputScale = getOutputScale(); + const outputScale = new OutputScale(); canvas.width = (upscaleFactor * this.canvasWidth * outputScale.sx) | 0; canvas.height = (upscaleFactor * this.canvasHeight * outputScale.sy) | 0; diff --git a/web/ui_utils.js b/web/ui_utils.js index e3479d500..0e362b3da 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -78,20 +78,29 @@ const SpreadMode = { const AutoPrintRegExp = /\bprint\s*\(/; /** - * Returns scale factor for the canvas. It makes sense for the HiDPI displays. - * @returns {Object} The object with horizontal (sx) and vertical (sy) scales. - * The scaled property is false if scaling is not required, true otherwise. + * Scale factors for the canvas, necessary with HiDPI displays. */ -function getOutputScale() { - const pixelRatio = window.devicePixelRatio || 1; - return { - sx: pixelRatio, - sy: pixelRatio, +class OutputScale { + constructor() { + const pixelRatio = window.devicePixelRatio || 1; - get scaled() { - return this.sx !== 1 || this.sy !== 1; - }, - }; + /** + * @type {number} Horizontal scale. + */ + this.sx = pixelRatio; + + /** + * @type {number} Vertical scale. + */ + this.sy = pixelRatio; + } + + /** + * @type {boolean} Returns `true` when scaling is required, `false` otherwise. + */ + get scaled() { + return this.sx !== 1 || this.sy !== 1; + } } /** @@ -836,7 +845,6 @@ export { DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, getActiveOrFocusedElement, - getOutputScale, getPageSizeInches, getVisibleElements, isPortraitOrientation, @@ -849,6 +857,7 @@ export { noContextMenuHandler, normalizeWheelEventDelta, normalizeWheelEventDirection, + OutputScale, parseQueryString, PresentationModeState, ProgressBar,