summaryrefslogtreecommitdiff
path: root/tools/genlayout.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/genlayout.py')
-rw-r--r--tools/genlayout.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tools/genlayout.py b/tools/genlayout.py
new file mode 100644
index 0000000..f6003bd
--- /dev/null
+++ b/tools/genlayout.py
@@ -0,0 +1,48 @@
+list = []
+
+def flush():
+ global mode, name, x, y, w, h
+ if mode == 'rect':
+ list.append((name, round(x+w/2), round(y+h/2)))
+ if mode == 'circle':
+ list.append((name, round(x), round(y)))
+ mode = None
+
+def readsvg(filename):
+ global mode, name, x, y, w, h
+ mode = None
+ name = None
+ x = y = w = h = 0
+ for line in open(filename).readlines():
+ line = line.strip()
+ if line == "<rect":
+ flush()
+ mode = 'rect'
+ x = y = w = h = 0
+ name = None
+ elif line == "<ellipse" or line == "<circle":
+ flush()
+ mode = 'circle'
+ x = y = w = h = 0
+ name = None
+ if line.startswith('x="'): x = round(float(line.split('"')[1]))
+ if line.startswith('y="'): y = round(float(line.split('"')[1]))
+ if line.startswith('width="'): w = round(float(line.split('"')[1]))
+ if line.startswith('height="'): h = round(float(line.split('"')[1]))
+ if line.startswith('cx="'): x = round(float(line.split('"')[1]))
+ if line.startswith('cy="'): y = round(float(line.split('"')[1]))
+ if line.startswith('inkscape:label="'): name = line.split('"')[1]
+ flush()
+
+readsvg("tools/boxes.svg")
+readsvg("tools/layout.svg")
+
+def print_list():
+ print("const LAYOUT = {")
+ for (name,x,y) in list:
+ xc = round((x+w/2.0))
+ yc = round((y+h/2.0))
+ print(f'\t"{name}": [{x}, {y}],')
+ print("}")
+
+print_list()