Skip to content

Commit

Permalink
fix(fabric.Object): add strokeuniform to object toObject output. (#6772)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Dec 31, 2020
1 parent 0327661 commit 31007b6
Show file tree
Hide file tree
Showing 18 changed files with 475 additions and 457 deletions.
2 changes: 1 addition & 1 deletion src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@
strokeLineCap: this.strokeLineCap,
strokeDashOffset: this.strokeDashOffset,
strokeLineJoin: this.strokeLineJoin,
// strokeUniform: this.strokeUniform,
strokeUniform: this.strokeUniform,
strokeMiterLimit: toFixed(this.strokeMiterLimit, NUM_FRACTION_DIGITS),
scaleX: toFixed(this.scaleX, NUM_FRACTION_DIGITS),
scaleY: toFixed(this.scaleY, NUM_FRACTION_DIGITS),
Expand Down
81 changes: 41 additions & 40 deletions test/unit/activeselection.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,38 @@
var clone = group.toObject();

var expectedObject = {
'version': fabric.version,
'type': 'activeSelection',
'originX': 'left',
'originY': 'top',
'left': 50,
'top': 100,
'width': 80,
'height': 60,
'fill': 'rgb(0,0,0)',
'stroke': null,
'strokeWidth': 0,
'strokeDashArray': null,
'strokeLineCap': 'butt',
'strokeDashOffset': 0,
'strokeLineJoin': 'miter',
'strokeMiterLimit': 4,
'scaleX': 1,
'scaleY': 1,
'shadow': null,
'visible': true,
'backgroundColor': '',
'angle': 0,
'flipX': false,
'flipY': false,
'opacity': 1,
'fillRule': 'nonzero',
'paintFirst': 'fill',
'globalCompositeOperation': 'source-over',
'skewX': 0,
'skewY': 0,
'objects': clone.objects
version: fabric.version,
type: 'activeSelection',
originX: 'left',
originY: 'top',
left: 50,
top: 100,
width: 80,
height: 60,
fill: 'rgb(0,0,0)',
stroke: null,
strokeWidth: 0,
strokeDashArray: null,
strokeLineCap: 'butt',
strokeDashOffset: 0,
strokeLineJoin: 'miter',
strokeMiterLimit: 4,
scaleX: 1,
scaleY: 1,
shadow: null,
visible: true,
backgroundColor: '',
angle: 0,
flipX: false,
flipY: false,
opacity: 1,
fillRule: 'nonzero',
paintFirst: 'fill',
globalCompositeOperation: 'source-over',
skewX: 0,
skewY: 0,
strokeUniform: false,
objects: clone.objects
};

assert.deepEqual(clone, expectedObject);
Expand All @@ -98,15 +99,15 @@
group.includeDefaultValues = false;
var clone = group.toObject();
var objects = [{
'version': fabric.version,
version: fabric.version,
type: 'rect',
left: 10,
top: -30,
width: 30,
height: 10,
strokeWidth: 0
}, {
'version': fabric.version,
version: fabric.version,
type: 'rect',
left: -40,
top: -10,
Expand All @@ -115,13 +116,13 @@
strokeWidth: 0
}];
var expectedObject = {
'version': fabric.version,
'type': 'activeSelection',
'left': 50,
'top': 100,
'width': 80,
'height': 60,
'objects': objects
version: fabric.version,
type: 'activeSelection',
left: 50,
top: 100,
width: 80,
height: 60,
objects: objects
};
assert.deepEqual(clone, expectedObject);
});
Expand Down
19 changes: 10 additions & 9 deletions test/unit/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@
'13.99], ["z", null]]}';

var PATH_DATALESS_JSON = '{"version":"' + fabric.version + '","objects":[{"type":"path","version":"' + fabric.version + '","originX":"left","originY":"top","left":99.5,"top":99.5,"width":200,"height":200,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"sourcePath":"http://example.com/"}]}';

var RECT_JSON = '{"version":"' + fabric.version + '","objects":[{"type":"rect","version":"' + fabric.version + '","originX":"left","originY":"top","left":0,"top":0,"width":10,"height":10,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,' +
'"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"rx":0,"ry":0}],"background":"#ff5555","overlay":"rgba(0,0,0,0.2)"}';

Expand Down Expand Up @@ -174,12 +174,12 @@
});

QUnit.test('interactive', function(assert) {
assert.ok(typeof canvas.interactive == 'boolean');
assert.ok(typeof canvas.interactive === 'boolean');
assert.ok(canvas.interactive, 'default is true');
});

QUnit.test('selection', function(assert) {
assert.ok(typeof canvas.selection == 'boolean');
assert.ok(typeof canvas.selection === 'boolean');
assert.ok(canvas.selection, 'default is true');
});

Expand Down Expand Up @@ -784,7 +784,7 @@
var rect = makeRect({ left: 0, top: 0, width: 30, height: 30 }),
rectOver = makeRect({ left: 0, top: 0, width: 30, height: 30 }),
target,
pointer = { clientX: 15, clientY: 15, 'shiftKey': true },
pointer = { clientX: 15, clientY: 15, shiftKey: true },
pointer2 = { clientX: 4, clientY: 4 };
canvas.add(rect);
canvas.add(rectOver);
Expand Down Expand Up @@ -1346,7 +1346,7 @@
QUnit.test('toObject', function(assert) {
assert.ok(typeof canvas.toObject === 'function');
var expectedObject = {
'version': fabric.version,
version: fabric.version,
objects: canvas.getObjects()
};
assert.deepEqual(expectedObject, canvas.toObject());
Expand All @@ -1362,7 +1362,7 @@
var clipPath = makeRect();
var canvasWithClipPath = new fabric.Canvas(null, { clipPath: clipPath });
var expectedObject = {
'version': fabric.version,
version: fabric.version,
objects: canvasWithClipPath.getObjects(),
clipPath: {
type: 'rect',
Expand Down Expand Up @@ -1396,7 +1396,8 @@
skewX: 0,
skewY: 0,
rx: 0,
ry: 0
ry: 0,
strokeUniform: false
}
};

Expand All @@ -1412,7 +1413,7 @@
QUnit.test('toDatalessObject', function(assert) {
assert.ok(typeof canvas.toDatalessObject === 'function');
var expectedObject = {
'version': fabric.version,
version: fabric.version,
objects: canvas.getObjects()
};

Expand Down
9 changes: 5 additions & 4 deletions test/unit/canvas_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
'13.99], ["z"]]}], "background": "#ff5555","overlay": "rgba(0,0,0,0.2)"}';

var PATH_DATALESS_JSON = '{"version":"' + fabric.version + '","objects":[{"type":"path","version":"' + fabric.version + '","originX":"left","originY":"top","left":99.5,"top":99.5,"width":200,"height":200,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"sourcePath":"http://example.com/"}]}';

var RECT_JSON = '{"version":"' + fabric.version + '","objects":[{"type":"rect","version":"' + fabric.version + '","originX":"left","originY":"top","left":0,"top":0,"width":10,"height":10,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"rx":0,"ry":0}],"background":"#ff5555","overlay":"rgba(0,0,0,0.2)"}';

var RECT_JSON_WITH_PADDING = '{"version":"' + fabric.version + '","objects":[{"type":"rect","version":"' + fabric.version + '","originX":"left","originY":"top","left":0,"top":0,"width":10,"height":20,"fill":"rgb(0,0,0)",' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,' +
'"stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeUniform":false,"strokeMiterLimit":4,' +
'"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,' +
'"shadow":null,"visible":true,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","skewX":0,"skewY":0,"rx":0,"ry":0,"padding":123,"foo":"bar"}]}';

Expand Down Expand Up @@ -106,7 +106,8 @@
skewX: 0,
skewY: 0,
cropX: 0,
cropY: 0
cropY: 0,
strokeUniform: false
};

function _createImageElement() {
Expand Down
67 changes: 34 additions & 33 deletions test/unit/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,40 @@
QUnit.test('toObject', function(assert) {
var circle = new fabric.Circle();
var defaultProperties = {
'version': fabric.version,
'type': 'circle',
'originX': 'left',
'originY': 'top',
'left': 0,
'top': 0,
'width': 0,
'height': 0,
'fill': 'rgb(0,0,0)',
'stroke': null,
'strokeWidth': 1,
'strokeDashArray': null,
'strokeLineCap': 'butt',
'strokeDashOffset': 0,
'strokeLineJoin': 'miter',
'strokeMiterLimit': 4,
'scaleX': 1,
'scaleY': 1,
'angle': 0,
'flipX': false,
'flipY': false,
'opacity': 1,
'shadow': null,
'visible': true,
'backgroundColor': '',
'fillRule': 'nonzero',
'paintFirst': 'fill',
'globalCompositeOperation': 'source-over',
'radius': 0,
'startAngle': 0,
'endAngle': 2 * Math.PI,
'skewX': 0,
'skewY': 0,
version: fabric.version,
type: 'circle',
originX: 'left',
originY: 'top',
left: 0,
top: 0,
width: 0,
height: 0,
fill: 'rgb(0,0,0)',
stroke: null,
strokeWidth: 1,
strokeDashArray: null,
strokeLineCap: 'butt',
strokeDashOffset: 0,
strokeLineJoin: 'miter',
strokeMiterLimit: 4,
scaleX: 1,
scaleY: 1,
angle: 0,
flipX: false,
flipY: false,
opacity: 1,
shadow: null,
visible: true,
backgroundColor: '',
fillRule: 'nonzero',
paintFirst: 'fill',
globalCompositeOperation: 'source-over',
radius: 0,
startAngle: 0,
endAngle: 2 * Math.PI,
skewX: 0,
skewY: 0,
strokeUniform: false
};
assert.ok(typeof circle.toObject === 'function');
assert.deepEqual(circle.toObject(), defaultProperties);
Expand Down
65 changes: 33 additions & 32 deletions test/unit/ellipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,39 @@
QUnit.test('toObject', function(assert) {
var ellipse = new fabric.Ellipse();
var defaultProperties = {
'version': fabric.version,
'type': 'ellipse',
'originX': 'left',
'originY': 'top',
'left': 0,
'top': 0,
'width': 0,
'height': 0,
'fill': 'rgb(0,0,0)',
'stroke': null,
'strokeWidth': 1,
'strokeDashArray': null,
'strokeLineCap': 'butt',
'strokeDashOffset': 0,
'strokeLineJoin': 'miter',
'strokeMiterLimit': 4,
'scaleX': 1,
'scaleY': 1,
'angle': 0,
'flipX': false,
'flipY': false,
'opacity': 1,
'skewX': 0,
'skewY': 0,
'rx': 0,
'ry': 0,
'shadow': null,
'visible': true,
'backgroundColor': '',
'fillRule': 'nonzero',
'paintFirst': 'fill',
'globalCompositeOperation': 'source-over',
version: fabric.version,
type: 'ellipse',
originX: 'left',
originY: 'top',
left: 0,
top: 0,
width: 0,
height: 0,
fill: 'rgb(0,0,0)',
stroke: null,
strokeWidth: 1,
strokeDashArray: null,
strokeLineCap: 'butt',
strokeDashOffset: 0,
strokeLineJoin: 'miter',
strokeMiterLimit: 4,
scaleX: 1,
scaleY: 1,
angle: 0,
flipX: false,
flipY: false,
opacity: 1,
skewX: 0,
skewY: 0,
rx: 0,
ry: 0,
shadow: null,
visible: true,
backgroundColor: '',
fillRule: 'nonzero',
paintFirst: 'fill',
globalCompositeOperation: 'source-over',
strokeUniform: false,
};
assert.ok(typeof ellipse.toObject === 'function');
assert.deepEqual(ellipse.toObject(), defaultProperties);
Expand Down
Loading

0 comments on commit 31007b6

Please sign in to comment.