Mercurial > MadButterfly
annotate pyink/mbbbox.py @ 1527:d42951ebfc6f
Update "cur_timeline" attribute for renaming timeline
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 31 Aug 2011 17:16:44 +0800 |
parents | ce981aa3fbf2 |
children |
rev | line source |
---|---|
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
1 ## \file |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
2 # \brief MadButterfly with bbox. |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
3 # |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
4 # This module export a document with bounding box information. |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
5 # |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
6 import pybExtension |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
7 |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
8 class mbbbox_ext(pybExtension.PYBindExtImp): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
9 def _translate_attr(self, node, attrname, attrvalue): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
10 if attrname == 'xlink:href' and attrvalue.startswith('file://'): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
11 # translate to relative path |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
12 from os.path import relpath, dirname, realpath, abspath |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
13 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
14 fn = abspath(attrvalue[7:]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
15 fn = realpath(fn) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
16 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
17 doc_name = abspath(self._doc_name) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
18 doc_name = realpath(doc_name) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
19 doc_dir = dirname(doc_name) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
20 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
21 relfn = relpath(fn, doc_dir) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
22 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
23 if not relfn.startswith('../'): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
24 attrvalue = relfn |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
25 pass |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
26 pass |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
27 |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
28 return attrname, attrvalue |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
29 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
30 def _print_subtree(self, node, lvl, out): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
31 def _print_level(txt, lvl, out): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
32 indent = ' ' * lvl |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
33 print >> out, '%s%s' % (indent, txt) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
34 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
35 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
36 def _print_node_open(node, lvl, out): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
37 node_name = node.name() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
38 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
39 attrs = [] |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
40 if node_name == 'svg:svg': |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
41 attrs.append('xmlns:dc="http://purl.org/dc/elements/1.1/"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
42 attrs.append('xmlns:cc="http://creativecommons.org/ns#"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
43 attrs.append('xmlns:rdf=' |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
44 '"http://www.w3.org/1999/02/22-rdf-syntax-ns#"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
45 attrs.append('xmlns:svg="http://www.w3.org/2000/svg"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
46 attrs.append('xmlns="http://www.w3.org/2000/svg"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
47 attrs.append('xmlns:xlink="http://www.w3.org/1999/xlink"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
48 attrs.append('xmlns:sodipodi="http://' |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
49 'sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
50 attrs.append('xmlns:inkscape=' |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
51 '"http://www.inkscape.org/namespaces/inkscape"') |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
52 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
53 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
54 for attrname in node.allAttributes(): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
55 attrvalue = node.getAttribute(attrname) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
56 attrname, attrvalue = \ |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
57 self._translate_attr(node, attrname, attrvalue) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
58 if attrname[0:13] == 'inkscape:bbox': |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
59 continue |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
60 attr = '%s="%s"' % (attrname, attrvalue) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
61 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
62 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
63 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
64 parent_node = node.parent() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
65 if parent_node: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
66 parent_name = parent_node.name() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
67 if parent_name == 'svg:g': |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
68 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
69 attr = 'inkscape:bbox-x="%f"' % (bbox[0]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
70 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
71 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
72 attr = 'inkscape:bbox-y="%f"' % (bbox[1]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
73 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
74 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
75 attr = 'inkscape:bbox-width="%f"' % (bbox[2]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
76 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
77 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
78 attr = 'inkscape:bbox-height="%f"' % (bbox[3]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
79 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
80 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
81 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
82 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
83 if attrs: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
84 attrs_str = ' '.join(attrs) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
85 line = '<%s %s>' % (node_name, attrs_str) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
86 else: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
87 line = '<%s>' % (node_name) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
88 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
89 _print_level(line, lvl, out) |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
90 pass |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
91 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
92 def _print_node_close(node, lvl, out): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
93 node_name = node.name() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
94 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
95 line = '</%s>' % (node_name) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
96 _print_level(line, lvl, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
97 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
98 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
99 def _print_node_single(node, lvl, out): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
100 node_name = node.name() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
101 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
102 attrs = [] |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
103 for attrname in node.allAttributes(): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
104 if attrname[0:13] == 'inkscape:bbox': |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
105 continue |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
106 attrvalue = node.getAttribute(attrname) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
107 attrname, attrvalue = \ |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
108 self._translate_attr(node, attrname, attrvalue) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
109 attr = '%s="%s"' % (attrname, attrvalue) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
110 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
111 pass |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
112 |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
113 parent_node = node.parent() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
114 if parent_node: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
115 parent_name = parent_node.name() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
116 if parent_name == 'svg:g': |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
117 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
118 attr = 'inkscape:bbox-x="%f"' % (bbox[0]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
119 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
120 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
121 attr = 'inkscape:bbox-y="%f"' % (bbox[1]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
122 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
123 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
124 attr = 'inkscape:bbox-width="%f"' % (bbox[2]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
125 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
126 bbox = node.getBBox() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
127 attr = 'inkscape:bbox-height="%f"' % (bbox[3]) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
128 attrs.append(attr) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
129 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
130 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
131 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
132 if attrs: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
133 attrs_str = ' '.join(attrs) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
134 line = '<%s %s/>' % (node_name, attrs_str) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
135 else: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
136 line = '<%s/>' % (node_name) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
137 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
138 _print_level(line, lvl, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
139 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
140 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
141 def _print_node_content(node, lvl, out): |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
142 line = node.content() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
143 _print_level(line, lvl, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
144 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
145 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
146 children = node.childList() |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
147 if not children: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
148 if node.name() != 'string': |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
149 _print_node_single(node, lvl, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
150 else: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
151 _print_node_content(node, lvl, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
152 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
153 return |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
154 |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
155 _print_node_open(node, lvl, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
156 for child in children: |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
157 self._print_subtree(child, lvl + 1, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
158 pass |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
159 _print_node_close(node, lvl, out) |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
160 pass |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
161 |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
162 def save(self, module, doc, filename): |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
163 self._doc_name = filename |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
164 out = file(filename, 'w+') |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
165 |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
166 print >>out, '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
167 root = doc.rdoc.root() |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
168 self._print_subtree(root, 0, out) |
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
169 |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
170 out.close() |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
171 pass |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
172 pass |
1404
ce981aa3fbf2
Translate pathes for xlink:href attriutes to relative pathes.
Thinker K.F. Li <thinker@codemud.net>
parents:
1394
diff
changeset
|
173 |
1393
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
174 |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
175 extension = (mbbbox_ext(), |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
176 'net.scribboo.mbbbox', |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
177 'SVG with BBox exporter', |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
178 'output', |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
179 {'extension': '.svg', |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
180 'mimetype': 'image/svg+xml', |
2d56ed5b0995
Add exporter for export svg with bbox information.
Thinker K.F. Li <thinker@codemud.net>
parents:
diff
changeset
|
181 '_filetypename': 'SVG+BBox (*.svg)'}) |