1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Fix flaw in mozCurrentTransform polyfill

Set transformation matrix in (polyfilled) mozPrintCallback when a scale
is applied. Removed _scaleX and _scaleY in favor of _transformMatrix to
emphasize that the caller MUST ensure that the state of the matrix is
correct before `addContextCurrentTransform` is called.
This commit is contained in:
Rob Wu 2015-03-11 20:55:26 +01:00
parent c17ff30d19
commit 6eb9e6a6a4
2 changed files with 13 additions and 8 deletions

View file

@ -46,11 +46,8 @@ function createScratchCanvas(width, height) {
}
function addContextCurrentTransform(ctx) {
// If the context doesn't expose a `mozCurrentTransform`, add a JS based on.
// If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
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;
@ -59,7 +56,7 @@ function addContextCurrentTransform(ctx) {
ctx._originalTransform = ctx.transform;
ctx._originalSetTransform = ctx.setTransform;
ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
ctx._transformStack = [];
Object.defineProperty(ctx, 'mozCurrentTransform', {
@ -435,6 +432,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.smaskCounter = 0;
this.tempSMask = null;
if (canvasCtx) {
// NOTE: if mozCurrentTransform is polyfilled, then the current state of
// the transformation must already be set in canvasCtx._transformMatrix.
addContextCurrentTransform(canvasCtx);
}
this.cachedGetSinglePixelWidth = null;