Remove the backingStorePixelRatio-part of the getOutputScale helper function

The `CanvasRenderingContext2D.backingStorePixelRatio` property was never standardized, and only Safari set (its prefixed version of) it to anything other than `1`.
Note that e.g. MDN doesn't contain any information about this property, and one of the few sources of information (at this point) is the following post: https://stackoverflow.com/questions/24332639/why-context2d-backingstorepixelratio-deprecated

Hence we can simplify the `getOutputScale` helper function, by removing some dead code, and now it no longer requires any parameters when called.
This commit is contained in:
Jonas Jenwald 2022-02-17 22:21:59 +01:00
parent d9a3a24353
commit 0159ec0a12
3 changed files with 9 additions and 17 deletions

View File

@ -806,8 +806,7 @@ class PDFPageView {
} }
const ctx = canvas.getContext("2d", { alpha: false }); const ctx = canvas.getContext("2d", { alpha: false });
const outputScale = getOutputScale(ctx); const outputScale = (this.outputScale = getOutputScale());
this.outputScale = outputScale;
if (this.useOnlyCssZoom) { if (this.useOnlyCssZoom) {
const actualSizeViewport = viewport.clone({ const actualSizeViewport = viewport.clone({
@ -844,9 +843,9 @@ class PDFPageView {
this.paintedViewportMap.set(canvas, viewport); this.paintedViewportMap.set(canvas, viewport);
// Rendering area // Rendering area
const transform = !outputScale.scaled const transform = outputScale.scaled
? null ? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
: [outputScale.sx, 0, 0, outputScale.sy, 0, 0]; : null;
const renderContext = { const renderContext = {
canvasContext: ctx, canvasContext: ctx,
transform, transform,

View File

@ -233,7 +233,7 @@ class PDFThumbnailView {
canvas.mozOpaque = true; canvas.mozOpaque = true;
} }
const ctx = canvas.getContext("2d", { alpha: false }); const ctx = canvas.getContext("2d", { alpha: false });
const outputScale = getOutputScale(ctx); const outputScale = getOutputScale();
canvas.width = (upscaleFactor * this.canvasWidth * outputScale.sx) | 0; canvas.width = (upscaleFactor * this.canvasWidth * outputScale.sx) | 0;
canvas.height = (upscaleFactor * this.canvasHeight * outputScale.sy) | 0; canvas.height = (upscaleFactor * this.canvasHeight * outputScale.sy) | 0;

View File

@ -79,18 +79,11 @@ const AutoPrintRegExp = /\bprint\s*\(/;
/** /**
* Returns scale factor for the canvas. It makes sense for the HiDPI displays. * Returns scale factor for the canvas. It makes sense for the HiDPI displays.
* @returns {Object} The object with horizontal (sx) and vertical (sy) * @returns {Object} The object with horizontal (sx) and vertical (sy) scales.
* scales. The scaled property is set to false if scaling is * The scaled property is false if scaling is not required, true otherwise.
* not required, true otherwise.
*/ */
function getOutputScale(ctx) { function getOutputScale() {
const devicePixelRatio = window.devicePixelRatio || 1; const pixelRatio = window.devicePixelRatio || 1;
const backingStoreRatio =
ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.backingStorePixelRatio ||
1;
const pixelRatio = devicePixelRatio / backingStoreRatio;
return { return {
sx: pixelRatio, sx: pixelRatio,
sy: pixelRatio, sy: pixelRatio,