changeset 646:3a1e80de44ff

Add image support
author wycc
date Thu, 29 Jul 2010 00:12:18 +0800
parents 818e870e1eb5
children 492da72e6537
files nodejs/svg.js
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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) 
 {