Skip to content

Commit

Permalink
fix(): ensure scaling factor is positive for strokeUniform (#7729)
Browse files Browse the repository at this point in the history
* Update object.class.js

redundant else if

* added a visual test

* removed useless file

* prefer dashes

* prefer dashes

* modified golden

* more tolerance

Co-authored-by: Andrea Bogazzi <andreabogazzi79@gmail.com>
  • Loading branch information
ShaMan123 and asturur authored Feb 22, 2022
1 parent 84e405d commit 23ae1a7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -1537,13 +1537,10 @@
}

ctx.save();
if (this.strokeUniform && this.group) {
if (this.strokeUniform) {
var scaling = this.getObjectScaling();
ctx.scale(1 / scaling.x, 1 / scaling.y);
}
else if (this.strokeUniform) {
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
}
this._setLineDash(ctx, this.strokeDashArray);
this._setStrokeStyles(ctx, this);
ctx.stroke();
Expand Down
44 changes: 44 additions & 0 deletions test/visual/generic_rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,50 @@
height: 60,
});

function renderStrokeWithNegativeScale(canvas, callback) {
var rect = new fabric.Rect({
width: 10,
height: 10,
fill: 'transparent',
stroke: 'blue',
strokeWidth: 15,
strokeUniform: true,
strokeDashArray: [2, 2],
top: 65,
left: 30,
});
// do not do this at init time or they will be positive
rect.scaleX = -2;
rect.scaleY = -4;

var rect2 = new fabric.Rect({
width: 10,
height: 10,
fill: 'transparent',
stroke: 'red',
strokeWidth: 15,
scaleX: -2,
scaleY: -4,
strokeDashArray: [2, 2],
strokeUniform: true,
top: 10,
left: 55,
});
canvas.add(rect, rect2);
canvas.renderAll();
callback(canvas.lowerCanvasEl);
}

tests.push({
test: 'Rect with strokeUniform: true and negative scaling',
code: renderStrokeWithNegativeScale,
golden: 'strokeNegativeScale.png',
percentage: 0.011,
disabled: fabric.isLikelyNode,
width: 100,
height: 100,
});

function shadownonscaling(canvas, callback) {
var obj = new fabric.Rect();
obj.set({
Expand Down
Binary file added test/visual/golden/strokeNegativeScale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 23ae1a7

Please sign in to comment.