Fix a bug or two. Now working as intended

This commit is contained in:
Dominic Zimmer 2019-11-13 14:58:34 +01:00
parent 3e12fed614
commit c0800a5ead

41
generate_svgs.py Normal file → Executable file
View File

@ -1,3 +1,4 @@
#!/bin/python3
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
import argparse import argparse
import re import re
@ -41,6 +42,11 @@ parsed = vars(parser.parse_args())
disable_tables = [ disable_tables = [
list(range(size)) for size in table_group_sizes list(range(size)) for size in table_group_sizes
] ]
# open XML
tree = ET.parse(parsed["input"])
root = tree.getroot()
if parsed["all"]: if parsed["all"]:
disable_tables = [] disable_tables = []
else: else:
@ -58,26 +64,19 @@ else:
tableid = f"{lower}{thechar}" tableid = f"{lower}{thechar}"
if parsed[tableid]: if parsed[tableid]:
disable_tables[i].remove(j) disable_tables[i].remove(j)
print(disable_tables)
pattern_rect = re.compile("table_(.)(.*)")
pattern_text = re.compile("label_(.)")
# parse XML for the table rects
rects = root.findall(".//{http://www.w3.org/2000/svg}rect")
rects = list(filter(lambda rect: pattern_rect.match(rect.attrib["id"]), rects))
# parse XML for the text containers
texts = root.findall(".//{http://www.w3.org/2000/svg}text")
texts = list(filter(lambda text: pattern_text.match(text.attrib["id"]), texts))
pattern_rect = re.compile("table_(.)(.*)") for text in texts:
pattern_text = re.compile("label_(.)")
tree = ET.parse(parsed["input"])
root = tree.getroot()
# parse XML for the table rects
rects = root.findall(".//{http://www.w3.org/2000/svg}rect")
rects = list(filter(lambda rect: pattern_rect.match(rect.attrib["id"]), rects))
# parse XML for the text containers
texts = root.findall(".//{http://www.w3.org/2000/svg}text")
texts = list(filter(lambda text: pattern_text.match(text.attrib["id"]), texts))
for text in texts:
# parse group of text # parse group of text
match = pattern_text.match(text.attrib["id"]) match = pattern_text.match(text.attrib["id"])
group = ord(match.group(1)) - ord('a') group = ord(match.group(1)) - ord('a')
@ -85,20 +84,16 @@ for text in texts:
# disable text if all of its childs are disabled # disable text if all of its childs are disabled
all_childs_disabled = len(disable_tables[group]) == table_group_sizes[group] # no element removed all_childs_disabled = len(disable_tables[group]) == table_group_sizes[group] # no element removed
if all_childs_disabled: if all_childs_disabled:
print("disable group", group)
span = list(text)[0] span = list(text)[0]
style_span="font-size:3.17499995px;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332;" style_span="font-size:3.17499995px;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332;"
span.attrib["style"] = style_span span.attrib["style"] = style_span
else: # otherwise do nothing, we start with a full canvas
print("dont disable group", group)
# do nothing, we start with a full canvas
for rect in rects: for rect in rects:
match = pattern_rect.match(rect.attrib["id"]) match = pattern_rect.match(rect.attrib["id"])
group, number = ord(match.group(1)) - ord('a'), table_char_to_num[match.group(2)] group, number = ord(match.group(1)) - ord('a'), table_char_to_num[match.group(2)]
print(group, number)
if number in disable_tables[group]: if number in disable_tables[group]:
#other group, color grey #other group, color grey
rect.attrib["style"] = "fill:#808080;stroke-width:0.26458332" rect.attrib["style"] = "fill:#808080;stroke-width:0.26458332"
#groupstring = chr(ord('a') + group_id) #groupstring = chr(ord('a') + group_id)
tree.write(parsed["output"]) tree.write(parsed["output"])