Merge pull request #2283 from yurydelendik/hidpi
Fixes output for HiDPI device
This commit is contained in:
commit
f99150bc22
@ -1072,6 +1072,21 @@ var PDFView = {
|
|||||||
//#endif
|
//#endif
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns scale factor for the canvas. It makes sense for the HiDPI displays.
|
||||||
|
* @return {Object} The object with horizontal (sx) and vertical (sy)
|
||||||
|
scales. The scaled property is set to false if scaling is
|
||||||
|
not required, true otherwise.
|
||||||
|
*/
|
||||||
|
getOutputScale: function pdfViewGetOutputDPI() {
|
||||||
|
var pixelRatio = 'devicePixelRatio' in window ? window.devicePixelRatio : 1;
|
||||||
|
return {
|
||||||
|
sx: pixelRatio,
|
||||||
|
sy: pixelRatio,
|
||||||
|
scaled: pixelRatio != 1
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the error box.
|
* Show the error box.
|
||||||
* @param {String} message A message that is human readable.
|
* @param {String} message A message that is human readable.
|
||||||
@ -1957,14 +1972,29 @@ var PageView = function pageView(container, pdfPage, id, scale,
|
|||||||
textLayerDiv ? new TextLayerBuilder(textLayerDiv, this.id - 1) : null;
|
textLayerDiv ? new TextLayerBuilder(textLayerDiv, this.id - 1) : null;
|
||||||
|
|
||||||
var scale = this.scale, viewport = this.viewport;
|
var scale = this.scale, viewport = this.viewport;
|
||||||
canvas.width = Math.floor(viewport.width);
|
var outputScale = PDFView.getOutputScale();
|
||||||
canvas.height = Math.floor(viewport.height);
|
canvas.width = Math.floor(viewport.width) * outputScale.sx;
|
||||||
|
canvas.height = Math.floor(viewport.height) * outputScale.sy;
|
||||||
|
|
||||||
|
if (outputScale.scaled) {
|
||||||
|
var cssScale = 'scale(' + (1 / outputScale.sx) + ', ' +
|
||||||
|
(1 / outputScale.sy) + ')';
|
||||||
|
CustomStyle.setProp('transform' , canvas, cssScale);
|
||||||
|
CustomStyle.setProp('transformOrigin' , canvas, '0% 0%');
|
||||||
|
if (textLayerDiv) {
|
||||||
|
CustomStyle.setProp('transform' , textLayerDiv, cssScale);
|
||||||
|
CustomStyle.setProp('transformOrigin' , textLayerDiv, '0% 0%');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var ctx = canvas.getContext('2d');
|
var ctx = canvas.getContext('2d');
|
||||||
ctx.save();
|
ctx.save();
|
||||||
ctx.fillStyle = 'rgb(255, 255, 255)';
|
ctx.fillStyle = 'rgb(255, 255, 255)';
|
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
|
if (outputScale.scaled) {
|
||||||
|
ctx.scale(outputScale.sx, outputScale.sy);
|
||||||
|
}
|
||||||
|
|
||||||
// Rendering area
|
// Rendering area
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user