Fix issue with svg-gradient breaking the opacity

This commit is contained in:
Luke Page
2013-07-10 17:16:56 +01:00
parent b711d16f0d
commit c68352dc17
2 changed files with 14 additions and 13 deletions

View File

@@ -554,8 +554,7 @@ tree.functions = {
}
positionValue = position ? position.toCSS(renderEnv) : i === 0 ? "0%" : "100%";
alpha = color.alpha;
color.alpha = 1;
returner += '<stop offset="' + positionValue + '" stop-color="' + color.toCSS(renderEnv) + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : '') + '/>';
returner += '<stop offset="' + positionValue + '" stop-color="' + color.toRGB() + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : '') + '/>';
}
returner += '</' + gradientType + 'Gradient>' +
'<rect ' + rectangleDimension + ' fill="url(#gradient)" /></svg>';

View File

@@ -40,24 +40,18 @@ tree.Color.prototype = {
return Math.round(c);
}).concat(this.alpha).join(',' + (compress ? '' : ' ')) + ")";
} else {
var color = this.rgb.map(function (i) {
i = Math.round(i);
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
return i.length === 1 ? '0' + i : i;
}).join('');
var color = this.toRGB();
if (compress) {
color = color.split('');
var splitcolor = color.split('');
// Convert color to short format
if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
color = color[0] + color[2] + color[4];
} else {
color = color.join('');
if (splitcolor[1] == splitcolor[2] && splitcolor[3] == splitcolor[4] && splitcolor[5] == splitcolor[6]) {
color = '#' + splitcolor[1] + splitcolor[3] + splitcolor[5];
}
}
return '#' + color;
return color;
}
},
@@ -80,6 +74,14 @@ tree.Color.prototype = {
return new(tree.Color)(result, this.alpha + other.alpha);
},
toRGB: function () {
return '#' + this.rgb.map(function (i) {
i = Math.round(i);
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
return i.length === 1 ? '0' + i : i;
}).join('');
},
toHSL: function () {
var r = this.rgb[0] / 255,
g = this.rgb[1] / 255,