annotate nodejs/svg.js @ 646:3a1e80de44ff

Add image support
author wycc
date Thu, 29 Jul 2010 00:12:18 +0800
parents e517bbefe0e9
children 492da72e6537
rev   line source
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
1 var libxml = require('libxmljs');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
2 var sys=require('sys');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
3 var mbfly = require("mbfly");
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
4 var mb_rt = new mbfly.mb_rt(":0.0", 720,480);
646
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
5 var ldr = mbfly.img_ldr_new(".");
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
6
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
7 function MB_loadSVG(mb_rt,root,filename) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
8 var doc = libxml.parseXmlFile(filename);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
9 var nodes = doc.root().childNodes();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
10 var coord = mb_rt.coord_new(root);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
11 var k;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
12
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
13 for(k in nodes) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
14 var n = nodes[k].name();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
15 if (n == "defs") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
16 _MB_parseDefs(root,nodes[k]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
17 } else if (n == "g") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
18 _MB_parseGroup(root,'root_coord',nodes[k]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
19 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
20 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
21 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
22
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
23 function getInteger(n,name)
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
24 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
25 if (n == null) return 0;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
26 var a = n.attr(name);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
27 if (a==null) return 0;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
28 return parseInt(a.value());
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
29 }
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
30 function parsePointSize(s)
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
31 {
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
32 var fs=0;
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
33 var i;
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
34
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
35 for(i=0;i<s.length;i++) {
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
36 if (s[i]<'0' || s[i] > '9') break;
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
37 fs = fs*10 + (s[i]-'0');
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
38 }
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
39 return fs;
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
40
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
41 }
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
42
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
43
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
44 function parseColor(c)
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
45 {
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
46 if (c[0] == '#') {
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
47 return parseInt(c.substring(1,3),16)<<16 | parseInt(c.substring(3,5),16)<<8 | parseInt(c.substring(5,7),16);
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
48 }
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
49 }
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
50 function parseTextStyle(style,n)
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
51 {
625
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
52 var attr;
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
53 if (n) {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
54 attr = n.attr('style');
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
55 } else {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
56 attr = null;
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
57 }
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
58 if (attr == null) {
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
59 return;
625
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
60 }
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
61 var f = attr.value().split(';');
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
62
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
63 for(i in f) {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
64 var kv = f[i].split(':');
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
65 if (kv[0] == 'font-size') {
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
66 style.fs = parsePointSize(kv[1]);
625
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
67 } else if (kv[0] == "font-style") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
68 } else if (kv[0] == "font-weight") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
69 } else if (kv[0] == "fill") {
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
70 style.color = parseColor(kv[1]);
625
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
71 } else if (kv[0] == "fill-opacity") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
72 } else if (kv[0] == "stroke") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
73 } else if (kv[0] == "stroke-width") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
74 } else if (kv[0] == "stroke-linecap") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
75 } else if (kv[0] == "stroke-linejoin") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
76 } else if (kv[0] == "stroke-lineopacity") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
77 } else if (kv[0] == "font-family") {
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
78 style.family = kv[1];
625
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
79 } else if (kv[0] == "font-stretch") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
80 } else if (kv[0] == "font-variant") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
81 } else if (kv[0] == "text-anchor") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
82 } else if (kv[0] == "text-align") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
83 } else if (kv[0] == "writing-mode") {
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
84 } else if (kv[0] == "line-height") {
632
e517bbefe0e9 Add the missing 'else'
wycc
parents: 631
diff changeset
85 } else {
625
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
86 sys.puts("Unknown style: "+kv[0]);
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
87 }
9f2080b68f8e Add the text style parser. This can not handle the recursive tspan yet.
wycc
parents: 624
diff changeset
88 }
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
89 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
90
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
91 function _MB_parseTSpan(coord, n,style)
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
92 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
93 var x = getInteger(n,'x');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
94 var y = getInteger(n,'y');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
95 var tcoord = mb_rt.coord_new(coord);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
96 var nodes = n.childNodes();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
97 var k;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
98
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
99 sys.puts(n.text());
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
100 var obj = mb_rt.stext_new(n.text(),x,y);
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
101 parseTextStyle(style,n);
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
102 style.paint = mb_rt.paint_color_new(1,1,1,1);
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
103 style.face=mb_rt.font_face_query(style.family, 2, 100);
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
104 obj.set_style([[20,style.face,style.fs]]);
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
105 style.paint.fill(obj);
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
106 tcoord.add_shape(obj);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
107 for(k in nodes) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
108 var name = nodes[k].name();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
109 if (name == "tspan") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
110 _MB_parseTSpan(tcoord,nodes[k]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
111 } else {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
112 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
113 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
114 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
115
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
116 function _MB_parseText(coord,id, n)
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
117 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
118 var x = getInteger(n,'x');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
119 var y = getInteger(n,'y');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
120 var tcoord = mb_rt.coord_new(coord);
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
121 var style = new Object();
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
122 style.fs = 20;
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
123 style.family = 'courier';
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
124 parseTextStyle(style,n);
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
125 var nodes = n.childNodes();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
126 var k;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
127 for(k in nodes) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
128 var n = nodes[k].name();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
129 if (n == "tspan") {
631
01e960bfc9ff Implement text style parser
wycc
parents: 625
diff changeset
130 _MB_parseTSpan(tcoord,nodes[k],style);
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
131 } else {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
132 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
133 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
134
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
135
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
136 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
137
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
138
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
139 function parseTransform(coord, s)
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
140 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
141 var off = s.indexOf('translate');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
142 if (off != -1) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
143 var ss = s.substring(off+9);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
144 for(i=0;i<ss.length;i++) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
145 if (ss[i] == '(') break;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
146 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
147 ss = ss.substring(i+1);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
148 for(i=0;i<ss.length;i++) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
149 if (ss[i] == ')') {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
150 ss = ss.substring(0,i);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
151 break;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
152 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
153 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
154 var f = ss.split(',');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
155 var x,y;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
156 x = parseInt(f[0]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
157 y = parseInt(f[1]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
158 coord[2] = x;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
159 coord[5] = y;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
160 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
161 off = s.indexOf('matrix');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
162 if (off != -1) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
163 sys.puts("matrix");
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
164 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
165 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
166
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
167 function _MB_parseRect(coord, id, n)
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
168 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
169
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
170 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
171
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
172 function _MB_parseGroup(root, group_id, n)
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
173 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
174 var k;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
175 var nodes = n.childNodes();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
176 var coord = mb_rt.coord_new(root);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
177 // Parse the transform and style here
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
178 var trans = n.attr('transform');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
179 if (trans!=null) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
180 parseTransform(coord, trans.value());
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
181 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
182
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
183 for(k in nodes) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
184 var n = nodes[k].name();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
185 var attr = nodes[k].attr('id');
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
186 var id;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
187 if (attr) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
188 id = attr.value();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
189 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
190 if (n == "g") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
191 _MB_parseGroup(coord, id, nodes[k]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
192 } else if (n == "text") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
193 _MB_parseText(coord, id, nodes[k]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
194 } else if (n == "rect") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
195 _MB_parseRect(coord, id, nodes[k]);
646
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
196 } else if (n == "image") {
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
197 _MB_parseImage(coord, id, nodes[k]);
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
198 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
199 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
200
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
201 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
202
646
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
203 function _MB_parseImage(coord,id, n)
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
204 {
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
205 sys.puts("---> image");
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
206 var ref = n.attr('href').value();
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
207
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
208 if (ref == null) return;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
209 sys.puts(ref);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
210 if (ref.substr(0,7) != "file://") {
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
211 return;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
212 }
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
213 ref = ref.substring(7);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
214 sys.puts("Load image "+ref);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
215 var w;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
216 var h;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
217 var x,y;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
218
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
219 w = n.attr("width");
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
220 if (w == null) return;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
221 w = parseInt(w.value());
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
222 h = n.attr("height");
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
223 if (h == null) return;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
224 h = parseInt(h.value());
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
225 x = n.attr("x");
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
226 if (x == null) return;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
227 x = parseInt(x.value());
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
228 y = n.attr("y");
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
229 if (y == null) return;
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
230 y = parseInt(y.value());
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
231 sys.puts("x="+x+",y="+y+",w="+w+",h="+h);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
232 var img = mb_rt.image_new(x,y,w,h);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
233 var img_data = ldr.load(ref);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
234 sys.puts(img_data);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
235 var paint = mb_rt.paint_image_new(img_data);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
236 paint.fill(img);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
237 coord.add_shape(img);
3a1e80de44ff Add image support
wycc
parents: 632
diff changeset
238 }
624
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
239
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
240 function _MB_parseDefs(root,n)
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
241 {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
242 var k;
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
243 var nodes = n.childNodes();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
244
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
245 for(k in nodes) {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
246 var name = nodes[k].name();
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
247 if (name == "linearGradient") {
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
248 //_MB_parseLinearGradient(root,nodes[k]);
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
249 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
250 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
251 }
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
252
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
253
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
254 MB_loadSVG(mb_rt,mb_rt.root,"test.svg");
d45c928f6523 Add SVG parser sample code.
wycc
parents:
diff changeset
255 mb_rt.redraw_all();