From 4154cf975a9a458dab4af4610010c3faddbdcad4 Mon Sep 17 00:00:00 2001 From: wout Date: Sat, 13 Apr 2013 20:57:44 +0100 Subject: Ensure center point for rotations --- src/element.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/element.js b/src/element.js index b069d3a..269d61b 100644 --- a/src/element.js +++ b/src/element.js @@ -200,6 +200,15 @@ SVG.extend(SVG.Element, { /* parse matrix */ o = this._parseMatrix(o) + /* ensure correct rotation center point */ + if (o.rotation != null) { + if (o.cx == null) + o.cx = this.bbox().cx + + if (o.cy == null) + o.cy = this.bbox().cy + } + /* merge values */ for (v in o) if (o[v] != null) @@ -221,13 +230,8 @@ SVG.extend(SVG.Element, { transform.push('matrix(' + o.matrix + ')') /* add rotation */ - if (o.rotation != 0) { - transform.push( - 'rotate(' + o.rotation + ',' - + (o.cx != null ? o.cx : this.bbox().cx) + ',' - + (o.cy != null ? o.cy : this.bbox().cy) + ')' - ) - } + if (o.rotation != 0) + transform.push('rotate(' + o.rotation + ',' + o.cx + ',' + o.cy + ')') /* add scale */ if (o.scaleX != 1 || o.scaleY != 1) -- cgit v1.2.3