1
0
Fork 0
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:
Jonas Jenwald 2025-03-10 16:30:25 +01:00 committed by GitHub
commit 4152eae3fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 79 additions and 50 deletions

View file

@ -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