Skip to content

Commit

Permalink
Fix stroke width calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sapics committed May 8, 2015
1 parent 3bcde59 commit d459a87
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/canvas.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,13 @@
*/
_setObjectScale: function(localMouse, transform, lockScalingX, lockScalingY, by, lockScalingFlip) {
var target = transform.target, forbidScalingX = false, forbidScalingY = false,
strokeWidth = target.stroke ? target.strokeWidth : 0;
vLine = target.type === 'line' && target.width === 0,
hLine = target.type === 'line' && target.height === 0,
strokeWidthX = hLine ? 0 : target.strokeWidth,
strokeWidthY = vLine ? 0 : target.strokeWidth;

transform.newScaleX = localMouse.x / (target.width + strokeWidth / 2);
transform.newScaleY = localMouse.y / (target.height + strokeWidth / 2);
transform.newScaleX = localMouse.x / (target.width + strokeWidthX);
transform.newScaleY = localMouse.y / (target.height + strokeWidthY);

if (lockScalingFlip && transform.newScaleX <= 0 && transform.newScaleX < target.scaleX) {
forbidScalingX = true;
Expand Down Expand Up @@ -536,9 +539,12 @@
_scaleObjectEqually: function(localMouse, target, transform) {

var dist = localMouse.y + localMouse.x,
strokeWidth = target.stroke ? target.strokeWidth : 0,
lastDist = (target.height + (strokeWidth / 2)) * transform.original.scaleY +
(target.width + (strokeWidth / 2)) * transform.original.scaleX;
vLine = target.type === 'line' && target.width === 0,
hLine = target.type === 'line' && target.height === 0,
strokeWidthX = hLine ? 0 : target.strokeWidth,
strokeWidthY = vLine ? 0 : target.strokeWidth,
lastDist = (target.height + strokeWidthY) * transform.original.scaleY +
(target.width + strokeWidthX) * transform.original.scaleX;

// We use transform.scaleX/Y instead of target.scaleX/Y
// because the object may have a min scale and we'll loose the proportions
Expand Down
9 changes: 6 additions & 3 deletions src/mixins/canvas_gestures.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@
target._scaling = true;

var constraintPosition = target.translateToOriginPoint(target.getCenterPoint(), t.originX, t.originY),
halfStrokeWidth = target.stroke ? target.strokeWidth / 2 : 0;
vLine = target.type === 'line' && target.width === 0,
hLine = target.type === 'line' && target.height === 0,
strokeWidthX = hLine ? 0 : target.strokeWidth,
strokeWidthY = vLine ? 0 : target.strokeWidth;

this._setObjectScale(new fabric.Point((t.scaleX * s * (target.width + halfStrokeWidth)),
(t.scaleY * s * (target.height + halfStrokeWidth))),
this._setObjectScale(new fabric.Point((t.scaleX * s * (target.width + strokeWidthX)),
(t.scaleY * s * (target.height + strokeWidthY))),
t, lockScalingX, lockScalingY, null, target.get('lockScalingFlip'));

target.setPositionByOrigin(constraintPosition, t.originX, t.originY);
Expand Down
4 changes: 2 additions & 2 deletions src/mixins/itext.svg_export.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* _TO_SVG_START_ */
(function() {
var toFixed = fabric.util.toFixed,
NUM_FRACTION_DIGITS = fabric.Object.NUM_FRACTION_DIGITS;

/* _TO_SVG_START_ */
fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.prototype */ {

/**
Expand Down Expand Up @@ -115,5 +115,5 @@
].join('');
}
});
/* _TO_SVG_END_ */
})();
/* _TO_SVG_END_ */

0 comments on commit d459a87

Please sign in to comment.