-
Notifications
You must be signed in to change notification settings - Fork 0
/
svgator.py
71 lines (60 loc) · 2.68 KB
/
svgator.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
# file with SVG text
filepath = 'text.txt'
# out files prefix
outprename = "Set1_"
with open(filepath) as fp:
line = fp.readline()
cnt = 1
while line:
# add space before and after
line = ' ' + line
line = line.replace('\n', ' \n')
# line = ' ' + line + ' '
# replace x1
line = line.replace(' б', ' <line class="cls-1" x1="1"')
line = line.replace(' в', ' <line class="cls-1" x1="2"')
line = line.replace(' г', ' <line class="cls-1" x1="3"')
line = line.replace(' д', ' <line class="cls-1" x1="4"')
line = line.replace(' ж', ' <line class="cls-1" x1="5"')
line = line.replace(' з', ' <line class="cls-1" x1="6"')
line = line.replace(' к', ' <line class="cls-1" x1="7"')
line = line.replace(' л', ' <line class="cls-1" x1="8"')
line = line.replace(' м', ' <line class="cls-1" x1="9"')
# replace y2
line = line.replace('а ', 'y2="1"/> ')
line = line.replace('е ', 'y2="2"/> ')
line = line.replace('є ', 'y2="3"/> ')
line = line.replace('и ', 'y2="4"/> ')
line = line.replace('і ', 'y2="5"/> ')
line = line.replace('о ', 'y2="6"/> ')
line = line.replace('у ', 'y2="7"/> ')
line = line.replace('ю ', 'y2="8"/> ')
line = line.replace('я ', 'y2="9"/> ')
# replace y1
line = line.replace('а', ' y1="1"')
line = line.replace('е', ' y1="2"')
line = line.replace('є', ' y1="3"')
line = line.replace('и', ' y1="4"')
line = line.replace('і', ' y1="5"')
line = line.replace('о', ' y1="6"')
line = line.replace('у', ' y1="7"')
line = line.replace('ю', ' y1="8"')
line = line.replace('я', ' y1="9"')
# replace x2
line = line.replace('б', ' x2="1" ')
line = line.replace('в', ' x2="2" ')
line = line.replace('г', ' x2="3" ')
line = line.replace('д', ' x2="4" ')
line = line.replace('ж', ' x2="5" ')
line = line.replace('з', ' x2="6" ')
line = line.replace('к', ' x2="7" ')
line = line.replace('л', ' x2="8" ')
line = line.replace('м', ' x2="9" ')
line = '<svg id="Set_5" data-name="Set 5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><defs><style>.cls-1{fill:none;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:0.5px;}</style></defs><title>Set_5</title>' + line + '</svg>'
line = line.replace('> <', '>\n<')
outfilename = outprename + str(cnt) + '.svg'
outfile = open(outfilename, "w")
outfile.write(line)
line = fp.readline()
cnt += 1
outfilename = ''