Merge pull request #4834 from dferer/canvas-max-size
Limit the size of canvases to 5MP (iOS restriction)
This commit is contained in:
commit
2efbdfe8d4
@ -140,6 +140,14 @@ PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
|
||||
PDFJS.verbosity = (PDFJS.verbosity === undefined ?
|
||||
PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
|
||||
|
||||
/**
|
||||
* The maximum supported canvas size in total pixels e.g. width * height.
|
||||
* The default value is 4096 * 4096. Use -1 for no limit.
|
||||
* @var {number}
|
||||
*/
|
||||
PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
|
||||
16777216 : PDFJS.maxCanvasPixels);
|
||||
|
||||
/**
|
||||
* Document initialization / loading parameters object.
|
||||
*
|
||||
|
@ -507,3 +507,12 @@ if (typeof PDFJS === 'undefined') {
|
||||
window.setTimeout(callback, 20);
|
||||
});
|
||||
})();
|
||||
|
||||
(function checkCanvasSizeLimitation() {
|
||||
var isIOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
|
||||
var isAndroid = /Android/g.test(navigator.userAgent);
|
||||
if (isIOS || isAndroid) {
|
||||
// 5MP
|
||||
PDFJS.maxCanvasPixels = 5242880;
|
||||
}
|
||||
})();
|
||||
|
@ -29,6 +29,7 @@ var PageView = function pageView(container, id, scale,
|
||||
this.scale = scale || 1.0;
|
||||
this.viewport = defaultViewport;
|
||||
this.pdfPageRotate = defaultViewport.rotation;
|
||||
this.hasRestrictedScaling = false;
|
||||
|
||||
this.renderingState = RenderingStates.INITIAL;
|
||||
this.resume = null;
|
||||
@ -125,8 +126,23 @@ var PageView = function pageView(container, id, scale,
|
||||
rotation: totalRotation
|
||||
});
|
||||
|
||||
if (PDFJS.useOnlyCssZoom && this.canvas) {
|
||||
this.cssTransform(this.canvas);
|
||||
var isScalingRestricted = false;
|
||||
if (this.canvas && PDFJS.maxCanvasPixels > 0) {
|
||||
var ctx = this.canvas.getContext('2d');
|
||||
var outputScale = getOutputScale(ctx);
|
||||
var pixelsInViewport = this.viewport.width * this.viewport.height;
|
||||
var maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport);
|
||||
if (((Math.floor(this.viewport.width) * outputScale.sx) | 0) *
|
||||
((Math.floor(this.viewport.height) * outputScale.sy) | 0) >
|
||||
PDFJS.maxCanvasPixels) {
|
||||
isScalingRestricted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.canvas &&
|
||||
(PDFJS.useOnlyCssZoom ||
|
||||
(this.hasRestrictedScaling && isScalingRestricted))) {
|
||||
this.cssTransform(this.canvas, true);
|
||||
return;
|
||||
} else if (this.canvas && !this.zoomLayer) {
|
||||
this.zoomLayer = this.canvas.parentNode;
|
||||
@ -138,7 +154,7 @@ var PageView = function pageView(container, id, scale,
|
||||
this.reset(true);
|
||||
};
|
||||
|
||||
this.cssTransform = function pageCssTransform(canvas) {
|
||||
this.cssTransform = function pageCssTransform(canvas, redrawAnnotations) {
|
||||
// Scale canvas, canvas wrapper, and page container.
|
||||
var width = this.viewport.width;
|
||||
var height = this.viewport.height;
|
||||
@ -201,7 +217,7 @@ var PageView = function pageView(container, id, scale,
|
||||
CustomStyle.setProp('transformOrigin', textLayerDiv, '0% 0%');
|
||||
}
|
||||
|
||||
if (PDFJS.useOnlyCssZoom && this.annotationLayer) {
|
||||
if (redrawAnnotations && this.annotationLayer) {
|
||||
setupAnnotations(div, this.pdfPage, this.viewport);
|
||||
}
|
||||
};
|
||||
@ -507,6 +523,19 @@ var PageView = function pageView(container, id, scale,
|
||||
outputScale.scaled = true;
|
||||
}
|
||||
|
||||
if (PDFJS.maxCanvasPixels > 0) {
|
||||
var pixelsInViewport = viewport.width * viewport.height;
|
||||
var maxScale = Math.sqrt(PDFJS.maxCanvasPixels / pixelsInViewport);
|
||||
if (outputScale.sx > maxScale || outputScale.sy > maxScale) {
|
||||
outputScale.sx = maxScale;
|
||||
outputScale.sy = maxScale;
|
||||
outputScale.scaled = true;
|
||||
this.hasRestrictedScaling = true;
|
||||
} else {
|
||||
this.hasRestrictedScaling = false;
|
||||
}
|
||||
}
|
||||
|
||||
canvas.width = (Math.floor(viewport.width) * outputScale.sx) | 0;
|
||||
canvas.height = (Math.floor(viewport.height) * outputScale.sy) | 0;
|
||||
canvas.style.width = Math.floor(viewport.width) + 'px';
|
||||
|
@ -34,7 +34,7 @@ var SCROLLBAR_PADDING = 40;
|
||||
var VERTICAL_PADDING = 5;
|
||||
var MAX_AUTO_SCALE = 1.25;
|
||||
var MIN_SCALE = 0.25;
|
||||
var MAX_SCALE = 4.0;
|
||||
var MAX_SCALE = 10.0;
|
||||
var VIEW_HISTORY_MEMORY = 20;
|
||||
var SCALE_SELECT_CONTAINER_PADDING = 8;
|
||||
var SCALE_SELECT_PADDING = 22;
|
||||
|
Loading…
x
Reference in New Issue
Block a user