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:
parent
c17ff30d19
commit
6eb9e6a6a4
@ -46,11 +46,8 @@ function createScratchCanvas(width, height) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function addContextCurrentTransform(ctx) {
|
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) {
|
if (!ctx.mozCurrentTransform) {
|
||||||
// Store the original context
|
|
||||||
ctx._scaleX = ctx._scaleX || 1.0;
|
|
||||||
ctx._scaleY = ctx._scaleY || 1.0;
|
|
||||||
ctx._originalSave = ctx.save;
|
ctx._originalSave = ctx.save;
|
||||||
ctx._originalRestore = ctx.restore;
|
ctx._originalRestore = ctx.restore;
|
||||||
ctx._originalRotate = ctx.rotate;
|
ctx._originalRotate = ctx.rotate;
|
||||||
@ -59,7 +56,7 @@ function addContextCurrentTransform(ctx) {
|
|||||||
ctx._originalTransform = ctx.transform;
|
ctx._originalTransform = ctx.transform;
|
||||||
ctx._originalSetTransform = ctx.setTransform;
|
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 = [];
|
ctx._transformStack = [];
|
||||||
|
|
||||||
Object.defineProperty(ctx, 'mozCurrentTransform', {
|
Object.defineProperty(ctx, 'mozCurrentTransform', {
|
||||||
@ -435,6 +432,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
|
|||||||
this.smaskCounter = 0;
|
this.smaskCounter = 0;
|
||||||
this.tempSMask = null;
|
this.tempSMask = null;
|
||||||
if (canvasCtx) {
|
if (canvasCtx) {
|
||||||
|
// NOTE: if mozCurrentTransform is polyfilled, then the current state of
|
||||||
|
// the transformation must already be set in canvasCtx._transformMatrix.
|
||||||
addContextCurrentTransform(canvasCtx);
|
addContextCurrentTransform(canvasCtx);
|
||||||
}
|
}
|
||||||
this.cachedGetSinglePixelWidth = null;
|
this.cachedGetSinglePixelWidth = null;
|
||||||
|
@ -362,10 +362,11 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
}
|
}
|
||||||
this.textLayer = textLayer;
|
this.textLayer = textLayer;
|
||||||
|
|
||||||
// TODO(mack): use data attributes to store these
|
|
||||||
ctx._scaleX = outputScale.sx;
|
|
||||||
ctx._scaleY = outputScale.sy;
|
|
||||||
if (outputScale.scaled) {
|
if (outputScale.scaled) {
|
||||||
|
//#if !(MOZCENTRAL || FIREFOX)
|
||||||
|
// Used by the mozCurrentTransform polyfill in src/display/canvas.js.
|
||||||
|
ctx._transformMatrix = [outputScale.sx, 0, 0, outputScale.sy, 0, 0];
|
||||||
|
//#endif
|
||||||
ctx.scale(outputScale.sx, outputScale.sy);
|
ctx.scale(outputScale.sx, outputScale.sy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -516,6 +517,11 @@ var PDFPageView = (function PDFPageViewClosure() {
|
|||||||
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 !(MOZCENTRAL || FIREFOX)
|
||||||
|
// Used by the mozCurrentTransform polyfill in src/display/canvas.js.
|
||||||
|
ctx._transformMatrix =
|
||||||
|
[PRINT_OUTPUT_SCALE, 0, 0, PRINT_OUTPUT_SCALE, 0, 0];
|
||||||
|
//#endif
|
||||||
ctx.scale(PRINT_OUTPUT_SCALE, PRINT_OUTPUT_SCALE);
|
ctx.scale(PRINT_OUTPUT_SCALE, PRINT_OUTPUT_SCALE);
|
||||||
|
|
||||||
var renderContext = {
|
var renderContext = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user