-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_svg.py
125 lines (118 loc) · 3.71 KB
/
build_svg.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import re
riscv_markers = """
<marker
style="overflow:visible"
id="000000_ArchsimMarker_Triangle"
refX="0"
refY="0"
orient="auto-start-reverse"
inkscape:stockid="TriangleStart"
markerWidth="2"
markerHeight="2.5"
viewBox="0 0 5.3244081 6.1553851"
inkscape:isstock="true"
inkscape:collect="always"
preserveAspectRatio="none"><path
transform="scale(0.5)"
style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:1pt"
d="M 5.77,0 -2.88,5 V -5 Z"
id="000000_ArchsimMarker_Triangle_Path" /></marker>
<marker
style="overflow:visible"
id="A51E37_ArchsimMarker_Triangle"
refX="0"
refY="0"
orient="auto-start-reverse"
inkscape:stockid="TriangleStart"
markerWidth="2"
markerHeight="2.5"
viewBox="0 0 5.3244081 6.1553851"
inkscape:isstock="true"
inkscape:collect="always"
preserveAspectRatio="none"><path
transform="scale(0.5)"
style="fill:#A51E37;fill-rule:evenodd;stroke:#A51E37;stroke-width:1pt"
d="M 5.77,0 -2.88,5 V -5 Z"
id="A51E37_ArchsimMarker_Triangle_Path" /></marker>
<marker
style="overflow:visible"
id="0000FF_ArchsimMarker_Triangle"
refX="0"
refY="0"
orient="auto-start-reverse"
inkscape:stockid="TriangleStart"
markerWidth="2"
markerHeight="2.5"
viewBox="0 0 5.3244081 6.1553851"
inkscape:isstock="true"
inkscape:collect="always"
preserveAspectRatio="none"><path
transform="scale(0.5)"
style="fill:#0000FF;fill-rule:evenodd;stroke:#0000FF;stroke-width:1pt"
d="M 5.77,0 -2.88,5 V -5 Z"
id="0000FF_ArchsimMarker_Triangle_Path" /></marker>
<marker
style="overflow:visible"
id="000000_ArchsimMarker_Dot"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Dot"
markerWidth="2.5"
markerHeight="2.5"
viewBox="0 0 5.6666667 5.6666667"
inkscape:isstock="true"
inkscape:collect="always"
preserveAspectRatio="xMidYMid"><path
transform="scale(0.5)"
style="fill:#000000;fill-rule:evenodd;stroke:none"
d="M 5,0 C 5,2.76 2.76,5 0,5 -2.76,5 -5,2.76 -5,0 c 0,-2.76 2.3,-5 5,-5 2.76,0 5,2.24 5,5 z"
id="Dot1"
sodipodi:nodetypes="sssss" /></marker>
<marker
style="overflow:visible"
id="0000FF_ArchsimMarker_Dot"
refX="0"
refY="0"
orient="auto"
inkscape:stockid="Dot"
markerWidth="2.5"
markerHeight="2.5"
viewBox="0 0 5.6666667 5.6666667"
inkscape:isstock="true"
inkscape:collect="always"
preserveAspectRatio="xMidYMid"><path
transform="scale(0.5)"
style="fill:#0000FF;fill-rule:evenodd;stroke:none"
d="M 5,0 C 5,2.76 2.76,5 0,5 -2.76,5 -5,2.76 -5,0 c 0,-2.76 2.3,-5 5,-5 2.76,0 5,2.24 5,5 z"
id="Dot1"
sodipodi:nodetypes="sssss" /></marker>
"""
if __name__ == "__main__":
for filename, markers in [
("riscv_five_stage_pipeline.svg", riscv_markers),
("riscv_single_stage_pipeline.svg", riscv_markers),
]:
# open with read permissions
file = open("./webgui/src/img/" + filename, "r+")
# read everything
old_content = file.read()
# go back to the beginning
file.seek(0)
# search for the custom markers section
match = re.search(
r"<!--CUSTOM MARKERS START-->([\s\S]*)<!--CUSTOM MARKERS END-->",
old_content,
)
if match is None:
raise Exception(
"Error: Did not find custom markers section in svg document"
)
# replace that section with our desired markers
section_start = match.start(1)
section_end = match.end(1)
new_content = old_content[:section_start] + markers + old_content[section_end:]
# write the new content to the svg
file.write(new_content)
file.truncate()
file.close()