-
Notifications
You must be signed in to change notification settings - Fork 0
/
Read_svg_file.py
35 lines (22 loc) · 924 Bytes
/
Read_svg_file.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
import xml.etree.ElementTree as ET
from simplepath import parsePath
def read_svg_file(svg_path):
svg_tree = ET.parse(svg_path)
root = svg_tree.getroot()
coords = []
coord_dict = {}
for path in root.iter('{http://www.w3.org/2000/svg}path'):
path_data = path.get('d')
path_coords = parsePath(path_data)
for segment in path_coords:
command, params = segment
if command == 'L':
start_coord = tuple(params[:2])
end_coord = tuple(params[2:])
if start_coord not in coord_dict:
coord_dict[start_coord] = len(coords)
coords.append(start_coord)
if end_coord not in coord_dict:
coord_dict[end_coord] = len(coords)
coords.append(end_coord)
return coords, coord_dict