comparison tools/svg2code.py @ 84:42698de1f653

Support translate() function for transform attribute of 'g' tag.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 22 Aug 2008 12:52:48 +0800
parents ea758bb3bbe2
children 9b4a02bcaeb1
comparison
equal deleted inserted replaced
83:ea758bb3bbe2 84:42698de1f653
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 from xml.dom.minidom import parse 2 from xml.dom.minidom import parse
3 import sys 3 import sys
4 import re
4 5
5 svgns='http://www.w3.org/2000/svg' 6 svgns='http://www.w3.org/2000/svg'
6 xlinkns='http://www.w3.org/1999/xlink' 7 xlinkns='http://www.w3.org/1999/xlink'
7 8
8 def translate_stops(parent, codefo, parent_id): 9 def translate_stops(parent, codefo, parent_id):
247 x, y, coord_id.encode('utf8')) 248 x, y, coord_id.encode('utf8'))
248 translate_style(text, coord_id, codefo, doc, 'TEXT_') 249 translate_style(text, coord_id, codefo, doc, 'TEXT_')
249 pass 250 pass
250 pass 251 pass
251 252
253 reo_translate = re.compile('translate\\(([0-9]+),([0-9]+)\\)')
254 def translate_transform(coord_id, transform, codefo):
255 transform = transform.strip()
256 mo = reo_translate.match(transform)
257 if mo:
258 x = float(mo.group(1))
259 y = float(mo.group(2))
260 print >> codefo, 'COORD_TRANSLATE([%s], %f, %f)dnl' % (
261 coord_id, x, y)
262 pass
263 pass
264
252 def translate_group(group, parent_id, codefo, doc): 265 def translate_group(group, parent_id, codefo, doc):
253 group_id = group.getAttribute('id') 266 group_id = group.getAttribute('id')
254 print >> codefo, 'dnl' 267 print >> codefo, 'dnl'
255 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id) 268 print >> codefo, 'ADD_COORD([%s], [%s])dnl' % (group_id, parent_id)
269
270 if group.hasAttribute('transform'):
271 transform = group.getAttribute('transform')
272 translate_transform(group_id, transform, codefo)
273 pass
274
256 translate_style(group, group_id, codefo, doc, 'GROUP_') 275 translate_style(group, group_id, codefo, doc, 'GROUP_')
257 for node in group.childNodes: 276 for node in group.childNodes:
258 if node.namespaceURI != svgns: 277 if node.namespaceURI != svgns:
259 continue 278 continue
260 if node.localName == 'g': 279 if node.localName == 'g':