fix rgba fill and stroke bug

This commit is contained in:
Horcrux
2016-06-10 23:33:18 +08:00
parent dba1fb2801
commit 239e1c928d
4 changed files with 14 additions and 13 deletions
+3 -6
View File
@@ -9,17 +9,14 @@ const fillRules = {
function fillFilter(props) { function fillFilter(props) {
let {fill} = props; let {fill} = props;
let fillOpacity = +props.fillOpacity;
if (fill === 'none') { if (fill === 'none') {
return null; return null;
} else if (fill) { } else if (fill) {
return patterns(fill, +props.fillOpacity, props.svgId); return patterns(fill, fillOpacity, props.svgId);
} else if (props.fill === undefined) { } else if (props.fill === undefined) {
let fillOpacity = +props.fillOpacity; return rgba('#000', isNaN(fillOpacity) ? 1 : fillOpacity).rgbaString();
if (isNaN(fillOpacity)) {
fillOpacity = 1;
}
return rgba('#000', fillOpacity).rgbaString();
} else { } else {
return null; return null;
} }
-4
View File
@@ -28,10 +28,6 @@ export default function(patternSting, opacity, svgId) {
return patternSting; return patternSting;
} }
if (isNaN(opacity)) {
opacity = 1;
}
// 尝试匹配 "url(#pattern)" // 尝试匹配 "url(#pattern)"
let matched = patternSting.match(patternReg); let matched = patternSting.match(patternReg);
+7 -2
View File
@@ -1,9 +1,14 @@
import Color from 'color'; import Color from 'color';
let noneFill = ['transparent', 'none']; let noneFill = ['transparent', 'none'];
export default function (color, opacity = 1) { export default function (color, opacity) {
if (noneFill.indexOf(color) !== -1 || !color) { if (noneFill.indexOf(color) !== -1 || !color) {
return Color('#000'); return Color('#000');
} else { } else {
return Color(color).alpha(+opacity); let c = Color(color);
if (!isNaN(opacity)) {
c = c.alpha(opacity);
}
return c;
} }
} }
+4 -1
View File
@@ -1,5 +1,8 @@
import _ from 'lodash';
export default function (stops, opacity) { export default function (stops, opacity) {
if (isNaN(opacity)) {
opacity = 1;
}
return _.reduce(stops, (ret, color, key) => { return _.reduce(stops, (ret, color, key) => {
ret[key] = color.alpha(color.alpha() * opacity).rgbaString(); ret[key] = color.alpha(color.alpha() * opacity).rgbaString();
return ret; return ret;