Move the maxCanvasPixels
option to a BaseViewer
/PDFPageView
option
This removes the `PDFJS.maxCanvasPixels` dependency from the viewer components, but please note that as a *temporary* solution the default viewer still uses it.
This commit is contained in:
parent
f4280368f7
commit
fdf99c6af5
@ -399,6 +399,7 @@ let PDFViewerApplication = {
|
||||
renderInteractiveForms: viewerPrefs['renderInteractiveForms'],
|
||||
enablePrintAutoRotate: viewerPrefs['enablePrintAutoRotate'],
|
||||
useOnlyCssZoom: PDFJS.useOnlyCssZoom,
|
||||
maxCanvasPixels: PDFJS.maxCanvasPixels,
|
||||
});
|
||||
pdfRenderingQueue.setViewer(this.pdfViewer);
|
||||
pdfLinkService.setViewer(this.pdfViewer);
|
||||
|
@ -50,6 +50,9 @@ const DEFAULT_CACHE_SIZE = 10;
|
||||
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
|
||||
* @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming.
|
||||
* The default value is `false`.
|
||||
* @property {number} maxCanvasPixels - (optional) The maximum supported canvas
|
||||
* size in total pixels, i.e. width * height. Use -1 for no limit.
|
||||
* The default value is 4096 * 4096 (16 mega-pixels).
|
||||
* @property {IL10n} l10n - Localization service.
|
||||
*/
|
||||
|
||||
@ -114,6 +117,7 @@ class BaseViewer {
|
||||
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
|
||||
this.renderer = options.renderer || RendererType.CANVAS;
|
||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||
this.maxCanvasPixels = options.maxCanvasPixels;
|
||||
this.l10n = options.l10n || NullL10n;
|
||||
|
||||
this.defaultRenderingQueue = !options.renderingQueue;
|
||||
@ -381,6 +385,7 @@ class BaseViewer {
|
||||
renderInteractiveForms: this.renderInteractiveForms,
|
||||
renderer: this.renderer,
|
||||
useOnlyCssZoom: this.useOnlyCssZoom,
|
||||
maxCanvasPixels: this.maxCanvasPixels,
|
||||
l10n: this.l10n,
|
||||
});
|
||||
bindOnAfterAndBeforeDraw(pageView);
|
||||
|
@ -18,10 +18,11 @@ import {
|
||||
RendererType, roundToDivide
|
||||
} from './ui_utils';
|
||||
import {
|
||||
createPromiseCapability, PDFJS, RenderingCancelledException, SVGGraphics
|
||||
createPromiseCapability, RenderingCancelledException, SVGGraphics
|
||||
} from 'pdfjs-lib';
|
||||
import { getGlobalEventBus } from './dom_events';
|
||||
import { RenderingStates } from './pdf_rendering_queue';
|
||||
import { viewerCompatibilityParams } from './viewer_compatibility';
|
||||
|
||||
/**
|
||||
* @typedef {Object} PDFPageViewOptions
|
||||
@ -40,9 +41,14 @@ import { RenderingStates } from './pdf_rendering_queue';
|
||||
* @property {string} renderer - 'canvas' or 'svg'. The default is 'canvas'.
|
||||
* @property {boolean} useOnlyCssZoom - (optional) Enables CSS only zooming.
|
||||
* The default value is `false`.
|
||||
* @property {number} maxCanvasPixels - (optional) The maximum supported canvas
|
||||
* size in total pixels, i.e. width * height. Use -1 for no limit.
|
||||
* The default value is 4096 * 4096 (16 mega-pixels).
|
||||
* @property {IL10n} l10n - Localization service.
|
||||
*/
|
||||
|
||||
const MAX_CANVAS_PIXELS = viewerCompatibilityParams.maxCanvasPixels || 16777216;
|
||||
|
||||
/**
|
||||
* @implements {IRenderableView}
|
||||
*/
|
||||
@ -67,6 +73,7 @@ class PDFPageView {
|
||||
this.enhanceTextSelection = options.enhanceTextSelection || false;
|
||||
this.renderInteractiveForms = options.renderInteractiveForms || false;
|
||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||
this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS;
|
||||
|
||||
this.eventBus = options.eventBus || getGlobalEventBus();
|
||||
this.renderingQueue = options.renderingQueue;
|
||||
@ -211,11 +218,11 @@ class PDFPageView {
|
||||
}
|
||||
|
||||
let isScalingRestricted = false;
|
||||
if (this.canvas && PDFJS.maxCanvasPixels > 0) {
|
||||
if (this.canvas && this.maxCanvasPixels > 0) {
|
||||
let outputScale = this.outputScale;
|
||||
if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
|
||||
((Math.floor(this.viewport.height) * outputScale.sy) | 0) >
|
||||
PDFJS.maxCanvasPixels) {
|
||||
this.maxCanvasPixels) {
|
||||
isScalingRestricted = true;
|
||||
}
|
||||
}
|
||||
@ -529,9 +536,9 @@ class PDFPageView {
|
||||
outputScale.scaled = true;
|
||||
}
|
||||
|
||||
if (PDFJS.maxCanvasPixels > 0) {
|
||||
if (this.maxCanvasPixels > 0) {
|
||||
let pixelsInViewport = viewport.width * viewport.height;
|
||||
let maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport);
|
||||
let maxScale = Math.sqrt(this.maxCanvasPixels / pixelsInViewport);
|
||||
if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
|
||||
outputScale.sx = maxScale;
|
||||
outputScale.sy = maxScale;
|
||||
|
Loading…
Reference in New Issue
Block a user