# HG changeset patch # User wycc # Date 1302096921 -28800 # Node ID 6fa411fd9549836f8bbf4196701b044eaa137811 # Parent 5dd46a4f6257d34dffb44b5ab00bccc0acfded8c# Parent ce981aa3fbf29ea4605aeabcdc00cc92d307df51 Commit merged result diff -r 5dd46a4f6257 -r 6fa411fd9549 nodejs/examples/mce/main.svg --- a/nodejs/examples/mce/main.svg Wed Apr 06 08:17:00 2011 +0800 +++ b/nodejs/examples/mce/main.svg Wed Apr 06 21:35:21 2011 +0800 @@ -1,40 +1,22 @@ - - - - + + - - - + + + + image/svg+xml + - - - + @@ -48,127 +30,128 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff -r 5dd46a4f6257 -r 6fa411fd9549 nodejs/examples/mce/mainmenu.js --- a/nodejs/examples/mce/mainmenu.js Wed Apr 06 08:17:00 2011 +0800 +++ b/nodejs/examples/mce/mainmenu.js Wed Apr 06 21:35:21 2011 +0800 @@ -93,7 +93,7 @@ } MainMenu.prototype.onNextPage=function() { - this.app.changeScene(98); + this.app.changeScene(97); } MainMenu.prototype.changePage=function(item) { this.app.epg.getList(item,this.onNextPage); diff -r 5dd46a4f6257 -r 6fa411fd9549 nodejs/mbapp.js --- a/nodejs/mbapp.js Wed Apr 06 08:17:00 2011 +0800 +++ b/nodejs/mbapp.js Wed Apr 06 21:35:21 2011 +0800 @@ -199,10 +199,10 @@ src.hide(); // Duplicate the group var nodes = src.children; - if (src.dup) { - src.dup.remove(); - src.dup = null; - } + //if (src.dup) { + // src.dup.remove(); + // src.dup = null; + //} if (src.dup == null) { var dup = this.mb_rt.coord_new(src.parent); for (i in nodes) { @@ -252,8 +252,8 @@ app.prototype.generateScaleTweenObject=function(coord,src,dest,p,id) { //sys.puts("xxxxxxx"); //sys.puts("dest="+dest); - // sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); - //sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); + sys.puts("src=["+src.sx+","+src.sy+","+src.r+","+src.tx+","+src.ty); + sys.puts("id="+id+" dest=["+dest.sx+","+dest.sy+","+dest.r+","+dest.tx+","+dest.ty); //sys.puts("src.center="+src.center); //sys.puts("src.center.x="+src.center.x+" src.center.y="+src.center.y); if (src == null) return; diff -r 5dd46a4f6257 -r 6fa411fd9549 nodejs/svg.js --- a/nodejs/svg.js Wed Apr 06 08:17:00 2011 +0800 +++ b/nodejs/svg.js Wed Apr 06 21:35:21 2011 +0800 @@ -976,16 +976,14 @@ attr = n.attr('duplicate-src'); if (attr) { var id = attr.value(); - var orign = this.mb_rt.mbnames[id].node; - sys.puts("xxxxxxxxxxxxxx"); - var nw = getInteger(orign,'width'); - var nh = getInteger(orign,'height'); - sys.puts("nw="+nw); - sys.puts("nh="+nh); - sys.puts("w="+w); - sys.puts("h="+h); - tcoord.sx *= w/nw; - tcoord.sy *= h/nh; + var coord = this.mb_rt.mbnames[id]; + if (coord) { + var orign = this.mb_rt.mbnames[id].node; + var nw = getInteger(orign,'width'); + var nh = getInteger(orign,'height'); + tcoord.sx *= w/nw; + tcoord.sy *= h/nh; + } } diff -r 5dd46a4f6257 -r 6fa411fd9549 pyink/mbbbox.py --- a/pyink/mbbbox.py Wed Apr 06 08:17:00 2011 +0800 +++ b/pyink/mbbbox.py Wed Apr 06 21:35:21 2011 +0800 @@ -1,130 +1,176 @@ +## \file +# \brief MadButterfly with bbox. +# +# This module export a document with bounding box information. +# import pybExtension -def _print_subtree(node, lvl, out): - def _print_level(txt, lvl, out): - indent = ' ' * lvl - print >> out, '%s%s' % (indent, txt) - pass - - def _print_node_open(node, lvl, out): - node_name = node.name() - - attrs = [] - for attrname in node.allAttributes(): - attrvalue = node.getAttribute(attrname) - if attrname[0:13] == 'inkscape:bbox': - continue - attr = '%s="%s"' % (attrname, attrvalue) - attrs.append(attr) - pass - - parent_node = node.parent() - if parent_node: - parent_name = parent_node.name() - if parent_name == 'svg:g': - bbox = node.getBBox() - attr = 'inkscape:bbox-x="%f"' % (bbox[0]) - attrs.append(attr) - bbox = node.getBBox() - attr = 'inkscape:bbox-y="%f"' % (bbox[1]) - attrs.append(attr) - bbox = node.getBBox() - attr = 'inkscape:bbox-width="%f"' % (bbox[2]) - attrs.append(attr) - bbox = node.getBBox() - attr = 'inkscape:bbox-height="%f"' % (bbox[3]) - attrs.append(attr) +class mbbbox_ext(pybExtension.PYBindExtImp): + def _translate_attr(self, node, attrname, attrvalue): + if attrname == 'xlink:href' and attrvalue.startswith('file://'): + # translate to relative path + from os.path import relpath, dirname, realpath, abspath + + fn = abspath(attrvalue[7:]) + fn = realpath(fn) + + doc_name = abspath(self._doc_name) + doc_name = realpath(doc_name) + doc_dir = dirname(doc_name) + + relfn = relpath(fn, doc_dir) + + if not relfn.startswith('../'): + attrvalue = relfn pass pass - if attrs: - attrs_str = ' '.join(attrs) - line = '<%s %s>' % (node_name, attrs_str) - else: - line = '<%s>' % (node_name) + return attrname, attrvalue + + def _print_subtree(self, node, lvl, out): + def _print_level(txt, lvl, out): + indent = ' ' * lvl + print >> out, '%s%s' % (indent, txt) + pass + + def _print_node_open(node, lvl, out): + node_name = node.name() + + attrs = [] + if node_name == 'svg:svg': + attrs.append('xmlns:dc="http://purl.org/dc/elements/1.1/"') + attrs.append('xmlns:cc="http://creativecommons.org/ns#"') + attrs.append('xmlns:rdf=' + '"http://www.w3.org/1999/02/22-rdf-syntax-ns#"') + attrs.append('xmlns:svg="http://www.w3.org/2000/svg"') + attrs.append('xmlns="http://www.w3.org/2000/svg"') + attrs.append('xmlns:xlink="http://www.w3.org/1999/xlink"') + attrs.append('xmlns:sodipodi="http://' + 'sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"') + attrs.append('xmlns:inkscape=' + '"http://www.inkscape.org/namespaces/inkscape"') + pass + + for attrname in node.allAttributes(): + attrvalue = node.getAttribute(attrname) + attrname, attrvalue = \ + self._translate_attr(node, attrname, attrvalue) + if attrname[0:13] == 'inkscape:bbox': + continue + attr = '%s="%s"' % (attrname, attrvalue) + attrs.append(attr) + pass + + parent_node = node.parent() + if parent_node: + parent_name = parent_node.name() + if parent_name == 'svg:g': + bbox = node.getBBox() + attr = 'inkscape:bbox-x="%f"' % (bbox[0]) + attrs.append(attr) + bbox = node.getBBox() + attr = 'inkscape:bbox-y="%f"' % (bbox[1]) + attrs.append(attr) + bbox = node.getBBox() + attr = 'inkscape:bbox-width="%f"' % (bbox[2]) + attrs.append(attr) + bbox = node.getBBox() + attr = 'inkscape:bbox-height="%f"' % (bbox[3]) + attrs.append(attr) + pass + pass + + if attrs: + attrs_str = ' '.join(attrs) + line = '<%s %s>' % (node_name, attrs_str) + else: + line = '<%s>' % (node_name) + pass + _print_level(line, lvl, out) pass - _print_level(line, lvl, out) - pass + + def _print_node_close(node, lvl, out): + node_name = node.name() + + line = '' % (node_name) + _print_level(line, lvl, out) + pass + + def _print_node_single(node, lvl, out): + node_name = node.name() + + attrs = [] + for attrname in node.allAttributes(): + if attrname[0:13] == 'inkscape:bbox': + continue + attrvalue = node.getAttribute(attrname) + attrname, attrvalue = \ + self._translate_attr(node, attrname, attrvalue) + attr = '%s="%s"' % (attrname, attrvalue) + attrs.append(attr) + pass - def _print_node_close(node, lvl, out): - node_name = node.name() - - line = '' % (node_name) - _print_level(line, lvl, out) + parent_node = node.parent() + if parent_node: + parent_name = parent_node.name() + if parent_name == 'svg:g': + bbox = node.getBBox() + attr = 'inkscape:bbox-x="%f"' % (bbox[0]) + attrs.append(attr) + bbox = node.getBBox() + attr = 'inkscape:bbox-y="%f"' % (bbox[1]) + attrs.append(attr) + bbox = node.getBBox() + attr = 'inkscape:bbox-width="%f"' % (bbox[2]) + attrs.append(attr) + bbox = node.getBBox() + attr = 'inkscape:bbox-height="%f"' % (bbox[3]) + attrs.append(attr) + pass + pass + + if attrs: + attrs_str = ' '.join(attrs) + line = '<%s %s/>' % (node_name, attrs_str) + else: + line = '<%s/>' % (node_name) + pass + _print_level(line, lvl, out) + pass + + def _print_node_content(node, lvl, out): + line = node.content() + _print_level(line, lvl, out) + pass + + children = node.childList() + if not children: + if node.name() != 'string': + _print_node_single(node, lvl, out) + else: + _print_node_content(node, lvl, out) + pass + return + + _print_node_open(node, lvl, out) + for child in children: + self._print_subtree(child, lvl + 1, out) + pass + _print_node_close(node, lvl, out) pass - def _print_node_single(node, lvl, out): - node_name = node.name() - - attrs = [] - for attrname in node.allAttributes(): - if attrname[0:13] == 'inkscape:bbox': - continue - attrvalue = node.getAttribute(attrname) - attr = '%s="%s"' % (attrname, attrvalue) - attrs.append(attr) - pass - - parent_node = node.parent() - if parent_node: - parent_name = parent_node.name() - if parent_name == 'svg:g': - bbox = node.getBBox() - attr = 'inkscape:bbox-x="%f"' % (bbox[0]) - attrs.append(attr) - bbox = node.getBBox() - attr = 'inkscape:bbox-y="%f"' % (bbox[1]) - attrs.append(attr) - bbox = node.getBBox() - attr = 'inkscape:bbox-width="%f"' % (bbox[2]) - attrs.append(attr) - bbox = node.getBBox() - attr = 'inkscape:bbox-height="%f"' % (bbox[3]) - attrs.append(attr) - pass - pass - - if attrs: - attrs_str = ' '.join(attrs) - line = '<%s %s/>' % (node_name, attrs_str) - else: - line = '<%s/>' % (node_name) - pass - _print_level(line, lvl, out) - pass - - def _print_node_content(node, lvl, out): - line = node.content() - _print_level(line, lvl, out) - pass - - children = node.childList() - if not children: - if node.name() != 'string': - _print_node_single(node, lvl, out) - else: - _print_node_content(node, lvl, out) - pass - return - - _print_node_open(node, lvl, out) - for child in children: - _print_subtree(child, lvl + 1, out) - pass - _print_node_close(node, lvl, out) - pass - -class mbbbox_ext(pybExtension.PYBindExtImp): def save(self, module, doc, filename): + self._doc_name = filename out = file(filename, 'w+') + print >>out, '' root = doc.rdoc.root() - _print_subtree(root, 0, out) - + self._print_subtree(root, 0, out) + out.close() pass pass - + extension = (mbbbox_ext(), 'net.scribboo.mbbbox',