diff --git a/src/item/Item.js b/src/item/Item.js index 4f5f99b8..7100d46e 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1106,7 +1106,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ if (!matrix) { matrix = this._globalMatrix = this._matrix.clone(); if (this._parent) - matrix.concatenate(this._parent.getGlobalMatrix()); + matrix.preConcatenate(this._parent.getGlobalMatrix()); matrix._updateVersion = updateVersion; } return matrix; @@ -3391,9 +3391,11 @@ var Item = Base.extend(Callback, /** @lends Item# */{ // Keep calculating the current global matrix, by keeping a history // and pushing / popping as we go along. var trackTransforms = param.trackTransforms, - transforms = param.transforms, + // If transforms does not exist, set it up with the identity matrix + transforms = param.transforms = param.transforms || [new Matrix()], + matrix = this._matrix, parentMatrix = transforms[transforms.length - 1], - globalMatrix = parentMatrix.clone().concatenate(this._matrix); + globalMatrix = parentMatrix.clone().concatenate(matrix); // If this item is not invertible, do not draw it, since it would cause // empty ctx.currentPath and mess up caching. It appears to also be a // good idea generally to not draw in such cirucmstances, e.g. SVG @@ -3402,6 +3404,8 @@ var Item = Base.extend(Callback, /** @lends Item# */{ return; // Only keep track of transformation if told so. See Project#draw() if (trackTransforms) { + if (!transforms) + transforms = param.transforms = []; transforms.push(this._globalMatrix = globalMatrix); // We also keep the cached _globalMatrix versioned. globalMatrix._updateVersion = updateVersion; @@ -3457,7 +3461,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ ctx.translate(-itemOffset.x, -itemOffset.y); } // Apply globalMatrix when drawing into temporary canvas. - (direct ? this._matrix : globalMatrix).applyToContext(ctx); + (direct ? matrix : globalMatrix).applyToContext(ctx); // If we're drawing into a separate canvas and a clipItem is defined for // the current rendering loop, we need to draw the clip item again. if (!direct && param.clipItem) diff --git a/src/path/PathItem.js b/src/path/PathItem.js index df19d109..c80fe131 100644 --- a/src/path/PathItem.js +++ b/src/path/PathItem.js @@ -196,7 +196,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{ // To compare with native canvas approach: var ctx = CanvasProvider.getContext(1, 1); // Abuse clip = true to get a shape for ctx.isPointInPath(). - this._draw(ctx, new Base({ clip: true, transforms: [new Matrix()] })); + this._draw(ctx, new Base({ clip: true })); var res = ctx.isPointInPath(point.x, point.y, this.getWindingRule()); CanvasProvider.release(ctx); return res; diff --git a/src/project/Project.js b/src/project/Project.js index b533b98c..1e622241 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -431,9 +431,6 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{ var param = new Base({ offset: new Point(0, 0), ratio: ratio, - // A stack of concatenated matrices, to keep track of the current - // global matrix, since Canvas is not able tell us (yet). - transforms: [matrix], // Tell the drawing routine that we want to track nested matrices // in param.transforms, and that we want it to set _globalMatrix // as used below. Item#rasterize() and Raster#getAverageColor() do @@ -458,7 +455,7 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{ || item.getLayer().getSelectedColor(); ctx.strokeStyle = ctx.fillStyle = color ? color.toCanvasStyle(ctx) : '#009dec'; - var mx = item._globalMatrix; + var mx = item._globalMatrix.clone().preConcatenate(matrix); if (item._drawSelected) item._drawSelected(ctx, mx); if (item._boundsSelected) {