Merge pull request #2414 from asturur/offset-stop

Offset stop
This commit is contained in:
Juriy Zaytsev 2015-08-12 14:50:36 -04:00
commit b9ca706d4a
2 changed files with 26 additions and 1 deletions

View file

@ -3,7 +3,7 @@
/* _FROM_SVG_START_ */
function getColorStop(el) {
var style = el.getAttribute('style'),
offset = el.getAttribute('offset'),
offset = el.getAttribute('offset') || 0,
color, colorAlpha, opacity;
// convert percents to absolute values

View file

@ -177,6 +177,31 @@
equal(gradient.colorStops[0].opacity, 0);
});
test('fromElement without stop', function() {
ok(typeof fabric.Gradient.fromElement == 'function');
var element = fabric.document.createElement('linearGradient');
var stop1 = fabric.document.createElement('stop');
var stop2 = fabric.document.createElement('stop');
stop1.setAttribute('stop-color', 'white');
stop2.setAttribute('offset', '100%');
stop2.setAttribute('stop-color', 'black');
stop2.setAttribute('stop-opacity', '0');
element.appendChild(stop1);
element.appendChild(stop2);
var object = new fabric.Object({ width: 100, height: 100 });
var gradient = fabric.Gradient.fromElement(element, object);
ok(gradient instanceof fabric.Gradient);
equal(gradient.colorStops[0].offset, 1);
equal(gradient.colorStops[1].offset, 0);
});
test('fromElement radialGradient', function() {
ok(typeof fabric.Gradient.fromElement == 'function');