Fixed wrong viewBox in IE, matrix invert method, pathDimention caching.
[raphael] / raphael.js
index 8af6840..57720ce 100644 (file)
             width: mmax[apply](0, X) - xmin,
             height: mmax[apply](0, Y) - ymin
         };
+    }, null, function (o) {
+        return {
+            x: o.x,
+            y: o.y,
+            width: o.width,
+            height: o.height
+        };
     }),
         pathClone = function (pathArray) {
             var res = [];
     };
     function Matrix(a, b, c, d, e, f) {
         if (a != null) {
-            this.a = a;
-            this.b = b;
-            this.c = c;
-            this.d = d;
-            this.e = e;
-            this.f = f;
+            this.a = +a;
+            this.b = +b;
+            this.c = +c;
+            this.d = +d;
+            this.e = +e;
+            this.f = +f;
         } else {
             this.a = 1;
             this.b = 0;
         this.f = out[1][2];
     };
     matrixproto.invert = function () {
-        var x = a * d - b * c;
-        return new Matrix(d / x, -b / x, -c / x, a / x, (c * f - d * e) / x, (b * e - a * f) / x);
+        var me = this,
+            x = me.a * me.d - me.b * me.c;
+        return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x);
     };
     matrixproto.clone = function () {
         return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
         \*/
         elproto.transform = function (tstr) {
             var _ = this._;
-            if (!tstr) {
+            if (tstr == null) {
                 return _.transform;
             }
             extractTransform(this, tstr);
             }
             extractTransform(this, tstr);
             var matrix = this.matrix.clone(),
+                vbs = this.paper._viewBoxShift,
                 skew = this.skew;
             matrix.translate(-.5, -.5);
+            if (vbs) {
+                matrix.scale(vbs.scale, vbs.scale, -1, -1);
+                matrix.add(1, 0, 0, 1, vbs.dx, vbs.dy);
+            }
             if (this.type == "image") {
                 if (Str(tstr).indexOf("m") + 1) {
                     this.node.style.filter = matrix.toFilter();
                     // angle = fill.angle;
 
                 this.node.style.filter = E;
-                skew.matrix = matrix;
+                skew.matrix = Str(matrix);
                 skew.offset = matrix.offset();
                 
                 // if (0&&angle) {
             eve("setViewBox", this, this._viewBox, [x, y, w, h, fit]);
             var width = this.width,
                 height = this.height,
-                size = 1e3 * mmax(w / width, h / height),
+                size = 1 / mmax(w / width, h / height),
                 H, W;
             if (fit) {
                 H = height / h;
                 }
             }
             this._viewBox = [x, y, w, h, !!fit];
+            this._viewBoxShift = {
+                dx: -x,
+                dy: -y,
+                scale: size
+            };
             this.forEach(function (el) {
                 el.transform("...");
             });
             }
             _.bbox = pathDimensions(mapPath(this.realPath, this.matrix));
             _.bbox.toString = x_y_w_h;
+            console.log(mapPath(this.realPath, this.matrix)+"");
             _.dirty = _.dirtyT = 0;
         }
         return _.bbox;