diff --git a/src/svg/SvgExporter.js b/src/svg/SvgExporter.js index ab734e85..3fd71c1b 100644 --- a/src/svg/SvgExporter.js +++ b/src/svg/SvgExporter.js @@ -30,10 +30,8 @@ var SvgExporter = this.SvgExporter = new function() { } function setAttributes(svg, attrs) { - for (var key in attrs) { - console.log(key + ', ' + attrs[key]); + for (var key in attrs) svg.setAttribute(key, attrs[key]); - } } function exportGroup(group) { @@ -41,6 +39,10 @@ var SvgExporter = this.SvgExporter = new function() { children = group._children; for (var i = 0, l = children.length; i < l; i++) svg.appendChild(SvgExporter.exportItem(children[i])); + // Override default SVG style on groups, then apply style. + setAttributes(svg, { + fill: 'none' + }); applyStyle(group, svg); return svg; } @@ -354,9 +356,9 @@ var SvgExporter = this.SvgExporter = new function() { Base.each(SvgStyles.properties, function(entry) { // Get a given style only if it differs from the value on the parent // (A layer or group which can have style values in SVG). - var value = style[entry.getter](); + var value = style[entry.get](); if (value != null && (!parentStyle - || !Base.equals(parentStyle[entry.getter](), value))) { + || !Base.equals(parentStyle[entry.get](), value))) { attrs[entry.attribute] = entry.type === 'color' ? value.toCssString() : entry.type === 'array' diff --git a/src/svg/SvgStyles.js b/src/svg/SvgStyles.js index 1a75611a..47acf474 100644 --- a/src/svg/SvgStyles.js +++ b/src/svg/SvgStyles.js @@ -1,3 +1,19 @@ +/* + * Paper.js + * + * This file is part of Paper.js, a JavaScript Vector Graphics Library, + * based on Scriptographer.org and designed to be largely API compatible. + * http://paperjs.org/ + * http://scriptographer.org/ + * + * Copyright (c) 2011, Juerg Lehni & Jonathan Puckey + * http://lehni.org/ & http://jonathanpuckey.com/ + * + * Distributed under the MIT license. See LICENSE file for details. + * + * All rights reserved. + */ + var SvgStyles = Base.each({ fillColor: 'fill', strokeColor: 'stroke', @@ -8,6 +24,7 @@ var SvgStyles = Base.each({ dashArray: 'stroke-dasharray', dashOffset: 'stroke-dashoffset' }, function(attr, prop) { + var part = Base.capitalize(prop); this.attributes[attr] = this.properties[prop] = { type: /Color$/.test(prop) ? 'color' @@ -16,7 +33,8 @@ var SvgStyles = Base.each({ : 'value', property: prop, attribute: attr, - getter: 'get' + Base.capitalize(prop) + get: 'get' + part, + set: 'set' + part }; }, { properties: {},