comparison tools/svg2code.py @ 64:c668c5c3ceae

M4 macro for C binding.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 13 Aug 2008 02:07:40 +0800
parents f4b792afa74e
children 35c2b7ba140b
comparison
equal deleted inserted replaced
63:f4b792afa74e 64:c668c5c3ceae
4 4
5 svgns='http://www.w3.org/2000/svg' 5 svgns='http://www.w3.org/2000/svg'
6 xlinkns='http://www.w3.org/1999/xlink' 6 xlinkns='http://www.w3.org/1999/xlink'
7 7
8 def translate_stops(parent, codefo, parent_id): 8 def translate_stops(parent, codefo, parent_id):
9 stops = []
9 for node in parent.childNodes: 10 for node in parent.childNodes:
10 if node.localName == 'stop' and node.namespaceURI == svgns: 11 if node.localName == 'stop' and node.namespaceURI == svgns:
11 style = node.getAttribute('style') 12 style = node.getAttribute('style')
12 style_props = [prop.strip() for prop in style.split(';') 13 style_props = [prop.strip() for prop in style.split(';')
13 if prop.strip()] 14 if prop.strip()]
24 else: 25 else:
25 raise ValueError, '\'%s\' is invalid color value.' % (color) 26 raise ValueError, '\'%s\' is invalid color value.' % (color)
26 27
27 opacity = style_map['stop-opacity'] 28 opacity = style_map['stop-opacity']
28 offset = node.getAttribute('offset') 29 offset = node.getAttribute('offset')
29 print >> codefo, '[COLOR_STOP([%s], %f, %f, %f, %f, %f)],' % ( 30 stops.append('[COLOR_STOP([%s], %f, %f, %f, %f, %f)]' % (
30 parent_id, r, g, b, float(opacity), float(offset)) 31 parent_id, r, g, b, float(opacity), float(offset)))
31 pass 32 pass
32 pass 33 pass
34 print >> codefo, '%sdnl' % (', '.join(stops))
33 pass 35 pass
34 36
35 def translate_linearGradient(linear, codefo, doc): 37 def translate_linearGradient(linear, codefo, doc):
36 linear_id = linear.getAttribute('id') 38 linear_id = linear.getAttribute('id')
37 if linear.hasAttribute('x1'): 39 if linear.hasAttribute('x1'):