From 65f1e5c66ddbac8e4d9799c14b939bcf8dec1b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 5 Nov 2012 09:05:32 -0800 Subject: [PATCH] Improve style handling in SvgExporter. --- examples/SVG Export/Rect and Attribute Testing.html | 2 +- src/svg/SvgExporter.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/examples/SVG Export/Rect and Attribute Testing.html b/examples/SVG Export/Rect and Attribute Testing.html index 4e1ff265..83934047 100644 --- a/examples/SVG Export/Rect and Attribute Testing.html +++ b/examples/SVG Export/Rect and Attribute Testing.html @@ -22,7 +22,7 @@ path1.id = "square1"; path1.strokeCap = "square"; path1.opacity = ".1"; - path1.dashArray = "[5, 2]"; + path1.dashArray = [5, 2]; path1.dashOffset = "0"; var point2 = new Point(75, 75); diff --git a/src/svg/SvgExporter.js b/src/svg/SvgExporter.js index 48e6c3af..00c8e5c3 100644 --- a/src/svg/SvgExporter.js +++ b/src/svg/SvgExporter.js @@ -39,6 +39,7 @@ 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])); + applyStyle(group, svg); return svg; } @@ -339,7 +340,8 @@ var SvgExporter = this.SvgExporter = new function() { function applyStyle(item, svg) { var attrs = {}, style = item._style, - parentStyle = item.getParent()._style, + parent = item.getParent(), + parentStyle = parent && parent._style, properties = { fillColor: 'fill', strokeColor: 'stroke', @@ -361,14 +363,15 @@ var SvgExporter = this.SvgExporter = new function() { // 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 getter = 'get' + Base.capitalize(name), - value = style[getter](), - parent = parentStyle[getter](); - if (!Base.equals(parent, value)) { - attrs[svgName] = value && /Color$/.test(name) + value = style[getter](); + if (value != null && (!parentStyle + || !Base.equals(parentStyle[getter](), value))) { + value = /Color$/.test(name) ? value.toCssString() : name == 'dashArray' ? value.join(',') : value; + attrs[svgName] = value; } });