changeset 1395:a768d74e5f49

Fix the svg:use. For a svg:use, it is a group which include the content it reference. It means that we can not tween it to its origin object directly. Instead, we need to ungroup it and then use the result matrix to generate the tweened transformation matrix. Therefore, we need to concate its matrix to the referenced object. Ad center object when the bbox-x is not available.
author wycc
date Sat, 02 Apr 2011 05:36:36 +0800
parents 4a786de1d62f
children a5672125e515
files nodejs/svg.js
diffstat 1 files changed, 31 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/svg.js	Wed Mar 30 22:24:52 2011 +0800
+++ b/nodejs/svg.js	Sat Apr 02 05:36:36 2011 +0800
@@ -39,8 +39,6 @@
 }
 
 loadSVG.prototype.load=function(mb_rt, root, filename) {
-    sys.puts(filename);
-    sys.puts(libxml);
     var doc = libxml.parseXmlFile(filename);
     var _root = doc.root();
     var nodes = _root.childNodes();
@@ -637,8 +635,12 @@
     var orig;
     
     a = node.attr("bbox-x");
-    if(!a)
+    if(!a) {
+	tgt.center = new Object();
+	tgt.center.x=0;
+	tgt.center.y=0;
 	return 0;
+    }
     
     /* bbox.orig is initial values of bbox.  The bbox is recomputed
      * according bbox.orig and current matrix.  See bbox.update().
@@ -791,10 +793,21 @@
     n.coord = pcoord;
     this._check_duplicate_src(n,pcoord);
 
-    guessPathBoundingBox(pcoord,d);
+    //guessPathBoundingBox(pcoord,d);
+    var trans = n.attr('transform');
+    if (trans)
+        parseTransform(pcoord,trans.value());
+    else {
+        pcoord.sx = 1;
+	pcoord.sy = 1;
+	pcoord.r = 0;
+	pcoord.tx = 0;
+	pcoord.ty = 0;
+    }
+
     pcoord.add_shape(path);
     this._set_paint(n, path);
-    this._set_bbox(n, path);
+    this._set_bbox(n, pcoord);
 
     make_mbnames(this.mb_rt, n, pcoord);
 };
@@ -1030,9 +1043,13 @@
 }
 
 loadSVG.prototype._check_duplicate_src=function(n,coord) {
+    if (n.name()=="use") {
+        n.coord.isuse = true
+    } else {
+        n.coord.isuse = false;
+    }
     var attr = n.attr('duplicate-src');
     if (attr == null) return;
-    sys.puts("---->"+attr.value());
     var id = attr.value();
     try {
         this.mb_rt.mbnames[id].target = coord;
@@ -1128,6 +1145,8 @@
     coord.center= new Object();
     coord.center.x = 10000;
     coord.center.y = 10000;
+    sys.puts("use id="+use_id+" "+trans);
+    sys.puts(n);
     if (trans!=null) {
 	parseTransform(coord, trans.value());
     } else {
@@ -1138,6 +1157,11 @@
 	coord.ty = 0;
         
     }
+    var attr = n.attr('duplicate-src');
+    if (attr) {
+        var src = this.mb_rt.mbnames[attr.value()];
+        multiply(coord, coord,src);
+    }
     multiply(accu,accu_matrix);
     multiply(accu,coord);
 
@@ -1147,16 +1171,7 @@
 	sys.puts("opacity=" + style.opacity);
 	coord.opacity=style.opacity;
     }
-    // For a use tag, we will duplicate the group inside it.
-    attr = n.attr('duplicate-src');
-    if (attr != null) {
-        c = this.mb_rt.mbnames[attr.value()];
-	if (c == null) {
-	    sys.puts("Can not find object "+attr.value());
-	    return;
-	}
-	coord.clone_from_subtree(c);
-    }
+
     if (root.center.x > coord.center.x)
 	root.center.x = coord.center.x;
     if (root.center.y > coord.center.y)