1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/python
# ./svg_levels.py >svg_levels.lua
import os, glob
from lxml import etree
from lxml.cssselect import CSSSelector
print '-- autogenerated by svg_levels.py\n\nsvg_objects = {'
ns = {'svg': 'http://www.w3.org/2000/svg',
'ink': 'http://www.inkscape.org/namespaces/inkscape'}
for svg in glob.glob('data/*.svg'):
t = etree.parse(svg)
basefile = os.path.basename(svg).split('.')[0]
print '%s = {' % basefile
sel = CSSSelector('svg|rect[ink|label="displace"]', ns)
for e in sel(t):
x, y = float(e.get('x')), float(e.get('y'))
w, h = float(e.get('width')), float(e.get('height'))
print """
Displacer:new{
x = %f, y = %f,
width = %f, height = %f
}
""" % (x,y,w,h)
print '},'
print '}'
|