mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Correctly fix SVG alpha support through opacity attributes.
This commit is contained in:
parent
14e6edb8ee
commit
68dc7e8b12
2 changed files with 9 additions and 6 deletions
|
@ -477,10 +477,11 @@ var Color = this.Color = Base.extend(new function() {
|
|||
/**
|
||||
* @return {String} A css string representation of the color.
|
||||
*/
|
||||
toCss: function(withAlpha) {
|
||||
if (!this._css) {
|
||||
toCss: function(noAlpha) {
|
||||
var css = this._css;
|
||||
if (!css || noAlpha) {
|
||||
var color = this.convert('rgb'),
|
||||
alpha = withAlpha === undefined || withAlpha ? color.getAlpha() : 1,
|
||||
alpha = noAlpha ? 1 : color.getAlpha(),
|
||||
components = [
|
||||
Math.round(color._red * 255),
|
||||
Math.round(color._green * 255),
|
||||
|
@ -488,10 +489,12 @@ var Color = this.Color = Base.extend(new function() {
|
|||
];
|
||||
if (alpha < 1)
|
||||
components.push(alpha);
|
||||
this._css = (components.length == 4 ? 'rgba(' : 'rgb(')
|
||||
var css = (components.length == 4 ? 'rgba(' : 'rgb(')
|
||||
+ components.join(', ') + ')';
|
||||
if (!noAlpha)
|
||||
this._css = css;
|
||||
}
|
||||
return this._css;
|
||||
return css;
|
||||
},
|
||||
|
||||
getCanvasStyle: function() {
|
||||
|
|
|
@ -349,7 +349,7 @@ new function() {
|
|||
attrs[entry.attribute] = value == null
|
||||
? 'none'
|
||||
: entry.type === 'color'
|
||||
? value.toCss(false) // false for withAlpha, see above
|
||||
? value.toCss(true) // false for noAlpha, see above
|
||||
: entry.type === 'array'
|
||||
? value.join(',')
|
||||
: entry.type === 'number'
|
||||
|
|
Loading…
Reference in a new issue