# HG changeset patch # User wycc # Date 1280333538 -28800 # Node ID 3a1e80de44fffe31cd12a246c5813b01a0506040 # Parent 818e870e1eb5dfb4b1d8124c30244f1950d421a3 Add image support diff -r 818e870e1eb5 -r 3a1e80de44ff nodejs/svg.js --- a/nodejs/svg.js Thu Jul 29 00:11:31 2010 +0800 +++ b/nodejs/svg.js Thu Jul 29 00:12:18 2010 +0800 @@ -2,6 +2,7 @@ var sys=require('sys'); var mbfly = require("mbfly"); var mb_rt = new mbfly.mb_rt(":0.0", 720,480); +var ldr = mbfly.img_ldr_new("."); function MB_loadSVG(mb_rt,root,filename) { var doc = libxml.parseXmlFile(filename); @@ -192,11 +193,49 @@ _MB_parseText(coord, id, nodes[k]); } else if (n == "rect") { _MB_parseRect(coord, id, nodes[k]); + } else if (n == "image") { + _MB_parseImage(coord, id, nodes[k]); } } } +function _MB_parseImage(coord,id, n) +{ + sys.puts("---> image"); + var ref = n.attr('href').value(); + + if (ref == null) return; + sys.puts(ref); + if (ref.substr(0,7) != "file://") { + return; + } + ref = ref.substring(7); + sys.puts("Load image "+ref); + var w; + var h; + var x,y; + + w = n.attr("width"); + if (w == null) return; + w = parseInt(w.value()); + h = n.attr("height"); + if (h == null) return; + h = parseInt(h.value()); + x = n.attr("x"); + if (x == null) return; + x = parseInt(x.value()); + y = n.attr("y"); + if (y == null) return; + y = parseInt(y.value()); + sys.puts("x="+x+",y="+y+",w="+w+",h="+h); + var img = mb_rt.image_new(x,y,w,h); + var img_data = ldr.load(ref); + sys.puts(img_data); + var paint = mb_rt.paint_image_new(img_data); + paint.fill(img); + coord.add_shape(img); +} function _MB_parseDefs(root,n) {