Skip to content

Commit

Permalink
Merge pull request #469 from Kienz/GradientsSVGOutput
Browse files Browse the repository at this point in the history
[BACK_INCOMPAT] Implement fabric.Gradient#toSVG() and radialGradient
  • Loading branch information
kangax committed Mar 9, 2013
2 parents ece75b6 + 5fec23e commit 5e177b2
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 106 deletions.
25 changes: 19 additions & 6 deletions src/circle.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,25 @@
* @return {String} svg representation of an instance
*/
toSVG: function() {
return ('<circle ' +
'cx="0" cy="0" ' +
'r="' + this.radius + '" ' +
'style="' + this.getSvgStyles() + '" ' +
'transform="' + this.getSvgTransform() + '" ' +
'/>');
var markup = [];

if (this.fill && this.fill.toLive) {
markup.push(this.fill.toSVG(this, false));
}
if (this.stroke && this.stroke.toLive) {
markup.push(this.stroke.toSVG(this, false));
}

markup.push(
'<circle ',
'cx="0" cy="0" ',
'r="', this.radius,
'" style="', this.getSvgStyles(),
'" transform="', this.getSvgTransform(),
'"/>'
);

return markup.join('');
},

/**
Expand Down
33 changes: 32 additions & 1 deletion src/color.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@
* @method _tryParsingColor
*/
_tryParsingColor: function(color) {
var source = Color.sourceFromHex(color);
var source;

if (color in Color.colorNameMap) {
color = Color.colorNameMap[color];
}

source = Color.sourceFromHex(color);

if (!source) {
source = Color.sourceFromRgb(color);
}
Expand Down Expand Up @@ -197,6 +204,30 @@
*/
fabric.Color.reHex = /^#?([0-9a-f]{6}|[0-9a-f]{3})$/i;

/**
* Map of the 16 basic color names with HEX code
* @static
* @field
*/
fabric.Color.colorNameMap = {
'aqua': '#00FFFF',
'black': '#000000',
'blue': '#0000FF',
'fuchsia': '#FF00FF',
'gray': '#808080',
'green': '#008000',
'lime': '#00FF00',
'maroon': '#800000',
'navy': '#000080',
'olive': '#808000',
'purple': '#800080',
'red': '#FF0000',
'silver': '#C0C0C0',
'teal': '#008080',
'white': '#FFFFFF',
'yellow': '#FFFF00'
};

/**
* Returns new color object, when given a color in RGB format
* @method fromRgb
Expand Down
25 changes: 18 additions & 7 deletions src/ellipse.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,25 @@
* @return {String} svg representation of an instance
*/
toSVG: function() {
return [
var markup = [];

if (this.fill && this.fill.toLive) {
markup.push(this.fill.toSVG(this, false));
}
if (this.stroke && this.stroke.toLive) {
markup.push(this.stroke.toSVG(this, false));
}

markup.push(
'<ellipse ',
'rx="', this.get('rx'), '" ',
'ry="', this.get('ry'), '" ',
'style="', this.getSvgStyles(), '" ',
'transform="', this.getSvgTransform(), '" ',
'/>'
].join('');
'rx="', this.get('rx'),
'" ry="', this.get('ry'),
'" style="', this.getSvgStyles(),
'" transform="', this.getSvgTransform(),
'"/>'
);

return markup.join('');
},

/**
Expand Down

0 comments on commit 5e177b2

Please sign in to comment.