Mercurial > MadButterfly
comparison nodejs/svg.js @ 646:3a1e80de44ff
Add image support
author | wycc |
---|---|
date | Thu, 29 Jul 2010 00:12:18 +0800 |
parents | e517bbefe0e9 |
children | 492da72e6537 |
comparison
equal
deleted
inserted
replaced
645:818e870e1eb5 | 646:3a1e80de44ff |
---|---|
1 var libxml = require('libxmljs'); | 1 var libxml = require('libxmljs'); |
2 var sys=require('sys'); | 2 var sys=require('sys'); |
3 var mbfly = require("mbfly"); | 3 var mbfly = require("mbfly"); |
4 var mb_rt = new mbfly.mb_rt(":0.0", 720,480); | 4 var mb_rt = new mbfly.mb_rt(":0.0", 720,480); |
5 var ldr = mbfly.img_ldr_new("."); | |
5 | 6 |
6 function MB_loadSVG(mb_rt,root,filename) { | 7 function MB_loadSVG(mb_rt,root,filename) { |
7 var doc = libxml.parseXmlFile(filename); | 8 var doc = libxml.parseXmlFile(filename); |
8 var nodes = doc.root().childNodes(); | 9 var nodes = doc.root().childNodes(); |
9 var coord = mb_rt.coord_new(root); | 10 var coord = mb_rt.coord_new(root); |
190 _MB_parseGroup(coord, id, nodes[k]); | 191 _MB_parseGroup(coord, id, nodes[k]); |
191 } else if (n == "text") { | 192 } else if (n == "text") { |
192 _MB_parseText(coord, id, nodes[k]); | 193 _MB_parseText(coord, id, nodes[k]); |
193 } else if (n == "rect") { | 194 } else if (n == "rect") { |
194 _MB_parseRect(coord, id, nodes[k]); | 195 _MB_parseRect(coord, id, nodes[k]); |
195 } | 196 } else if (n == "image") { |
196 } | 197 _MB_parseImage(coord, id, nodes[k]); |
197 | 198 } |
198 } | 199 } |
199 | 200 |
201 } | |
202 | |
203 function _MB_parseImage(coord,id, n) | |
204 { | |
205 sys.puts("---> image"); | |
206 var ref = n.attr('href').value(); | |
207 | |
208 if (ref == null) return; | |
209 sys.puts(ref); | |
210 if (ref.substr(0,7) != "file://") { | |
211 return; | |
212 } | |
213 ref = ref.substring(7); | |
214 sys.puts("Load image "+ref); | |
215 var w; | |
216 var h; | |
217 var x,y; | |
218 | |
219 w = n.attr("width"); | |
220 if (w == null) return; | |
221 w = parseInt(w.value()); | |
222 h = n.attr("height"); | |
223 if (h == null) return; | |
224 h = parseInt(h.value()); | |
225 x = n.attr("x"); | |
226 if (x == null) return; | |
227 x = parseInt(x.value()); | |
228 y = n.attr("y"); | |
229 if (y == null) return; | |
230 y = parseInt(y.value()); | |
231 sys.puts("x="+x+",y="+y+",w="+w+",h="+h); | |
232 var img = mb_rt.image_new(x,y,w,h); | |
233 var img_data = ldr.load(ref); | |
234 sys.puts(img_data); | |
235 var paint = mb_rt.paint_image_new(img_data); | |
236 paint.fill(img); | |
237 coord.add_shape(img); | |
238 } | |
200 | 239 |
201 function _MB_parseDefs(root,n) | 240 function _MB_parseDefs(root,n) |
202 { | 241 { |
203 var k; | 242 var k; |
204 var nodes = n.childNodes(); | 243 var nodes = n.childNodes(); |