mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #19635 from Snuffleupagus/thumbnails-maxCanvasPixels
Support the `maxCanvasPixels` option in the thumbnails code
This commit is contained in:
commit
4152eae3fb
5 changed files with 79 additions and 50 deletions
|
@ -640,9 +640,39 @@ class OutputScale {
|
|||
return this.sx !== 1 || this.sy !== 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {boolean} Returns `true` when scaling is symmetric,
|
||||
* `false` otherwise.
|
||||
*/
|
||||
get symmetric() {
|
||||
return this.sx === this.sy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {boolean} Returns `true` if scaling was limited,
|
||||
* `false` otherwise.
|
||||
*/
|
||||
limitCanvas(width, height, maxPixels, maxDim) {
|
||||
let maxAreaScale = Infinity,
|
||||
maxWidthScale = Infinity,
|
||||
maxHeightScale = Infinity;
|
||||
|
||||
if (maxPixels > 0) {
|
||||
maxAreaScale = Math.sqrt(maxPixels / (width * height));
|
||||
}
|
||||
if (maxDim !== -1) {
|
||||
maxWidthScale = maxDim / width;
|
||||
maxHeightScale = maxDim / height;
|
||||
}
|
||||
const maxScale = Math.min(maxAreaScale, maxWidthScale, maxHeightScale);
|
||||
|
||||
if (this.sx > maxScale || this.sy > maxScale) {
|
||||
this.sx = maxScale;
|
||||
this.sy = maxScale;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue