mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-16 22:10:32 +00:00
new Object property strokeUniform allows the stroke width to always stay the same width as object scales
This commit is contained in:
parent
210854f572
commit
3a2f070b6d
2 changed files with 30 additions and 3 deletions
|
|
@ -592,8 +592,16 @@
|
|||
if (skewX === 0 && skewY === 0) {
|
||||
return { x: dimensions.x * this.scaleX, y: dimensions.y * this.scaleY };
|
||||
}
|
||||
var dimX = dimensions.x / 2, dimY = dimensions.y / 2,
|
||||
points = [
|
||||
var dimX, dimY;
|
||||
if (this.strokeUniform) {
|
||||
dimX = this.width / 2;
|
||||
dimY = this.width / 2;
|
||||
}
|
||||
else {
|
||||
dimX = dimensions.x / 2;
|
||||
dimY = dimensions.y / 2;
|
||||
}
|
||||
var points = [
|
||||
{
|
||||
x: -dimX,
|
||||
y: -dimY
|
||||
|
|
@ -616,7 +624,10 @@
|
|||
points[i] = fabric.util.transformPoint(points[i], transformMatrix);
|
||||
}
|
||||
bbox = fabric.util.makeBoundingBoxFromPoints(points);
|
||||
return { x: bbox.width, y: bbox.height };
|
||||
return this.strokeUniform ?
|
||||
{ x: bbox.width + this.strokeWidth, y: bbox.height + this.strokeWidth }
|
||||
:
|
||||
{ x: bbox.width, y: bbox.height };
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -560,6 +560,16 @@
|
|||
*/
|
||||
noScaleCache: true,
|
||||
|
||||
/**
|
||||
* When `false`, the stoke width will scale with the object.
|
||||
* When `true`, the stroke will always match the exact pixel size entered for stroke width.
|
||||
* default to false
|
||||
* since 2.5.1
|
||||
* @type Boolean
|
||||
* @default false
|
||||
*/
|
||||
strokeUniform: false,
|
||||
|
||||
/**
|
||||
* When set to `true`, object's cache will be rerendered next render call.
|
||||
* since 1.7.0
|
||||
|
|
@ -1323,6 +1333,9 @@
|
|||
else {
|
||||
alternative && alternative(ctx);
|
||||
}
|
||||
if (this.strokeUniform) {
|
||||
ctx.setLineDash(ctx.getLineDash().map(function(value) { return value * ctx.lineWidth; }));
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
@ -1460,6 +1473,9 @@
|
|||
}
|
||||
|
||||
ctx.save();
|
||||
if (this.strokeUniform) {
|
||||
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
|
||||
}
|
||||
this._setLineDash(ctx, this.strokeDashArray, this._renderDashedStroke);
|
||||
this._applyPatternGradientTransform(ctx, this.stroke);
|
||||
ctx.stroke();
|
||||
|
|
|
|||
Loading…
Reference in a new issue