fix text context and complete gradient js code

This commit is contained in:
Horcrux
2016-04-26 22:08:54 +08:00
parent 1baf00c034
commit 902bdcb1d0
17 changed files with 72 additions and 154 deletions
+3 -32
View File
@@ -4,41 +4,11 @@ const LINEAR_GRADIENT = 1;
const RADIAL_GRADIENT = 2;
const PATTERN = 3;
function applyBoundingBoxToBrushData(brushData, props) {
let type = brushData[0];
let width = +props.width;
let height = +props.height;
if (type === LINEAR_GRADIENT) {
brushData[1] *= width;
brushData[2] *= height;
brushData[3] *= width;
brushData[4] *= height;
} else if (type === RADIAL_GRADIENT) {
brushData[1] *= width;
brushData[2] *= height;
brushData[3] *= width;
brushData[4] *= height;
brushData[5] *= width;
brushData[6] *= height;
} else if (type === PATTERN) {
// todo
}
}
export default function (colorOrBrush, props) {
export default function (colorOrBrush) {
if (!colorOrBrush) {
return null;
}
if (colorOrBrush._brush) {
if (colorOrBrush._bb) {
// The legacy API for Gradients allow for the bounding box to be used
// as a convenience for specifying gradient positions. This should be
// deprecated. It's not properly implemented in canvas mode. ReactART
// doesn't handle update to the bounding box correctly. That's why we
// mutate this so that if it's reused, we reuse the same resolved box.
applyBoundingBoxToBrushData(colorOrBrush._brush, props);
colorOrBrush._bb = false;
}
return colorOrBrush._brush;
}
@@ -48,5 +18,6 @@ export default function (colorOrBrush, props) {
export {
LINEAR_GRADIENT,
RADIAL_GRADIENT
RADIAL_GRADIENT,
PATTERN
}
+4 -4
View File
@@ -7,13 +7,13 @@ const fillRules = {
nonzero: 1
};
function fillFilter(props, dimensions) {
function fillFilter(props) {
let {fill} = props;
if (fill === 'none') {
return null;
} else if (fill) {
return patterns(fill, +props.fillOpacity, dimensions, props.svgId);
return patterns(fill, +props.fillOpacity, props.svgId);
} else if (props.fill === undefined) {
let fillOpacity = +props.fillOpacity;
if (isNaN(fillOpacity)) {
@@ -25,8 +25,8 @@ function fillFilter(props, dimensions) {
}
}
export default function(props, dimensions) {
let fill = extractBrush(fillFilter(props, dimensions), props);
export default function(props) {
let fill = extractBrush(fillFilter(props), props);
let fillRule = fillRules[props.fillRule] === 0 ? 0 : 1;
return {
+2 -4
View File
@@ -14,18 +14,16 @@ export default function(props, options = {stroke: true, join: true, transform: t
opacity: +props.opacity || 1
};
let dimensions = this.getBoundingBox ? this.getBoundingBox() : null;
if (props.clipPath) {
_.assign(extractedProps, extractClipping(props));
}
if (options.stroke) {
_.assign(extractedProps, extractStroke(props, dimensions));
_.assign(extractedProps, extractStroke(props));
}
if (options.fill) {
_.assign(extractedProps, extractFill(props, dimensions));
_.assign(extractedProps, extractFill(props));
}
if (options.transform) {
+4 -4
View File
@@ -15,7 +15,7 @@ const joins = {
round: 1
};
function strokeFilter(props, dimensions) {
function strokeFilter(props) {
let strokeWidth = +props.strokeWidth;
let {stroke} = props;
if (!strokeWidth && !stroke) {
@@ -39,7 +39,7 @@ function strokeFilter(props, dimensions) {
// TODO: propTypes check
return {
stroke: patterns(stroke, +props.strokeOpacity, dimensions, props.svgId),
stroke: patterns(stroke, +props.strokeOpacity, props.svgId),
strokeLinecap: caps[props.strokeLinecap] || 0,
strokeLinejoin: joins[props.strokeLinejoin] || 0,
strokeDasharray: strokeDasharray || null,
@@ -48,8 +48,8 @@ function strokeFilter(props, dimensions) {
};
}
export default function(props, dimensions) {
let strokeProps = strokeFilter(props, dimensions);
export default function(props) {
let strokeProps = strokeFilter(props);
return strokeProps ? {
...strokeProps,
+3 -3
View File
@@ -76,9 +76,9 @@ function extractFont(font) {
}
const anchord = {
right: 1,
center: 2,
left: 0
end: 1,
middle: 2,
start: 0
};
export default function(props) {
+2 -6
View File
@@ -23,7 +23,7 @@ export {
remove
}
export default function(patternSting, opacity, dimensions, svgId) {
export default function(patternSting, opacity, svgId) {
if (isGradient(patternSting)) {
return patternSting;
}
@@ -40,11 +40,7 @@ export default function(patternSting, opacity, dimensions, svgId) {
let pattern = patterns[patternName];
if (pattern) {
if (pattern.length === 2) {
return pattern(dimensions, opacity);
} else {
return pattern(opacity);
}
return pattern(opacity);
}
return null;
}