From be5a73a61d84542e43b58e955e6c9628feac138b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 16 Oct 2013 16:47:00 +0200 Subject: [PATCH] SVG: Implement support for Shape. --- src/item/Shape.js | 2 +- src/svg/SVGExport.js | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/item/Shape.js b/src/item/Shape.js index 7152cc53..998b8212 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -22,7 +22,7 @@ var Shape = Item.extend(/** @lends Shape# */{ _transformContent: false, _boundsSelected: true, - // TODO: SVG, serialization + // TODO: serialization initialize: function Shape(shape, point, size, radius, props) { this._shape = shape; diff --git a/src/svg/SVGExport.js b/src/svg/SVGExport.js index 2677e6d1..33391f33 100644 --- a/src/svg/SVGExport.js +++ b/src/svg/SVGExport.js @@ -41,7 +41,7 @@ new function() { return segments[index1]._point.getDistance(segments[index2]._point); } - function getTransform(item, coordinates) { + function getTransform(item, coordinates, center) { var matrix = item._matrix, trans = matrix.getTranslation(), attrs = {}; @@ -54,8 +54,8 @@ new function() { // in local coordinates. matrix = matrix.shiftless(); var point = matrix._inverseTransform(trans); - attrs.x = point.x; - attrs.y = point.y; + attrs[center ? 'cx' : 'x'] = point.x; + attrs[center ? 'cy' : 'y'] = point.y; trans = null; } if (matrix.isIdentity()) @@ -296,6 +296,34 @@ new function() { return createElement(type, attrs); } + function exportShape(item) { + var shape = item._shape, + center = item.getPosition(true), + radius = item._radius, + attrs = getTransform(item, true, shape !== 'rectangle'); + if (shape === 'rectangle') { + shape = 'rect'; // SVG + var size = item._size, + width = size.width, + height = size.height; + attrs.x -= width / 2; + attrs.y -= height / 2; + attrs.width = width; + attrs.height = height; + if (radius.isZero()) + radius = null; + } + if (radius) { + if (shape === 'circle') { + attrs.r = radius; + } else { + attrs.rx = radius.width; + attrs.ry = radius.height; + } + } + return createElement(shape, attrs); + } + function exportCompoundPath(item) { var attrs = getTransform(item, true); var data = item.getPathData(); @@ -393,6 +421,7 @@ new function() { layer: exportGroup, raster: exportRaster, path: exportPath, + shape: exportShape, 'compound-path': exportCompoundPath, 'placed-symbol': exportPlacedSymbol, 'point-text': exportText