Mercurial > MadButterfly
comparison tools/svg2code.py @ 81:13fdf205047b
Hide shapes and groups
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 21 Aug 2008 13:52:23 +0800 |
parents | e548221c04eb |
children | ea758bb3bbe2 |
comparison
equal
deleted
inserted
replaced
80:e548221c04eb | 81:13fdf205047b |
---|---|
97 def trans_color(code): | 97 def trans_color(code): |
98 return int(code[1:3], 16) / 255.0, \ | 98 return int(code[1:3], 16) / 255.0, \ |
99 int(code[3:5], 16) / 255.0, \ | 99 int(code[3:5], 16) / 255.0, \ |
100 int(code[5:7], 16) / 255.0 | 100 int(code[5:7], 16) / 255.0 |
101 | 101 |
102 def translate_style(node, coord_id, codefo, doc): | 102 def translate_style(node, coord_id, codefo, doc, prefix): |
103 node_id = node.getAttribute('id') | 103 node_id = node.getAttribute('id') |
104 style_str = node.getAttribute('style') | 104 style_str = node.getAttribute('style') |
105 prop_strs = [s.strip() for s in style_str.split(';')] | 105 prop_strs = [s.strip() for s in style_str.split(';')] |
106 prop_kvs = [s.split(':') for s in prop_strs if s] | 106 prop_kvs = [s.split(':') for s in prop_strs if s] |
107 prop_kvs = [(k.strip(), v.strip()) for k, v in prop_kvs] | 107 prop_kvs = [(k.strip(), v.strip()) for k, v in prop_kvs] |
151 if prop_map.has_key('stroke-width'): | 151 if prop_map.has_key('stroke-width'): |
152 stroke_width = float(prop_map['stroke-width']) | 152 stroke_width = float(prop_map['stroke-width']) |
153 print >> codefo, 'STROKE_WIDTH([%s], %f)dnl' % ( | 153 print >> codefo, 'STROKE_WIDTH([%s], %f)dnl' % ( |
154 node_id, stroke_width) | 154 node_id, stroke_width) |
155 pass | 155 pass |
156 | |
157 if prop_map.has_key('display'): | |
158 display = prop_map['display'].strip().lower() | |
159 if display == 'none': | |
160 print >> codefo, '%sHIDE([%s])dnl' % (prefix, node_id) | |
161 pass | |
162 pass | |
156 pass | 163 pass |
157 | 164 |
158 def translate_path(path, coord_id, codefo, doc): | 165 def translate_path(path, coord_id, codefo, doc): |
159 path_id = path.getAttribute('id') | 166 path_id = path.getAttribute('id') |
160 d = path.getAttribute('d') | 167 d = path.getAttribute('d') |
161 print >> codefo, 'dnl' | 168 print >> codefo, 'dnl' |
162 print >> codefo, 'ADD_PATH([%s], [%s], [%s])dnl' % (path_id, d, coord_id) | 169 print >> codefo, 'ADD_PATH([%s], [%s], [%s])dnl' % (path_id, d, coord_id) |
163 translate_style(path, coord_id, codefo, doc) | 170 translate_style(path, coord_id, codefo, doc, 'PATH_') |
164 pass | 171 pass |
165 | 172 |
166 def translate_rect(rect, coord_id, codefo, doc): | 173 def translate_rect(rect, coord_id, codefo, doc): |
167 rect_id = rect.getAttribute('id') | 174 rect_id = rect.getAttribute('id') |
168 x = float(rect.getAttribute('x')) | 175 x = float(rect.getAttribute('x')) |
178 width = float(rect.getAttribute('width')) | 185 width = float(rect.getAttribute('width')) |
179 height = float(rect.getAttribute('height')) | 186 height = float(rect.getAttribute('height')) |
180 print >> codefo, 'dnl' | 187 print >> codefo, 'dnl' |
181 print >> codefo, 'ADD_RECT([%s], %f, %f, %f, %f, %f, %f, [%s])dnl' % ( | 188 print >> codefo, 'ADD_RECT([%s], %f, %f, %f, %f, %f, %f, [%s])dnl' % ( |
182 rect_id, x, y, width, height, rx, ry, coord_id) | 189 rect_id, x, y, width, height, rx, ry, coord_id) |
183 translate_style(rect, coord_id, codefo, doc) | 190 translate_style(rect, coord_id, codefo, doc, 'RECT_') |
184 pass | 191 pass |
185 | 192 |
186 def translate_group(group, parent_id, codefo, doc): | 193 def translate_group(group, parent_id, codefo, doc): |
187 group_id = group.getAttribute('id') | 194 group_id = group.getAttribute('id') |
188 print >> codefo, 'dnl' | 195 print >> codefo, 'dnl' |
189 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) | 196 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) |
197 translate_style(group, group_id, codefo, doc, 'GROUP_') | |
190 for node in group.childNodes: | 198 for node in group.childNodes: |
191 if node.namespaceURI != svgns: | 199 if node.namespaceURI != svgns: |
192 continue | 200 continue |
193 if node.localName == 'g': | 201 if node.localName == 'g': |
194 translate_group(node, group_id, codefo, doc) | 202 translate_group(node, group_id, codefo, doc) |