diff --git a/web/app.js b/web/app.js index ae517270f..f1fe833cb 100644 --- a/web/app.js +++ b/web/app.js @@ -26,8 +26,6 @@ import { isValidRotation, isValidScrollMode, isValidSpreadMode, - MAX_SCALE, - MIN_SCALE, noContextMenuHandler, normalizeWheelEventDirection, parseQueryString, @@ -81,7 +79,6 @@ import { SecondaryToolbar } from "./secondary_toolbar.js"; import { Toolbar } from "./toolbar.js"; import { ViewHistory } from "./view_history.js"; -const DEFAULT_SCALE_DELTA = 1.1; const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms @@ -637,30 +634,18 @@ const PDFViewerApplication = { return this._initializedCapability.promise; }, - zoomIn(ticks) { + zoomIn(steps) { if (this.pdfViewer.isInPresentationMode) { return; } - let newScale = this.pdfViewer.currentScale; - do { - newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2); - newScale = Math.ceil(newScale * 10) / 10; - newScale = Math.min(MAX_SCALE, newScale); - } while (--ticks > 0 && newScale < MAX_SCALE); - this.pdfViewer.currentScaleValue = newScale; + this.pdfViewer.increaseScale(steps); }, - zoomOut(ticks) { + zoomOut(steps) { if (this.pdfViewer.isInPresentationMode) { return; } - let newScale = this.pdfViewer.currentScale; - do { - newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2); - newScale = Math.floor(newScale * 10) / 10; - newScale = Math.max(MIN_SCALE, newScale); - } while (--ticks > 0 && newScale > MIN_SCALE); - this.pdfViewer.currentScaleValue = newScale; + this.pdfViewer.decreaseScale(steps); }, zoomReset() { diff --git a/web/base_viewer.js b/web/base_viewer.js index 59ab4d61d..2e444898a 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -17,6 +17,7 @@ import { AnnotationMode, createPromiseCapability, version } from "pdfjs-lib"; import { CSS_UNITS, DEFAULT_SCALE, + DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, getVisibleElements, isPortraitOrientation, @@ -24,6 +25,8 @@ import { isValidScrollMode, isValidSpreadMode, MAX_AUTO_SCALE, + MAX_SCALE, + MIN_SCALE, moveToEndOfArray, PresentationModeState, RendererType, @@ -1693,6 +1696,34 @@ class BaseViewer { this.currentPageNumber = Math.max(currentPageNumber - advance, 1); return true; } + + /** + * Increase the current zoom level one, or more, times. + * @param {number} [steps] - Defaults to zooming once. + */ + increaseScale(steps = 1) { + let newScale = this._currentScale; + do { + newScale = (newScale * DEFAULT_SCALE_DELTA).toFixed(2); + newScale = Math.ceil(newScale * 10) / 10; + newScale = Math.min(MAX_SCALE, newScale); + } while (--steps > 0 && newScale < MAX_SCALE); + this.currentScaleValue = newScale; + } + + /** + * Decrease the current zoom level one, or more, times. + * @param {number} [steps] - Defaults to zooming once. + */ + decreaseScale(steps = 1) { + let newScale = this._currentScale; + do { + newScale = (newScale / DEFAULT_SCALE_DELTA).toFixed(2); + newScale = Math.floor(newScale * 10) / 10; + newScale = Math.max(MIN_SCALE, newScale); + } while (--steps > 0 && newScale > MIN_SCALE); + this.currentScaleValue = newScale; + } } export { BaseViewer }; diff --git a/web/pdf_scripting_manager.js b/web/pdf_scripting_manager.js index ce21ac7eb..f2af2386f 100644 --- a/web/pdf_scripting_manager.js +++ b/web/pdf_scripting_manager.js @@ -324,13 +324,13 @@ class PDFScriptingManager { if (isInPresentationMode) { return; } - this._eventBus.dispatch("zoomin", { source: this }); + this._pdfViewer.increaseScale(); break; case "ZoomViewOut": if (isInPresentationMode) { return; } - this._eventBus.dispatch("zoomout", { source: this }); + this._pdfViewer.decreaseScale(); break; } return; diff --git a/web/ui_utils.js b/web/ui_utils.js index 2b62e0e58..f8a8037e1 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -18,6 +18,7 @@ import { PixelsPerInch } from "pdfjs-lib"; const CSS_UNITS = PixelsPerInch.CSS / PixelsPerInch.PDF; const DEFAULT_SCALE_VALUE = "auto"; const DEFAULT_SCALE = 1.0; +const DEFAULT_SCALE_DELTA = 1.1; const MIN_SCALE = 0.1; const MAX_SCALE = 10.0; const UNKNOWN_SCALE = 0; @@ -1005,6 +1006,7 @@ export { binarySearchFirstItem, CSS_UNITS, DEFAULT_SCALE, + DEFAULT_SCALE_DELTA, DEFAULT_SCALE_VALUE, EventBus, getActiveOrFocusedElement,