From 6bacb386924e13c0713c68749683c3d1b1ba02d5 Mon Sep 17 00:00:00 2001 From: mduan Date: Tue, 15 Jan 2013 16:40:39 -0800 Subject: [PATCH] Make canvas transform matrix account for devicePixelRatio --- src/canvas.js | 4 +++- web/viewer.js | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/canvas.js b/src/canvas.js index 088e6c236..57861a940 100644 --- a/src/canvas.js +++ b/src/canvas.js @@ -46,6 +46,8 @@ function addContextCurrentTransform(ctx) { // If the context doesn't expose a `mozCurrentTransform`, add a JS based on. if (!ctx.mozCurrentTransform) { // Store the original context + ctx._scaleX = ctx._scaleX || 1.0; + ctx._scaleY = ctx._scaleY || 1.0; ctx._originalSave = ctx.save; ctx._originalRestore = ctx.restore; ctx._originalRotate = ctx.rotate; @@ -53,7 +55,7 @@ function addContextCurrentTransform(ctx) { ctx._originalTranslate = ctx.translate; ctx._originalTransform = ctx.transform; - ctx._transformMatrix = [1, 0, 0, 1, 0, 0]; + ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0]; ctx._transformStack = []; Object.defineProperty(ctx, 'mozCurrentTransform', { diff --git a/web/viewer.js b/web/viewer.js index d2e622761..704fd75e1 100644 --- a/web/viewer.js +++ b/web/viewer.js @@ -2048,6 +2048,9 @@ var PageView = function pageView(container, pdfPage, id, scale, } var ctx = canvas.getContext('2d'); + // TODO(mack): use data attributes to store these + ctx._scaleX = outputScale.sx; + ctx._scaleY = outputScale.sy; ctx.save(); ctx.fillStyle = 'rgb(255, 255, 255)'; ctx.fillRect(0, 0, canvas.width, canvas.height);