Mercurial > MadButterfly
changeset 652:1748dce31cdb
Merge the head from wycc
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 31 Jul 2010 13:30:38 +0800 |
parents | aa52883534fc (current diff) 492da72e6537 (diff) |
children | 34710e86b4a2 d58251f1bf0b |
files | |
diffstat | 4 files changed, 60 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/svg.js Sat Jul 31 13:28:48 2010 +0800 +++ b/nodejs/svg.js Sat Jul 31 13:30:38 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,52 @@ _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://") { + ref = ref.substring(7); + } else if (ref.substr(0,5)=="file:") { + ref = ref.substring(5); + } else { + return; + } + 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) {
--- a/nodejs/test.svg Sat Jul 31 13:28:48 2010 +0800 +++ b/nodejs/test.svg Sat Jul 31 13:30:38 2010 +0800 @@ -1,5 +1,6 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) --> + <svg xmlns:ns0="http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" @@ -14,8 +15,8 @@ height="480" id="svg2" sodipodi:version="0.32" - inkscape:version="0.46" - sodipodi:docname="list.svg" + inkscape:version="0.47+devel r9312" + sodipodi:docname="test.svg" version="1.0" inkscape:output_extension="org.inkscape.output.svg.inkscape"> <sodipodi:namedview @@ -34,10 +35,11 @@ inkscape:document-units="px" inkscape:current-layer="layer4" showgrid="false" - inkscape:window-width="1024" - inkscape:window-height="768" + inkscape:window-width="1347" + inkscape:window-height="894" inkscape:window-x="0" - inkscape:window-y="0" /> + inkscape:window-y="25" + inkscape:window-maximized="0" /> <defs id="defs4"> <linearGradient @@ -301,5 +303,12 @@ rx="10" ry="10" /> </g> + <image + y="78.788635" + x="34.986565" + id="image3033" + xlink:href="file:logo.png" + height="37" + width="46" /> </g> </svg>
--- a/src/img_ldr.c Sat Jul 31 13:28:48 2010 +0800 +++ b/src/img_ldr.c Sat Jul 31 13:30:38 2010 +0800 @@ -33,7 +33,10 @@ sz = strlen(sldr->repo); sz += strlen(img_id); fname = (char *)malloc(sz + 2); - strcpy(fname, sldr->repo); + if (img_id[0] != '/') + strcpy(fname, sldr->repo); + else + fname[0] = 0; strcat(fname, img_id); surf = mbe_image_surface_create_from_png(fname);