mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-10 02:05:37 +02:00
Move the zoomIn/zoomOut functionality into BaseViewer
(PR 14038 follow-up)
Given the simplicity of this functionality, we can move it from the default viewer and into the `BaseViewer` class instead. This way, it's possible to support more scripting functionality in the standalone viewer components; please see PR 14038. Please note that I purposely went with `increaseScale`/`decreaseScale`-method names, rather than using "zoom", to better match the existing `currentScale`/`currentScaleValue` getters/setters that's being used in the `BaseViewer` class.
This commit is contained in:
parent
83d3bb43f4
commit
d9f9fa4f1c
4 changed files with 39 additions and 21 deletions
|
@ -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 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue