2012-08-10 15:14:56 +00:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
|
var REFERENCE_RECT = {
|
2014-09-21 18:55:00 +00:00
|
|
|
'type': 'rect',
|
|
|
|
|
'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',
|
|
|
|
|
'strokeLineJoin': 'miter',
|
|
|
|
|
'strokeMiterLimit': 10,
|
|
|
|
|
'scaleX': 1,
|
|
|
|
|
'scaleY': 1,
|
|
|
|
|
'angle': 0,
|
|
|
|
|
'flipX': false,
|
|
|
|
|
'flipY': false,
|
|
|
|
|
'opacity': 1,
|
|
|
|
|
'shadow': null,
|
|
|
|
|
'visible': true,
|
|
|
|
|
'backgroundColor': '',
|
|
|
|
|
'clipTo': null,
|
|
|
|
|
'fillRule': 'nonzero',
|
|
|
|
|
'globalCompositeOperation': 'source-over',
|
2015-07-19 23:28:38 +00:00
|
|
|
'transformMatrix': null,
|
2014-09-21 18:55:00 +00:00
|
|
|
'rx': 0,
|
|
|
|
|
'ry': 0,
|
2015-09-02 19:28:57 +00:00
|
|
|
'skewX': 0,
|
|
|
|
|
'skewY': 0,
|
2012-08-10 15:14:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QUnit.module('fabric.Rect');
|
|
|
|
|
|
|
|
|
|
test('constructor', function(){
|
|
|
|
|
ok(fabric.Rect);
|
|
|
|
|
|
|
|
|
|
var rect = new fabric.Rect();
|
|
|
|
|
|
|
|
|
|
ok(rect instanceof fabric.Rect);
|
|
|
|
|
ok(rect instanceof fabric.Object);
|
|
|
|
|
|
|
|
|
|
deepEqual(rect.get('type'), 'rect');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('complexity', function() {
|
|
|
|
|
var rect = new fabric.Rect();
|
|
|
|
|
|
|
|
|
|
ok(typeof rect.complexity == 'function');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('toObject', function() {
|
|
|
|
|
var rect = new fabric.Rect();
|
|
|
|
|
ok(typeof rect.toObject == 'function');
|
|
|
|
|
|
|
|
|
|
var object = rect.toObject();
|
|
|
|
|
deepEqual(object, REFERENCE_RECT);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('fabric.Rect.fromObject', function() {
|
|
|
|
|
ok(typeof fabric.Rect.fromObject == 'function');
|
|
|
|
|
|
|
|
|
|
var rect = fabric.Rect.fromObject(REFERENCE_RECT);
|
|
|
|
|
ok(rect instanceof fabric.Rect);
|
|
|
|
|
deepEqual(rect.toObject(), REFERENCE_RECT);
|
2015-05-09 08:25:25 +00:00
|
|
|
|
|
|
|
|
var expectedObject = fabric.util.object.extend({ }, REFERENCE_RECT);
|
|
|
|
|
expectedObject.fill = {"type":"linear","coords":{"x1":0,"y1":0,"x2":200,"y2":0},"colorStops":[{"offset":"0","color":"rgb(255,0,0)","opacity":1},{"offset":"1","color":"rgb(0,0,255)","opacity":1}],"offsetX":0,"offsetY":0};
|
|
|
|
|
expectedObject.stroke = {"type":"linear","coords":{"x1":0,"y1":0,"x2":200,"y2":0},"colorStops":[{"offset":"0","color":"rgb(255,0,0)","opacity":1},{"offset":"1","color":"rgb(0,0,255)","opacity":1}],"offsetX":0,"offsetY":0};
|
|
|
|
|
rect = fabric.Rect.fromObject(expectedObject);
|
|
|
|
|
ok(rect.fill instanceof fabric.Gradient);
|
|
|
|
|
ok(rect.stroke instanceof fabric.Gradient);
|
2012-08-10 15:14:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('fabric.Rect.fromElement', function() {
|
|
|
|
|
ok(typeof fabric.Rect.fromElement == 'function');
|
|
|
|
|
|
|
|
|
|
var elRect = fabric.document.createElement('rect');
|
|
|
|
|
var rect = fabric.Rect.fromElement(elRect);
|
2015-02-02 23:02:16 +00:00
|
|
|
var expectedObject = fabric.util.object.extend({ }, REFERENCE_RECT);
|
|
|
|
|
expectedObject.visible = false;
|
2012-08-10 15:14:56 +00:00
|
|
|
ok(rect instanceof fabric.Rect);
|
2015-02-02 23:02:16 +00:00
|
|
|
deepEqual(rect.toObject(), expectedObject);
|
2012-08-11 16:59:53 +00:00
|
|
|
});
|
2012-08-10 15:14:56 +00:00
|
|
|
|
2012-08-11 16:59:53 +00:00
|
|
|
test('fabric.Rect.fromElement with custom attributes', function() {
|
2012-08-10 15:14:56 +00:00
|
|
|
var elRectWithAttrs = fabric.document.createElement('rect');
|
2012-08-11 16:59:53 +00:00
|
|
|
|
2012-08-10 15:14:56 +00:00
|
|
|
elRectWithAttrs.setAttribute('x', 10);
|
|
|
|
|
elRectWithAttrs.setAttribute('y', 20);
|
|
|
|
|
elRectWithAttrs.setAttribute('width', 222);
|
|
|
|
|
elRectWithAttrs.setAttribute('height', 333);
|
|
|
|
|
elRectWithAttrs.setAttribute('rx', 11);
|
|
|
|
|
elRectWithAttrs.setAttribute('ry', 12);
|
|
|
|
|
elRectWithAttrs.setAttribute('fill', 'rgb(255,255,255)');
|
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
|
|
|
elRectWithAttrs.setAttribute('opacity', 0.45);
|
2012-08-10 15:14:56 +00:00
|
|
|
elRectWithAttrs.setAttribute('stroke', 'blue');
|
|
|
|
|
elRectWithAttrs.setAttribute('stroke-width', 3);
|
2013-05-18 11:01:34 +00:00
|
|
|
elRectWithAttrs.setAttribute('stroke-dasharray', '5, 2');
|
|
|
|
|
elRectWithAttrs.setAttribute('stroke-linecap', 'round');
|
|
|
|
|
elRectWithAttrs.setAttribute('stroke-linejoin', 'bevil');
|
|
|
|
|
elRectWithAttrs.setAttribute('stroke-miterlimit', 5);
|
2012-08-10 15:14:56 +00:00
|
|
|
//elRectWithAttrs.setAttribute('transform', 'translate(-10,-20) scale(2) rotate(45) translate(5,10)');
|
|
|
|
|
|
|
|
|
|
var rectWithAttrs = fabric.Rect.fromElement(elRectWithAttrs);
|
|
|
|
|
ok(rectWithAttrs instanceof fabric.Rect);
|
|
|
|
|
|
|
|
|
|
var expectedObject = fabric.util.object.extend(REFERENCE_RECT, {
|
2014-08-05 11:19:53 +00:00
|
|
|
left: 10,
|
|
|
|
|
top: 20,
|
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
|
|
|
width: 222,
|
|
|
|
|
height: 333,
|
|
|
|
|
fill: 'rgb(255,255,255)',
|
|
|
|
|
opacity: 0.45,
|
|
|
|
|
stroke: 'blue',
|
|
|
|
|
strokeWidth: 3,
|
|
|
|
|
strokeDashArray: [5, 2],
|
|
|
|
|
strokeLineCap: 'round',
|
|
|
|
|
strokeLineJoin: 'bevil',
|
2013-05-18 11:01:34 +00:00
|
|
|
strokeMiterLimit: 5,
|
Parse SVG stroke-opacity and fill-opacity
- SVG attribute opacity is now used for object's opacity
- fill-opacity and stroke-opacity are added to stroke and fill color value
- Add hsl/hsla support (e.g. hsl(270, 80%, 10%), hsla(320, 10%, 66%, 0.5))
- Add support for rgb/rgba values with whitespaces around values (e.g. rgba( 255 , 100 , 50 , 0.1 )) and percentage values (e.g. rgb(100%, 67%, 15%, 0.8))
- Delete stroke and strokeWidth from fabric.Text (defined in fabric.Object)
- New unit test for parse stroke-opacity and fill-opacity
- Update unit tests (new tests for hsl/hsla and rgb/rgba (whitespaces and percentage values))
- Change equal and deepEqual parameter order (e.g. equal(actualValue, expectedValue, message))
- Doc additions
2013-05-25 09:03:09 +00:00
|
|
|
rx: 11,
|
2014-08-05 11:19:53 +00:00
|
|
|
ry: 12
|
2012-08-10 15:14:56 +00:00
|
|
|
});
|
|
|
|
|
deepEqual(rectWithAttrs.toObject(), expectedObject);
|
2012-08-11 16:59:53 +00:00
|
|
|
});
|
2012-08-10 15:14:56 +00:00
|
|
|
|
2012-08-11 16:59:53 +00:00
|
|
|
test('empty fromElement', function() {
|
2012-08-10 15:14:56 +00:00
|
|
|
ok(fabric.Rect.fromElement() === null);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('clone with rounded corners', function() {
|
|
|
|
|
var rect = new fabric.Rect({ width: 100, height: 100, rx: 20, ry: 30 });
|
|
|
|
|
var clone = rect.clone();
|
|
|
|
|
|
|
|
|
|
equal(clone.get('rx'), rect.get('rx'));
|
|
|
|
|
equal(clone.get('ry'), rect.get('ry'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('toSVG with rounded corners', function() {
|
2015-04-28 02:27:00 +00:00
|
|
|
var rect = new fabric.Rect({ width: 100, height: 100, rx: 20, ry: 30, strokeWidth: 0 });
|
2012-08-10 15:14:56 +00:00
|
|
|
var svg = rect.toSVG();
|
|
|
|
|
|
2015-05-18 06:00:36 +00:00
|
|
|
equal(svg, '<rect x="-50" y="-50" rx="20" ry="30" width="100" height="100" style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;" transform="translate(50 50)"/>\n');
|
2012-08-10 15:14:56 +00:00
|
|
|
});
|
2013-09-28 21:46:14 +00:00
|
|
|
|
|
|
|
|
test('toObject without default values', function() {
|
|
|
|
|
var options = { type: 'rect', width: 69, height: 50, left: 10, top: 20 };
|
|
|
|
|
var rect = new fabric.Rect(options);
|
|
|
|
|
rect.includeDefaultValues = false;
|
|
|
|
|
deepEqual(rect.toObject(), options);
|
|
|
|
|
});
|
2013-06-02 21:04:54 +00:00
|
|
|
})();
|