25 lines
814 B
Python
25 lines
814 B
Python
"""Parse column rectangles from template.svg."""
|
|
import re
|
|
|
|
|
|
def parse_column_rects(svg_path):
|
|
with open(svg_path) as f:
|
|
content = f.read()
|
|
blocks = re.findall(r"<rect[^>]+>", content)
|
|
cols = []
|
|
for block in blocks:
|
|
x = float(re.search(r'x="([^"]+)"', block).group(1))
|
|
y = float(re.search(r'y="([^"]+)"', block).group(1))
|
|
w = float(re.search(r'width="([^"]+)"', block).group(1))
|
|
h = float(re.search(r'height="([^"]+)"', block).group(1))
|
|
cols.append({"x": x, "y": y, "w": w, "h": h})
|
|
return cols
|
|
|
|
|
|
def column_bounds(cols):
|
|
return [(c["x"], c["x"] + c["w"]) for c in cols]
|
|
|
|
|
|
def row_bounds(num_rows, table_y, table_height):
|
|
step = table_height / num_rows
|
|
return [(table_y + i * step, table_y + (i + 1) * step) for i in range(num_rows)]
|