Mercurial > MadButterfly
comparison nodejs/svg.js @ 1435:b12c513212af
A prelimanary support for the SVG 1.2 flowRoot style text support. This is useless unless the region is rectangle.
sort the scenes by layer and start attribute.
author | wycc |
---|---|
date | Mon, 11 Apr 2011 12:54:39 +0800 |
parents | 13e126941bdd |
children | 167873cd35c5 |
comparison
equal
deleted
inserted
replaced
1434:4be04f29fa70 | 1435:b12c513212af |
---|---|
76 this.parseMetadata(coord,nodes[k]); | 76 this.parseMetadata(coord,nodes[k]); |
77 } else if (n == "g") { | 77 } else if (n == "g") { |
78 this.parseGroup(accu,coord,'root_coord',nodes[k]); | 78 this.parseGroup(accu,coord,'root_coord',nodes[k]); |
79 } | 79 } |
80 } | 80 } |
81 } | 81 |
82 | 82 this.sortScene(); |
83 | 83 } |
84 | |
85 | |
86 | |
87 loadSVG.prototype.sortScene=function() | |
88 { | |
89 for(i=0;i<this.scenes.length;i++) { | |
90 sys.puts(this._groupMap[this.scenes[i].ref]); | |
91 sys.puts(this._groupMap[this.scenes[i].ref].layer); | |
92 this.scenes[i].layer = this._groupMap[this.scenes[i].ref].layer; | |
93 } | |
94 this.scenes.sort(function(a,b) { | |
95 if (a.layer > b.layer) return 1; | |
96 if (a.layer < b.layer) return -1; | |
97 if (a.start > b.start) return 1; | |
98 if (a.start < b.start) return -1; | |
99 return 0; | |
100 }); | |
101 sys.puts("scenes"); | |
102 for(i=0;i<this.scenes.length;i++) { | |
103 var s = this.scenes[i]; | |
104 sys.puts(s.layer+": start="+s.start+" end="+s.end+" ref="+s.ref); | |
105 } | |
106 | |
107 } | |
84 | 108 |
85 loadSVG.prototype.leaveSVG=function() | 109 loadSVG.prototype.leaveSVG=function() |
86 { | 110 { |
87 var p = this.pgstack.pop(); | 111 var p = this.pgstack.pop(); |
88 p.hide(); | 112 p.hide(); |
103 mb_rt.mbnames[name] = obj; | 127 mb_rt.mbnames[name] = obj; |
104 } | 128 } |
105 mbname = n.attr("label"); | 129 mbname = n.attr("label"); |
106 if(mbname&&(mbname.value()!="")) { | 130 if(mbname&&(mbname.value()!="")) { |
107 name = mbname.value(); | 131 name = mbname.value(); |
132 sys.puts("defone object "+ name); | |
108 mb_rt.mbnames[name] = obj; | 133 mb_rt.mbnames[name] = obj; |
109 } | 134 } |
110 try { | 135 try { |
111 var gname = n.attr('id').value(); | 136 var gname = n.attr('id').value(); |
112 sys.puts("defone object "+ gname); | 137 sys.puts("defone object "+ gname); |
211 } | 236 } |
212 } | 237 } |
213 } | 238 } |
214 function tspan_set_text(text) | 239 function tspan_set_text(text) |
215 { | 240 { |
241 sys.puts("kkkkk "+text); | |
216 this.text.set_text(text); | 242 this.text.set_text(text); |
217 } | 243 } |
218 | 244 |
219 function _parse_font_size(fn_sz_str) { | 245 function _parse_font_size(fn_sz_str) { |
220 var pos; | 246 var pos; |
238 var weight = 80; | 264 var weight = 80; |
239 var slant = 0; | 265 var slant = 0; |
240 var sz = 10; | 266 var sz = 10; |
241 var face; | 267 var face; |
242 var k; | 268 var k; |
243 var obj = this.mb_rt.stext_new(n.text(),x,y); | 269 if (x == 0) x = coord.text_x; |
244 | 270 if (y == 0) y = coord.text_y; |
271 var obj = this.mb_rt.stext_new(n.text().trim(),x,y); | |
272 sys.puts("get text "+n.text().trim() +"at "+x+","+y); | |
273 | |
274 tcoord.node = n; | |
275 n.coord = tcoord; | |
276 this._check_duplicate_src(n,tcoord); | |
245 style = parse_style(n); | 277 style = parse_style(n); |
246 for(k in pstyle) { | 278 for(k in pstyle) { |
247 if(k in style) | 279 if(k in style) |
248 continue; | 280 continue; |
249 style[k] = pstyle[k]; | 281 style[k] = pstyle[k]; |
635 var bbox, center; | 667 var bbox, center; |
636 var orig; | 668 var orig; |
637 | 669 |
638 a = node.attr("bbox-x"); | 670 a = node.attr("bbox-x"); |
639 if(!a) { | 671 if(!a) { |
672 sys.puts("No bbox: "+node); | |
640 tgt.center = new Object(); | 673 tgt.center = new Object(); |
641 tgt.center.x=0; | 674 tgt.center.x=0; |
642 tgt.center.y=0; | 675 tgt.center.y=0; |
676 tgt.center.rel = new Object(); | |
677 tgt.center.rel.x=0; | |
678 tgt.center.rel.y=0; | |
679 tgt.bbox = new Object(); | |
680 tgt.center.__proto__ = _center_proto; | |
681 tgt.center.owner = tgt; | |
643 return 0; | 682 return 0; |
644 } | 683 } |
645 | 684 |
646 /* bbox.orig is initial values of bbox. The bbox is recomputed | 685 /* bbox.orig is initial values of bbox. The bbox is recomputed |
647 * according bbox.orig and current matrix. See bbox.update(). | 686 * according bbox.orig and current matrix. See bbox.update(). |
811 this._set_bbox(n, pcoord); | 850 this._set_bbox(n, pcoord); |
812 | 851 |
813 make_mbnames(this.mb_rt, n, pcoord); | 852 make_mbnames(this.mb_rt, n, pcoord); |
814 }; | 853 }; |
815 | 854 |
855 loadSVG.prototype.parseFlowRegion=function(coord, n,style) | |
856 { | |
857 var nodes = n.childNodes(); | |
858 | |
859 var k; | |
860 | |
861 for(k in nodes) { | |
862 var c= nodes[k].name(); | |
863 if (c == "rect") { | |
864 // We support rectangle only for now. The x,y,w,h are extrcated and use by the flowPara latter. | |
865 coord.text_x = getInteger(nodes[k],'x'); | |
866 coord.text_y = getInteger(nodes[k],'y'); | |
867 coord.text_w = getInteger(nodes[k],'width'); | |
868 coord.text_h = getInteger(nodes[k],'height'); | |
869 } | |
870 } | |
871 } | |
872 loadSVG.prototype.parseFlowRoot=function(accu,coord, id, n) { | |
873 var nodes = n.childNodes(); | |
874 var tcoord = this.mb_rt.coord_new(coord); | |
875 var trans = n.attr('transform'); | |
876 | |
877 | |
878 | |
879 tcoord.node = n; | |
880 n.coord = tcoord; | |
881 this._check_duplicate_src(n,tcoord); | |
882 | |
883 if (trans) | |
884 parseTransform(tcoord,trans.value()); | |
885 else { | |
886 tcoord.sx = 1; | |
887 tcoord.sy = 1; | |
888 tcoord.r = 0; | |
889 tcoord.tx = 0; | |
890 tcoord.ty = 0; | |
891 } | |
892 style = parse_style(n); | |
893 var nodes = n.childNodes(); | |
894 var k; | |
895 for(k in nodes) { | |
896 var c= nodes[k].name(); | |
897 if (c == "flowRegion") { | |
898 this.parseFlowRegion(tcoord,nodes[k],style); | |
899 } else if (c == "flowPara") { | |
900 this.parseTSpan(tcoord,nodes[k],style); | |
901 } else if (c == "flowDiv") { | |
902 } | |
903 } | |
904 var nx = coord[0]*tcoord.text_x+coord[1]*tcoord.text_y+coord[2]; | |
905 if (coord.center.x > nx) | |
906 coord.center.x = nx; | |
907 var ny = coord[3]*tcoord.text_x+coord[4]*tcoord.text_y+coord[5]; | |
908 if (coord.center.y > ny) | |
909 coord.center.y = ny; | |
910 this._set_bbox(n, tcoord); | |
911 | |
912 make_mbnames(this.mb_rt, n, tcoord); | |
913 } | |
914 | |
816 loadSVG.prototype.parseText=function(accu,coord,id, n) | 915 loadSVG.prototype.parseText=function(accu,coord,id, n) |
817 { | 916 { |
818 var nodes = n.childNodes(); | 917 var nodes = n.childNodes(); |
819 if (nodes == "") return; | 918 if (nodes == "") return; |
820 var x = getInteger(n,'x'); | 919 var x = getInteger(n,'x'); |
824 | 923 |
825 tcoord.node = n; | 924 tcoord.node = n; |
826 n.coord = tcoord; | 925 n.coord = tcoord; |
827 this._check_duplicate_src(n,tcoord); | 926 this._check_duplicate_src(n,tcoord); |
828 | 927 |
928 tcoord.sx = 1; | |
929 tcoord.sy = 1; | |
930 tcoord.r = 0; | |
931 tcoord.tx = 0; | |
932 tcoord.ty = 0; | |
829 if (n.attr('x')) { | 933 if (n.attr('x')) { |
830 var nx = coord[0]*x+coord[1]*y+coord[2]; | 934 var nx = coord[0]*x+coord[1]*y+coord[2]; |
831 if (coord.center.x > nx) | 935 if (coord.center.x > nx) |
832 coord.center.x = nx; | 936 coord.center.x = nx; |
833 } | 937 } |
834 if (n.attr('y')) { | 938 if (n.attr('y')) { |
835 var ny = coord[3]*x+coord[4]*y+coord[5]; | 939 var ny = coord[3]*x+coord[4]*y+coord[5]; |
836 if (coord.center.y > ny) | 940 if (coord.center.y > ny) |
837 coord.center.y = ny; | 941 coord.center.y = ny; |
838 } | 942 } |
943 | |
839 style = parse_style(n); | 944 style = parse_style(n); |
840 var nodes = n.childNodes(); | 945 var nodes = n.childNodes(); |
841 var k; | 946 var k; |
842 for(k in nodes) { | 947 for(k in nodes) { |
843 var c= nodes[k].name(); | 948 var c= nodes[k].name(); |
1074 if (n.name()=="use") { | 1179 if (n.name()=="use") { |
1075 n.coord.isuse = true | 1180 n.coord.isuse = true |
1076 } else { | 1181 } else { |
1077 n.coord.isuse = false; | 1182 n.coord.isuse = false; |
1078 } | 1183 } |
1079 var attr = n.attr('duplicate-src'); | 1184 |
1185 // A workaround, should be removed. | |
1186 var attr = n.attr('saved_id'); | |
1187 if (attr) return; | |
1188 | |
1189 attr = n.attr('duplicate-src'); | |
1080 if (attr == null) { | 1190 if (attr == null) { |
1081 sys.puts("no duplicated" + n); | 1191 sys.puts("no duplicated" + n); |
1082 return; | 1192 return; |
1083 } | 1193 } |
1084 var id = attr.value(); | 1194 var id = attr.value(); |
1086 if (this.mb_rt.mbnames[id].target) { | 1196 if (this.mb_rt.mbnames[id].target) { |
1087 sys.puts("duplicated"); | 1197 sys.puts("duplicated"); |
1088 } | 1198 } |
1089 this.mb_rt.mbnames[id].target = coord; | 1199 this.mb_rt.mbnames[id].target = coord; |
1090 coord.refid = this.mb_rt.mbnames[id].id; | 1200 coord.refid = this.mb_rt.mbnames[id].id; |
1201 sys.puts("set the refid of "+id+" to be "+coord.refid); | |
1091 } catch(e) { | 1202 } catch(e) { |
1092 sys.puts("id "+id+" is not defined"); | 1203 sys.puts("id "+id+" is not defined"); |
1093 } | 1204 } |
1094 } | 1205 } |
1095 | 1206 |
1104 var accu=[1,0,0,0,1,0]; | 1215 var accu=[1,0,0,0,1,0]; |
1105 var style; | 1216 var style; |
1106 | 1217 |
1107 n.coord = coord; | 1218 n.coord = coord; |
1108 coord.node = n; | 1219 coord.node = n; |
1220 n.layer = root.id; | |
1109 this._check_duplicate_src(n,coord); | 1221 this._check_duplicate_src(n,coord); |
1110 | 1222 |
1111 coord.center= new Object(); | 1223 coord.center= new Object(); |
1112 coord.center.x = 10000; | 1224 coord.center.x = 10000; |
1113 coord.center.y = 10000; | 1225 coord.center.y = 10000; |
1140 this.parseGroup(accu,coord, id, nodes[k]); | 1252 this.parseGroup(accu,coord, id, nodes[k]); |
1141 } else if (c == "path") { | 1253 } else if (c == "path") { |
1142 this.parsePath(accu,coord, id, nodes[k]); | 1254 this.parsePath(accu,coord, id, nodes[k]); |
1143 } else if (c == "text") { | 1255 } else if (c == "text") { |
1144 this.parseText(accu,coord, id, nodes[k]); | 1256 this.parseText(accu,coord, id, nodes[k]); |
1257 } else if (c == "flowRoot") { | |
1258 this.parseFlowRoot(accu, coord, id, nodes[k]); | |
1145 } else if (c == "rect") { | 1259 } else if (c == "rect") { |
1146 this.parseRect(accu_matrix,coord, id, nodes[k]); | 1260 this.parseRect(accu_matrix,coord, id, nodes[k]); |
1147 } else if (c == "image") { | 1261 } else if (c == "image") { |
1148 this.parseImage(accu_matrix,coord, id, nodes[k]); | 1262 this.parseImage(accu_matrix,coord, id, nodes[k]); |
1149 } else if (c == "use") { | 1263 } else if (c == "use") { |