From b1013db1b1a44d5fcd2e1a244d3c21c013d23e6e Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Thu, 19 Apr 2012 09:40:39 -0700 Subject: store the canvas center (in local space) per each subpath, instead of tracking it by the pen tool. This fixes the bug where the canvas transform was incorrectly applied when the stroke width was changed --- js/lib/geom/sub-path.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'js/lib/geom/sub-path.js') diff --git a/js/lib/geom/sub-path.js b/js/lib/geom/sub-path.js index 2ecafa1c..60335990 100755 --- a/js/lib/geom/sub-path.js +++ b/js/lib/geom/sub-path.js @@ -34,6 +34,8 @@ var GLSubpath = function GLSubpath() { this._Anchors = []; this._BBoxMin = [0, 0, 0]; this._BBoxMax = [0, 0, 0]; + this._canvasCenterLocalCoord = [0,0,0]; + this._isClosed = false; this._Samples = []; //polyline representation of this curve in canvas space @@ -274,6 +276,14 @@ GLSubpath.prototype.setIsClosed = function (isClosed) { } }; +GLSubpath.prototype.setCanvasCenterLocalCoord = function(center){ + this._canvasCenterLocalCoord = center; +}; + +GLSubpath.prototype.getCanvasCenterLocalCoord = function(){ + return this._canvasCenterLocalCoord; +}; + GLSubpath.prototype.getNumAnchors = function () { return this._Anchors.length; }; @@ -681,13 +691,16 @@ GLSubpath.prototype.setStrokeWidth = function (w) { if (this._dirty){ this.createSamples(false); //this will also update the bounding box } else{ - this.computeBoundingBox(false); + this.computeBoundingBox(true,false); } this.offsetPerBBoxMin(); //this will shift the local coordinates such that the bbox min point is at (0,0) //figure out the adjustment to the canvas position and size var delta = Math.round(diffStrokeWidth*0.5); + //update the canvas center (it's simply the center of the new bbox in this case) + this._canvasCenterLocalCoord = [0.5*(this._BBoxMax[0]+this._BBoxMin[0]),0.5*(this._BBoxMax[1]+this._BBoxMin[1]),0.5*(this._BBoxMax[2]+this._BBoxMin[2])]; + //update the width, height, left and top var ElementMediator = require("js/mediators/element-mediator").ElementMediator; var penCanvasCurrentWidth = parseInt(ElementMediator.getProperty(this._canvas, "width")); -- cgit v1.2.3