Mercurial > MadButterfly
comparison nodejs/svg.js @ 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 | cd5fb45bc247 |
children | 6fa4a53c3fca |
comparison
equal
deleted
inserted
replaced
1394:4a786de1d62f | 1395:a768d74e5f49 |
---|---|
37 if (filename) | 37 if (filename) |
38 this.load(mb_rt,root,filename); | 38 this.load(mb_rt,root,filename); |
39 } | 39 } |
40 | 40 |
41 loadSVG.prototype.load=function(mb_rt, root, filename) { | 41 loadSVG.prototype.load=function(mb_rt, root, filename) { |
42 sys.puts(filename); | |
43 sys.puts(libxml); | |
44 var doc = libxml.parseXmlFile(filename); | 42 var doc = libxml.parseXmlFile(filename); |
45 var _root = doc.root(); | 43 var _root = doc.root(); |
46 var nodes = _root.childNodes(); | 44 var nodes = _root.childNodes(); |
47 var coord = mb_rt.coord_new(root); | 45 var coord = mb_rt.coord_new(root); |
48 var k; | 46 var k; |
635 var vstr; | 633 var vstr; |
636 var bbox, center; | 634 var bbox, center; |
637 var orig; | 635 var orig; |
638 | 636 |
639 a = node.attr("bbox-x"); | 637 a = node.attr("bbox-x"); |
640 if(!a) | 638 if(!a) { |
639 tgt.center = new Object(); | |
640 tgt.center.x=0; | |
641 tgt.center.y=0; | |
641 return 0; | 642 return 0; |
643 } | |
642 | 644 |
643 /* bbox.orig is initial values of bbox. The bbox is recomputed | 645 /* bbox.orig is initial values of bbox. The bbox is recomputed |
644 * according bbox.orig and current matrix. See bbox.update(). | 646 * according bbox.orig and current matrix. See bbox.update(). |
645 */ | 647 */ |
646 tgt.bbox = bbox = new Object(); | 648 tgt.bbox = bbox = new Object(); |
789 var pcoord = this.mb_rt.coord_new(coord); | 791 var pcoord = this.mb_rt.coord_new(coord); |
790 pcoord.node = n; | 792 pcoord.node = n; |
791 n.coord = pcoord; | 793 n.coord = pcoord; |
792 this._check_duplicate_src(n,pcoord); | 794 this._check_duplicate_src(n,pcoord); |
793 | 795 |
794 guessPathBoundingBox(pcoord,d); | 796 //guessPathBoundingBox(pcoord,d); |
797 var trans = n.attr('transform'); | |
798 if (trans) | |
799 parseTransform(pcoord,trans.value()); | |
800 else { | |
801 pcoord.sx = 1; | |
802 pcoord.sy = 1; | |
803 pcoord.r = 0; | |
804 pcoord.tx = 0; | |
805 pcoord.ty = 0; | |
806 } | |
807 | |
795 pcoord.add_shape(path); | 808 pcoord.add_shape(path); |
796 this._set_paint(n, path); | 809 this._set_paint(n, path); |
797 this._set_bbox(n, path); | 810 this._set_bbox(n, pcoord); |
798 | 811 |
799 make_mbnames(this.mb_rt, n, pcoord); | 812 make_mbnames(this.mb_rt, n, pcoord); |
800 }; | 813 }; |
801 | 814 |
802 loadSVG.prototype.parseText=function(accu,coord,id, n) | 815 loadSVG.prototype.parseText=function(accu,coord,id, n) |
1028 var m = [1,0,0,1,0,0] | 1041 var m = [1,0,0,1,0,0] |
1029 this.parseGroup(m,root,id, n) | 1042 this.parseGroup(m,root,id, n) |
1030 } | 1043 } |
1031 | 1044 |
1032 loadSVG.prototype._check_duplicate_src=function(n,coord) { | 1045 loadSVG.prototype._check_duplicate_src=function(n,coord) { |
1046 if (n.name()=="use") { | |
1047 n.coord.isuse = true | |
1048 } else { | |
1049 n.coord.isuse = false; | |
1050 } | |
1033 var attr = n.attr('duplicate-src'); | 1051 var attr = n.attr('duplicate-src'); |
1034 if (attr == null) return; | 1052 if (attr == null) return; |
1035 sys.puts("---->"+attr.value()); | |
1036 var id = attr.value(); | 1053 var id = attr.value(); |
1037 try { | 1054 try { |
1038 this.mb_rt.mbnames[id].target = coord; | 1055 this.mb_rt.mbnames[id].target = coord; |
1039 } catch(e) { | 1056 } catch(e) { |
1040 sys.puts("id "+id+" is not defined"); | 1057 sys.puts("id "+id+" is not defined"); |
1126 this._check_duplicate_src(n,coord); | 1143 this._check_duplicate_src(n,coord); |
1127 | 1144 |
1128 coord.center= new Object(); | 1145 coord.center= new Object(); |
1129 coord.center.x = 10000; | 1146 coord.center.x = 10000; |
1130 coord.center.y = 10000; | 1147 coord.center.y = 10000; |
1148 sys.puts("use id="+use_id+" "+trans); | |
1149 sys.puts(n); | |
1131 if (trans!=null) { | 1150 if (trans!=null) { |
1132 parseTransform(coord, trans.value()); | 1151 parseTransform(coord, trans.value()); |
1133 } else { | 1152 } else { |
1134 coord.sx = 1; | 1153 coord.sx = 1; |
1135 coord.sy = 1; | 1154 coord.sy = 1; |
1136 coord.r = 0; | 1155 coord.r = 0; |
1137 coord.tx = 0; | 1156 coord.tx = 0; |
1138 coord.ty = 0; | 1157 coord.ty = 0; |
1139 | 1158 |
1140 } | 1159 } |
1160 var attr = n.attr('duplicate-src'); | |
1161 if (attr) { | |
1162 var src = this.mb_rt.mbnames[attr.value()]; | |
1163 multiply(coord, coord,src); | |
1164 } | |
1141 multiply(accu,accu_matrix); | 1165 multiply(accu,accu_matrix); |
1142 multiply(accu,coord); | 1166 multiply(accu,coord); |
1143 | 1167 |
1144 style = {}; | 1168 style = {}; |
1145 parseGroupStyle(style, n); | 1169 parseGroupStyle(style, n); |
1146 if(style.opacity) { | 1170 if(style.opacity) { |
1147 sys.puts("opacity=" + style.opacity); | 1171 sys.puts("opacity=" + style.opacity); |
1148 coord.opacity=style.opacity; | 1172 coord.opacity=style.opacity; |
1149 } | 1173 } |
1150 // For a use tag, we will duplicate the group inside it. | 1174 |
1151 attr = n.attr('duplicate-src'); | |
1152 if (attr != null) { | |
1153 c = this.mb_rt.mbnames[attr.value()]; | |
1154 if (c == null) { | |
1155 sys.puts("Can not find object "+attr.value()); | |
1156 return; | |
1157 } | |
1158 coord.clone_from_subtree(c); | |
1159 } | |
1160 if (root.center.x > coord.center.x) | 1175 if (root.center.x > coord.center.x) |
1161 root.center.x = coord.center.x; | 1176 root.center.x = coord.center.x; |
1162 if (root.center.y > coord.center.y) | 1177 if (root.center.y > coord.center.y) |
1163 root.center.y = coord.center.y; | 1178 root.center.y = coord.center.y; |
1164 | 1179 |