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:
parent
d9a3a24353
commit
0159ec0a12
@ -806,8 +806,7 @@ class PDFPageView {
|
||||
}
|
||||
|
||||
const ctx = canvas.getContext("2d", { alpha: false });
|
||||
const outputScale = getOutputScale(ctx);
|
||||
this.outputScale = outputScale;
|
||||
const outputScale = (this.outputScale = getOutputScale());
|
||||
|
||||
if (this.useOnlyCssZoom) {
|
||||
const actualSizeViewport = viewport.clone({
|
||||
@ -844,9 +843,9 @@ class PDFPageView {
|
||||
this.paintedViewportMap.set(canvas, viewport);
|
||||
|
||||
// Rendering area
|
||||
const transform = !outputScale.scaled
|
||||
? null
|
||||
: [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
|
||||
const transform = outputScale.scaled
|
||||
? [outputScale.sx, 0, 0, outputScale.sy, 0, 0]
|
||||
: null;
|
||||
const renderContext = {
|
||||
canvasContext: ctx,
|
||||
transform,
|
||||
|
@ -233,7 +233,7 @@ class PDFThumbnailView {
|
||||
canvas.mozOpaque = true;
|
||||
}
|
||||
const ctx = canvas.getContext("2d", { alpha: false });
|
||||
const outputScale = getOutputScale(ctx);
|
||||
const outputScale = getOutputScale();
|
||||
|
||||
canvas.width = (upscaleFactor * this.canvasWidth * outputScale.sx) | 0;
|
||||
canvas.height = (upscaleFactor * this.canvasHeight * outputScale.sy) | 0;
|
||||
|
@ -79,18 +79,11 @@ const AutoPrintRegExp = /\bprint\s*\(/;
|
||||
|
||||
/**
|
||||
* Returns scale factor for the canvas. It makes sense for the HiDPI displays.
|
||||
* @returns {Object} The object with horizontal (sx) and vertical (sy)
|
||||
* scales. The scaled property is set to false if scaling is
|
||||
* not required, true otherwise.
|
||||
* @returns {Object} The object with horizontal (sx) and vertical (sy) scales.
|
||||
* The scaled property is false if scaling is not required, true otherwise.
|
||||
*/
|
||||
function getOutputScale(ctx) {
|
||||
const devicePixelRatio = window.devicePixelRatio || 1;
|
||||
const backingStoreRatio =
|
||||
ctx.webkitBackingStorePixelRatio ||
|
||||
ctx.mozBackingStorePixelRatio ||
|
||||
ctx.backingStorePixelRatio ||
|
||||
1;
|
||||
const pixelRatio = devicePixelRatio / backingStoreRatio;
|
||||
function getOutputScale() {
|
||||
const pixelRatio = window.devicePixelRatio || 1;
|
||||
return {
|
||||
sx: pixelRatio,
|
||||
sy: pixelRatio,
|
||||
|
Loading…
x
Reference in New Issue
Block a user