Merge pull request #12618 from Snuffleupagus/thumbnails-render-transform

Ensure that rendering of thumbnails work correctly on HiDPI displays (issue 9820)
This commit is contained in:
Tim van der Meij 2020-11-14 16:32:09 +01:00 committed by GitHub
commit 1bf640bb86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -229,7 +229,7 @@ class PDFThumbnailView {
/** /**
* @private * @private
*/ */
_getPageDrawContext(noCtxScale = false) { _getPageDrawContext() {
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
// Keep the no-thumbnail outline visible, i.e. `data-loaded === false`, // Keep the no-thumbnail outline visible, i.e. `data-loaded === false`,
// until rendering/image conversion is complete, to avoid display issues. // until rendering/image conversion is complete, to avoid display issues.
@ -249,10 +249,11 @@ class PDFThumbnailView {
canvas.style.width = this.canvasWidth + "px"; canvas.style.width = this.canvasWidth + "px";
canvas.style.height = this.canvasHeight + "px"; canvas.style.height = this.canvasHeight + "px";
if (!noCtxScale && outputScale.scaled) { const transform = outputScale.scaled
ctx.scale(outputScale.sx, outputScale.sy); ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
} : null;
return ctx;
return [ctx, transform];
} }
/** /**
@ -333,7 +334,7 @@ class PDFThumbnailView {
} }
}; };
const ctx = this._getPageDrawContext(); const [ctx, transform] = this._getPageDrawContext();
const drawViewport = this.viewport.clone({ scale: this.scale }); const drawViewport = this.viewport.clone({ scale: this.scale });
const renderContinueCallback = cont => { const renderContinueCallback = cont => {
if (!this.renderingQueue.isHighestPriority(this)) { if (!this.renderingQueue.isHighestPriority(this)) {
@ -349,6 +350,7 @@ class PDFThumbnailView {
const renderContext = { const renderContext = {
canvasContext: ctx, canvasContext: ctx,
transform,
viewport: drawViewport, viewport: drawViewport,
optionalContentConfigPromise: this._optionalContentConfigPromise, optionalContentConfigPromise: this._optionalContentConfigPromise,
}; };
@ -393,7 +395,7 @@ class PDFThumbnailView {
this.renderingState = RenderingStates.FINISHED; this.renderingState = RenderingStates.FINISHED;
const ctx = this._getPageDrawContext(true); const [ctx] = this._getPageDrawContext();
const canvas = ctx.canvas; const canvas = ctx.canvas;
if (img.width <= 2 * canvas.width) { if (img.width <= 2 * canvas.width) {
ctx.drawImage( ctx.drawImage(