Skip to content

Commit d7808b0

Browse files
committed
Fixing pattern canvas transform for chrome
1 parent 8ac0690 commit d7808b0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/canvas.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function addContextCurrentTransform(ctx) {
5757
ctx._originalScale = ctx.scale;
5858
ctx._originalTranslate = ctx.translate;
5959
ctx._originalTransform = ctx.transform;
60+
ctx._originalSetTransform = ctx.setTransform;
6061

6162
ctx._transformMatrix = [ctx._scaleX, 0, 0, ctx._scaleY, 0, 0];
6263
ctx._transformStack = [];
@@ -138,6 +139,12 @@ function addContextCurrentTransform(ctx) {
138139
ctx._originalTransform(a, b, c, d, e, f);
139140
};
140141

142+
ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
143+
this._transformMatrix = [a, b, c, d, e, f];
144+
145+
ctx._originalSetTransform(a, b, c, d, e, f);
146+
};
147+
141148
ctx.rotate = function ctxRotate(angle) {
142149
var cosValue = Math.cos(angle);
143150
var sinValue = Math.sin(angle);

src/pattern.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ var TilingPattern = (function TilingPatternClosure() {
351351

352352
// set the new canvas element context as the graphics context
353353
var tmpCtx = tmpCanvas.getContext('2d');
354+
// for simulated mozCurrentTransform canvas (normaly setting width/height
355+
// will reset the matrix)
356+
tmpCtx.setTransform(1, 0, 0, 1, 0, 0);
354357
var graphics = new CanvasGraphics(tmpCtx, commonObjs, objs);
355358

356359
this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
@@ -415,7 +418,7 @@ var TilingPattern = (function TilingPatternClosure() {
415418
// The temporary canvas is created only because the memory is released
416419
// more quickly than creating multiple temporary canvases.
417420
if (temporaryPatternCanvas === null) {
418-
temporaryPatternCanvas = createScratchCanvas(0, 0);
421+
temporaryPatternCanvas = createScratchCanvas(1, 1);
419422
}
420423
this.createPatternCanvas(temporaryPatternCanvas);
421424

0 commit comments

Comments
 (0)