Fix a bug or two. Now working as intended
This commit is contained in:
parent
3e12fed614
commit
c0800a5ead
69
generate_svgs.py
Normal file → Executable file
69
generate_svgs.py
Normal file → Executable 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,47 +64,36 @@ 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_(.)")
|
# parse group of text
|
||||||
|
match = pattern_text.match(text.attrib["id"])
|
||||||
|
group = ord(match.group(1)) - ord('a')
|
||||||
|
|
||||||
tree = ET.parse(parsed["input"])
|
# disable text if all of its childs are disabled
|
||||||
root = tree.getroot()
|
all_childs_disabled = len(disable_tables[group]) == table_group_sizes[group] # no element removed
|
||||||
|
if all_childs_disabled:
|
||||||
|
span = list(text)[0]
|
||||||
|
style_span="font-size:3.17499995px;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332;"
|
||||||
|
span.attrib["style"] = style_span
|
||||||
|
# otherwise do nothing, we start with a full canvas
|
||||||
|
|
||||||
# parse XML for the table rects
|
for rect in rects:
|
||||||
rects = root.findall(".//{http://www.w3.org/2000/svg}rect")
|
match = pattern_rect.match(rect.attrib["id"])
|
||||||
rects = list(filter(lambda rect: pattern_rect.match(rect.attrib["id"]), rects))
|
group, number = ord(match.group(1)) - ord('a'), table_char_to_num[match.group(2)]
|
||||||
|
if number in disable_tables[group]:
|
||||||
# parse XML for the text containers
|
#other group, color grey
|
||||||
texts = root.findall(".//{http://www.w3.org/2000/svg}text")
|
rect.attrib["style"] = "fill:#808080;stroke-width:0.26458332"
|
||||||
texts = list(filter(lambda text: pattern_text.match(text.attrib["id"]), texts))
|
#groupstring = chr(ord('a') + group_id)
|
||||||
|
|
||||||
for text in texts:
|
|
||||||
# parse group of text
|
|
||||||
match = pattern_text.match(text.attrib["id"])
|
|
||||||
group = ord(match.group(1)) - ord('a')
|
|
||||||
|
|
||||||
# disable text if all of its childs are disabled
|
|
||||||
all_childs_disabled = len(disable_tables[group]) == table_group_sizes[group] # no element removed
|
|
||||||
if all_childs_disabled:
|
|
||||||
print("disable group", group)
|
|
||||||
span = list(text)[0]
|
|
||||||
style_span="font-size:3.17499995px;fill:#ffffff;fill-opacity:1;stroke-width:0.26458332;"
|
|
||||||
span.attrib["style"] = style_span
|
|
||||||
else:
|
|
||||||
print("dont disable group", group)
|
|
||||||
# do nothing, we start with a full canvas
|
|
||||||
|
|
||||||
for rect in rects:
|
|
||||||
match = pattern_rect.match(rect.attrib["id"])
|
|
||||||
group, number = ord(match.group(1)) - ord('a'), table_char_to_num[match.group(2)]
|
|
||||||
print(group, number)
|
|
||||||
if number in disable_tables[group]:
|
|
||||||
#other group, color grey
|
|
||||||
rect.attrib["style"] = "fill:#808080;stroke-width:0.26458332"
|
|
||||||
#groupstring = chr(ord('a') + group_id)
|
|
||||||
tree.write(parsed["output"])
|
tree.write(parsed["output"])
|
||||||
|
Loading…
Reference in New Issue
Block a user