Mercurial > MadButterfly
annotate tools/svg2code.py @ 241:104d83378582
Add scene support in svg2code.py.
- Add mb_sprite_t::goto_scene()
- svg2code.py recoganize "scenes" tag in metadata of SVG file.
- tranform scenes into SCENE() macro.
- define SCENE macro in mb_c_*.m4
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 31 Dec 2008 02:08:40 +0800 |
parents | 3fadd2f2742e |
children | 50d253d0fcba a90fd749af82 |
rev | line source |
---|---|
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 from xml.dom.minidom import parse |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 import sys |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
4 import re |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 svgns='http://www.w3.org/2000/svg' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 xlinkns='http://www.w3.org/1999/xlink' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
9 re_rgb = re.compile('rgb\\( *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?) *, *([0-9]+(\\.[0-9]+)?) *\\)') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 def translate_stops(parent, codefo, parent_id): |
64 | 11 stops = [] |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 for node in parent.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 if node.localName == 'stop' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 style = node.getAttribute('style') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 style_props = [prop.strip() for prop in style.split(';') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 if prop.strip()] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 style_kvpairs = [prop.split(':') for prop in style_props] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 style_kvpairs = [(prop[0].strip(), prop[1].strip()) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 for prop in style_kvpairs] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 style_map = dict(style_kvpairs) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 color = style_map['stop-color'].strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 if len(color) == 7 and color[0] == '#': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 r = float(int(color[1:3], 16)) / 255.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 g = float(int(color[3:5], 16)) / 255.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 b = float(int(color[5:7], 16)) / 255.0 |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
27 elif color.lower() == 'white': |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
28 r, g, b = 1, 1, 1 |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
29 elif color.lower() == 'black': |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
30 r, g, b = 0, 0, 0 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 else: |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
32 mo = re_rgb.match(color) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
33 if mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
34 r = float(mo.group(1)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
35 g = float(mo.group(3)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
36 b = float(mo.group(5)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
37 else: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
38 raise ValueError, '\'%s\' is invalid color value.' % (color) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
39 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
41 try: |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
42 opacity = style_map['stop-opacity'] |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
43 except: |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
44 opacity = 1 |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
45 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 offset = node.getAttribute('offset') |
64 | 47 stops.append('[COLOR_STOP([%s], %f, %f, %f, %f, %f)]' % ( |
48 parent_id, r, g, b, float(opacity), float(offset))) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 pass |
64 | 51 print >> codefo, '%sdnl' % (', '.join(stops)) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 def translate_linearGradient(linear, codefo, doc): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
55 linear_id = _get_id(linear) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 if linear.hasAttribute('x1'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 x1 = float(linear.getAttribute('x1')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 y1 = float(linear.getAttribute('y1')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 x2 = float(linear.getAttribute('x2')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 y2 = float(linear.getAttribute('y2')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
61 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
62 x1 = y1 = x2 = y2 = 0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
63 pass |
63 | 64 print >> codefo, 'ADD_LINEAR_PAINT([%s], %f, %f, %f, %f, [' % ( |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
65 linear_id, x1, y1, x2, y2) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
66 translate_stops(linear, codefo, linear_id) |
63 | 67 print >> codefo, '])dnl' |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
68 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
69 href = linear.getAttributeNS(xlinkns, 'href').strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
70 if href and href[0] == '#': |
78 | 71 print >> codefo, 'REF_STOPS_LINEAR([%s], [%s])dnl' % ( |
72 linear_id, href[1:]) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
73 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
74 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
75 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
76 def translate_radialGradient(radial, codefo, doc): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
77 radial_id = _get_id(radial) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
78 try: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
79 cx = float(radial.getAttribute('cx')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
80 cy = float(radial.getAttribute('cy')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
81 except: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
82 cx = cy = 0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
83 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
84 try: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 r = float(radial.getAttribute('r')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
86 except: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
87 r = 0.5 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
88 pass |
63 | 89 print >> codefo, 'ADD_RADIAL_PAINT([%s], %f, %f, %f, [' % ( |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
90 radial_id, cx, cy, r) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
91 translate_stops(radial, codefo, radial_id) |
63 | 92 print >>codefo, '])dnl' |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
93 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
94 href = radial.getAttributeNS(xlinkns, 'href').strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
95 if href[0] == '#': |
78 | 96 print >> codefo, 'REF_STOPS_RADIAL([%s], [%s])dnl' % ( |
97 radial_id, href[1:]) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
98 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
99 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
100 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
101 def translate_defs(defs, codefo, doc): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
102 for node in defs.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
103 if node.namespaceURI != svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
104 continue |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
105 if node.localName == 'linearGradient': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
106 translate_linearGradient(node, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
107 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
108 elif node.localName == 'radialGradient': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
109 translate_radialGradient(node, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
110 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
111 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
112 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
113 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
114 def trans_color(code): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
115 return int(code[1:3], 16) / 255.0, \ |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
116 int(code[3:5], 16) / 255.0, \ |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
117 int(code[5:7], 16) / 255.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
118 |
83 | 119 def get_style_map(style_str): |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
120 prop_strs = [s.strip() for s in style_str.split(';')] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
121 prop_kvs = [s.split(':') for s in prop_strs if s] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
122 prop_kvs = [(k.strip(), v.strip()) for k, v in prop_kvs] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
123 prop_map = dict(prop_kvs) |
83 | 124 return prop_map |
125 | |
126 def translate_style(node, coord_id, codefo, doc, prefix): | |
127 node_id = node.getAttribute('id') | |
128 style_str = node.getAttribute('style') | |
129 prop_map = get_style_map(style_str) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
130 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
131 try: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
132 opacity = float(node.getAttribute('opacity')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
133 except: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
134 opacity = 1.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
135 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
136 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
137 if prop_map.has_key('fill'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
138 fill = prop_map['fill'].strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
139 if fill.startswith('#') and len(fill) == 7: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
140 r, g, b = trans_color(fill) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
141 print >> codefo, 'FILL_SHAPE([%s], %f, %f, %f, %f)dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
142 node_id, r, g, b, opacity) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
143 elif fill.startswith('url(') and fill.endswith(')'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
144 paint_id = fill[5:-1] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
145 print >> codefo, 'FILL_SHAPE_WITH_PAINT([%s], [%s])dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
146 node_id, paint_id) |
86
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
147 elif fill.lower() == 'none': |
7d0580f89468
Fix bug of dealing matrix().
Thinker K.F. Li <thinker@branda.to>
parents:
85
diff
changeset
|
148 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
149 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
150 raise ValueError, '\'%s\' is an invalid value for fill.' % (fill) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
151 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
152 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
153 try: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
154 stroke_opacity = float(node.getAttribute('stroke-opacity')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
155 except: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
156 stroke_opacity = 1.0 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
157 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
158 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
159 if prop_map.has_key('stroke'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
160 stroke = prop_map['stroke'].strip() |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
161 if stroke.startswith('#') and len(stroke) == 7: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
162 r, g, b = trans_color(stroke) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
163 print >> codefo, 'STROKE_SHAPE([%s], %f, %f, %f, %f)dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
164 node_id, r, g, b, stroke_opacity) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
165 elif stroke.startswith('url(') and stroke.endswith(')'): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
166 paint_id = stroke[5:-1] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
167 print >> codefo, 'STROKE_SHAPE_WITH_PAINT([%s], [%s])dnl' % ( |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
168 node_id, paint_id) |
83 | 169 elif stroke.lower() == 'none': |
170 pass | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
171 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
172 raise ValueError, '\'%s\' is an invalid value for stroke.' \ |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
173 % (stroke) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
174 pass |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
175 |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
176 if prop_map.has_key('stroke-width'): |
83 | 177 if prop_map['stroke-width'].endswith('px'): |
178 stroke_width = float(prop_map['stroke-width'][:-2]) | |
179 else: | |
180 stroke_width = float(prop_map['stroke-width']) | |
181 pass | |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
182 print >> codefo, 'STROKE_WIDTH([%s], %f)dnl' % ( |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
183 node_id, stroke_width) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
184 pass |
81 | 185 |
186 if prop_map.has_key('display'): | |
187 display = prop_map['display'].strip().lower() | |
188 if display == 'none': | |
189 print >> codefo, '%sHIDE([%s])dnl' % (prefix, node_id) | |
190 pass | |
191 pass | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
192 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
193 |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
194 def translate_shape_transform(shape, coord_id, codefo): |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
195 shape_id = shape.getAttribute('id') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
196 |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
197 if shape.hasAttribute('transform'): |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
198 shape_coord_id = shape_id + '_coord' |
101 | 199 ## \page shape_coord Coordinate Transformation for Shapes. |
200 # | |
201 # svg2code.py add a coord_t for a shape if transform attribute | |
202 # of it's tag is setted. The name of coord_t object is | |
203 # <shape_id> + "_coord". | |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
204 print >> codefo, 'dnl' |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
205 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % ( |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
206 shape_coord_id, coord_id) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
207 transform = shape.getAttribute('transform') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
208 translate_transform(shape_coord_id, transform, codefo, 'SHAPE_') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
209 coord_id = shape_coord_id |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
210 pass |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
211 return coord_id |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
212 |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
213 # M x y : Move to (x,y) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
214 # Z : close path |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
215 # L x y : lineto (x,y) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
216 # H x : horizontal line to x |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
217 # V y : Vertical line to y |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
218 # C x1 y1 x2 y2 x y : Draw a segment of bezier curve |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
219 # S x2 y2 x t : Draw a segment of bezier curve from the last |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
220 # control point |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
221 # Q x1 y1 x y : Draw a segment of quadratic curve |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
222 # T x y : Draw a segment of quadratic curve from the last |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
223 # control pint |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
224 # A x y r f s x y : Draw an arc |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
225 # translate the path data into two arrays. The first is an integer whose |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
226 # upper 8 bits are the command type The second array hold all arguments. |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
227 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
228 command_length={'M': 2, 'm':2, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
229 'Z': 0, 'z':0, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
230 'L': 2, 'l':2, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
231 'H': 1, 'h':1, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
232 'V': 1, 'v':1, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
233 'C': 6, 'c':6, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
234 'S': 4, 's':4, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
235 'Q': 4, 'q':4, |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
236 'T': 2, 't':2} |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
237 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
238 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
239 def translate_path_data(data,codefo): |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
240 temp = data.split() |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
241 fields=[] |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
242 for f in temp: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
243 for s in f.split(','): |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
244 if s != '': |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
245 fields.append(s) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
246 cmd = '' |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
247 commands='' |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
248 args=[] |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
249 fix_args=[] |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
250 for f in fields: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
251 if cmd == 'A' or cmd == 'a': |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
252 try: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
253 d = int(f) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
254 fix_args.append(d) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
255 if (narg % 7) == 0: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
256 commands = commands + cmd |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
257 narg = narg + 1 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
258 except: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
259 pass |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
260 else: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
261 try: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
262 d = float(f) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
263 args.append(d) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
264 if (narg % command_length[cmd]) == 0: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
265 commands = commands + cmd |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
266 narg = narg + 1 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
267 continue |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
268 except: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
269 pass |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
270 cmd = f |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
271 narg=0 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
272 pass |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
273 return [commands,args,fix_args] |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
274 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
275 _id_sn = 0 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
276 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
277 def _get_id(obj): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
278 global _id_sn |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
279 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
280 if obj.hasAttribute('id'): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
281 oid = obj.getAttribute('id') |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
282 else: |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
283 oid = '_MB_RAND_%s_' % (_id_sn) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
284 obj.setAttribute('id', oid) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
285 _id_sn = _id_sn + 1 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
286 pass |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
287 return oid |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
288 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
289 ## |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
290 # Decorator that check if objects have attribute 'mbname'. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
291 # |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
292 def check_mbname(func): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
293 def deco(obj, coord_id, codefo, doc): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
294 if obj.hasAttribute('mbname'): |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
295 ## \note mbname declare that this node should be in the |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
296 # symbol table. |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
297 mbname = obj.getAttribute('mbname') |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
298 print >> codefo, 'ADD_SYMBOL([%s])dnl' % (mbname) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
299 pass |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
300 func(obj, coord_id, codefo, doc) |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
301 pass |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
302 return deco |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
303 |
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
304 @check_mbname |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
305 def translate_path(path, coord_id, codefo, doc): |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
306 coord_id = translate_shape_transform(path, coord_id, codefo) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
307 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
308 path_id = path.getAttribute('id') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
309 d = path.getAttribute('d') |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
310 (commands,args,fix_args) = translate_path_data(d,codefo) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
311 print >> codefo, 'dnl' |
197
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
312 #print >> codefo, 'ADD_PATH([%s], [%s], [%s])dnl' % (path_id, d, coord_id) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
313 sarg='' |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
314 for c in args: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
315 sarg = sarg + "%f," % c |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
316 s_fix_arg='' |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
317 for c in fix_args: |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
318 s_fix_arg = s_fix_arg + ("%d," % c) |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
319 |
bcad1ccdf45c
Translate the path string into binary array to save the parsing in the runtime. It can reduce the size as well.
wycc@wycc-desktop
parents:
101
diff
changeset
|
320 print >> codefo, 'ADD_PATH([%s], [%s],[%s],[%s],[%d],[%s],[%d])dnl' % (path_id, coord_id,commands,sarg,len(args),s_fix_arg,len(fix_args)) |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
321 |
81 | 322 translate_style(path, coord_id, codefo, doc, 'PATH_') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
323 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
324 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
325 @check_mbname |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
326 def translate_rect(rect, coord_id, codefo, doc): |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
327 coord_id = translate_shape_transform(rect, coord_id, codefo) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
328 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
329 rect_id = _get_id(rect) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
330 x = float(rect.getAttribute('x')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
331 y = float(rect.getAttribute('y')) |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
332 rx = 0.0 |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
333 if rect.hasAttribute('rx'): |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
334 rx = float(rect.getAttribute('rx')) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
335 pass |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
336 ry = 0.0 |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
337 if rect.hasAttribute('ry'): |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
338 ry = float(rect.getAttribute('ry')) |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
339 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
340 width = float(rect.getAttribute('width')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
341 height = float(rect.getAttribute('height')) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
342 print >> codefo, 'dnl' |
80
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
343 print >> codefo, 'ADD_RECT([%s], %f, %f, %f, %f, %f, %f, [%s])dnl' % ( |
e548221c04eb
svg2code.py support stroke
Thinker K.F. Li <thinker@branda.to>
parents:
78
diff
changeset
|
344 rect_id, x, y, width, height, rx, ry, coord_id) |
81 | 345 translate_style(rect, coord_id, codefo, doc, 'RECT_') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
346 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
347 |
83 | 348 def translate_font_style(text, codefo): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
349 text_id = _get_id(text) |
83 | 350 style_str = text.getAttribute('style') |
351 style_map = get_style_map(style_str) | |
352 | |
353 font_sz = 10.0 | |
354 if style_map.has_key('font-size'): | |
355 if style_map['font-size'].endswith('px'): | |
356 font_sz = float(style_map['font-size'][:-2]) | |
357 print >> codefo, 'define([MB_FONT_SZ], %f)dnl' % (font_sz) | |
358 pass | |
359 pass | |
360 | |
361 font_style = 'normal' | |
362 if style_map.has_key('font-style'): | |
363 font_style = style_map['font-style'].lower() | |
364 pass | |
365 | |
366 font_family = 'Roman' | |
367 if style_map.has_key('font-family'): | |
368 font_family = style_map['font-family'].lower() | |
369 pass | |
370 pass | |
371 | |
372 def translate_text(text, coord_id, codefo, doc): | |
373 translate_font_style(text, codefo) | |
374 | |
375 txt_strs = [] | |
376 for node in text.childNodes: | |
377 if node.localName == None: | |
378 txt_strs.append(node.data) | |
379 elif node.localName == 'tspan': | |
380 node.setAttribute('style', text.getAttribute('style')) | |
381 translate_text(node, coord_id, codefo, doc) | |
382 pass | |
383 pass | |
384 if txt_strs: | |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
385 text_id = _get_id(text) |
83 | 386 x = float(text.getAttribute('x')) |
387 y = float(text.getAttribute('y')) | |
388 print >> codefo, 'dnl' | |
389 print >> codefo, \ | |
390 'ADD_TEXT([%s], [%s], %f, %f, MB_FONT_SZ, [%s])dnl' % ( | |
391 text_id.encode('utf8'), u''.join(txt_strs).encode('utf8'), | |
392 x, y, coord_id.encode('utf8')) | |
393 translate_style(text, coord_id, codefo, doc, 'TEXT_') | |
394 pass | |
395 pass | |
396 | |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
397 reo_func = re.compile('([a-zA-Z]+)\\([^\\)]*\\)') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
398 reo_translate = re.compile('translate\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
399 reo_matrix = re.compile('matrix\\(([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?),([-+]?[0-9]+(\\.[0-9]+)?)\\)') |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
400 def translate_transform(coord_id, transform, codefo, prefix): |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
401 transform = transform.strip() |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
402 mo = reo_func.match(transform) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
403 if not mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
404 return |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
405 name = mo.group(1) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
406 if name == 'translate': |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
407 mo = reo_translate.match(transform) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
408 if mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
409 x = float(mo.group(1)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
410 y = float(mo.group(3)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
411 print >> codefo, '%sTRANSLATE([%s], %f, %f)dnl' % ( |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
412 prefix, coord_id, x, y) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
413 pass |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
414 elif name == 'matrix': |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
415 mo = reo_matrix.match(transform) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
416 if mo: |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
417 r10, r11, r12 = \ |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
418 float(mo.group(1)), float(mo.group(3)), float(mo.group(5)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
419 r20, r21, r22 = \ |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
420 float(mo.group(7)), float(mo.group(9)), float(mo.group(11)) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
421 print >> codefo, \ |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
422 '%sMATRIX([%s], %f, %f, %f, %f, %f, %f)dnl' % ( |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
423 prefix, coord_id, r10, r11, r12, r20, r21, r22) |
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
424 pass |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
425 pass |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
426 pass |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
427 |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
428 @check_mbname |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
429 def translate_group(group, parent_id, codefo, doc): |
210
3fadd2f2742e
M4 macros to generate code for dynamic loading.
Thinker K.F. Li <thinker@branda.to>
parents:
197
diff
changeset
|
430 group_id = _get_id(group) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
431 print >> codefo, 'dnl' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
432 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
433 |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
434 if group.hasAttribute('transform'): |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
435 transform = group.getAttribute('transform') |
85
9b4a02bcaeb1
matrix() function in transform attribute of group and shapes
Thinker K.F. Li <thinker@branda.to>
parents:
84
diff
changeset
|
436 translate_transform(group_id, transform, codefo, 'COORD_') |
84
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
437 pass |
42698de1f653
Support translate() function for transform attribute of 'g' tag.
Thinker K.F. Li <thinker@branda.to>
parents:
83
diff
changeset
|
438 |
81 | 439 translate_style(group, group_id, codefo, doc, 'GROUP_') |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
440 for node in group.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
441 if node.namespaceURI != svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
442 continue |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
443 if node.localName == 'g': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
444 translate_group(node, group_id, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
445 elif node.localName == 'path': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
446 translate_path(node, group_id, codefo, doc) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
447 elif node.localName == 'rect': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
448 translate_rect(node, group_id, codefo, doc) |
83 | 449 elif node.localName == 'text': |
450 translate_text(node, group_id, codefo, doc) | |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
451 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
452 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
453 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
454 |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
455 ## \brief Translate "scenes" tag in "metadata" tag. |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
456 # |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
457 def translate_scenes(scenes_node, codefo, doc): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
458 scenes = [] |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
459 for scene in scenes_node.childNodes: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
460 if scene.localName != 'scene' or \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
461 not scene.hasAttribute('ref') or \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
462 not scene.hasAttribute('start'): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
463 continue |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
464 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
465 start_str = scene.getAttribute('start') |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
466 start = end = int(start_str) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
467 if scene.hasAttribute('end'): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
468 end_str = scene.getAttribute('end') |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
469 end = int(end_str) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
470 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
471 ref = scene.getAttribute('ref') |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
472 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
473 while len(scenes) <= end: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
474 scenes.append([]) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
475 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
476 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
477 for i in range(start, end + 1): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
478 scenes[i].append(ref) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
479 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
480 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
481 |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
482 for scene_idx, groups_in_scene in enumerate(scenes): |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
483 if groups_in_scene: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
484 groups_str = '[' + '],['.join(groups_in_scene) + ']' |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
485 else: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
486 groups_str = '' |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
487 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
488 print >> codefo, \ |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
489 'SCENE(%d, [%s])dnl' % (scene_idx, groups_str) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
490 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
491 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
492 |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
493 def svg_2_code(dom, codefo): |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
494 for node in dom.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
495 if node.localName == 'svg' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
496 break; |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
497 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
498 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
499 raise ValueErr, 'no any svg tag node.' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
500 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
501 svg = node |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
502 for node in svg.childNodes: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
503 if node.localName == 'defs' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
504 translate_defs(node, codefo, dom) |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
505 elif node.localName == 'metadata' and node.namespaceURI == svgns: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
506 for meta_node in node.childNodes: |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
507 if meta_node.localName == 'scenes': |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
508 translate_scenes(meta_node, codefo, dom) |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
509 pass |
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
510 pass |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
511 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
512 elif node.localName == 'g' and node.namespaceURI == svgns: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
513 translate_group(node, 'root_coord', codefo, dom) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
514 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
515 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
516 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
517 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
518 if __name__ == '__main__': |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
519 from os import path |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
520 if len(sys.argv) == 3: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
521 svgfn = sys.argv[1] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
522 codefn = sys.argv[2] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
523 elif len(sys.argv) == 2: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
524 svgfn = sys.argv[1] |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
525 codefn = 'out.mb' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
526 else: |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
527 print >> sys.stderr, '%s <SVG file> [<output>]' % (sys.argv[0]) |
241
104d83378582
Add scene support in svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
210
diff
changeset
|
528 sys.exit(1) |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
529 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
530 |
65
35c2b7ba140b
Use file name of generated M4 script as name of header
Thinker K.F. Li <thinker@branda.to>
parents:
64
diff
changeset
|
531 struct_name = path.basename(codefn).split('.')[0] |
62
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
532 |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
533 dom = parse(svgfn) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
534 codefo = file(codefn, 'w+') |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
535 print >> codefo, 'MADBUTTERFLY([%s],[dnl' % (struct_name) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
536 svg_2_code(dom, codefo) |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
537 print >> codefo, '])dnl' |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
538 pass |
7d976d925431
Generate C header files for SVG files.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
539 |