ParseSVG.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. # ##########################################################
  2. # FlatCAM: 2D Post-processing for Manufacturing #
  3. # http://flatcam.org #
  4. # Author: Juan Pablo Caram (c) #
  5. # Date: 12/18/2015 #
  6. # MIT Licence #
  7. # #
  8. # SVG Features supported: #
  9. # * Groups #
  10. # * Rectangles (w/ rounded corners) #
  11. # * Circles #
  12. # * Ellipses #
  13. # * Polygons #
  14. # * Polylines #
  15. # * Lines #
  16. # * Paths #
  17. # * All transformations #
  18. # #
  19. # Reference: www.w3.org/TR/SVG/Overview.html #
  20. # ##########################################################
  21. # import xml.etree.ElementTree as ET
  22. from svg.path import Line, Arc, CubicBezier, QuadraticBezier, parse_path
  23. from svg.path.path import Move
  24. from shapely.geometry import LineString, LinearRing, MultiLineString
  25. from shapely.affinity import skew, affine_transform, rotate
  26. import numpy as np
  27. from flatcamParsers.ParseFont import *
  28. log = logging.getLogger('base2')
  29. def svgparselength(lengthstr):
  30. """
  31. Parse an SVG length string into a float and a units
  32. string, if any.
  33. :param lengthstr: SVG length string.
  34. :return: Number and units pair.
  35. :rtype: tuple(float, str|None)
  36. """
  37. integer_re_str = r'[+-]?[0-9]+'
  38. number_re_str = r'(?:[+-]?[0-9]*\.[0-9]+(?:[Ee]' + integer_re_str + ')?' + r')|' + \
  39. r'(?:' + integer_re_str + r'(?:[Ee]' + integer_re_str + r')?)'
  40. length_re_str = r'(' + number_re_str + r')(em|ex|px|in|cm|mm|pt|pc|%)?'
  41. match = re.search(length_re_str, lengthstr)
  42. if match:
  43. return float(match.group(1)), match.group(2)
  44. return
  45. def path2shapely(path, object_type, res=1.0):
  46. """
  47. Converts an svg.path.Path into a Shapely
  48. Polygon or LinearString.
  49. :rtype : Polygon
  50. :rtype : LineString
  51. :param path: svg.path.Path instance
  52. :param res: Resolution (minimum step along path)
  53. :return: Shapely geometry object
  54. """
  55. points = []
  56. geometry = []
  57. geo_element = None
  58. rings = []
  59. for component in path:
  60. # Line
  61. if isinstance(component, Line):
  62. start = component.start
  63. x, y = start.real, start.imag
  64. if len(points) == 0 or points[-1] != (x, y):
  65. points.append((x, y))
  66. end = component.end
  67. points.append((end.real, end.imag))
  68. continue
  69. # Arc, CubicBezier or QuadraticBezier
  70. if isinstance(component, Arc) or \
  71. isinstance(component, CubicBezier) or \
  72. isinstance(component, QuadraticBezier):
  73. # How many points to use in the discrete representation.
  74. length = component.length(res / 10.0)
  75. steps = int(length / res + 0.5)
  76. # solve error when step is below 1,
  77. # it may cause other problems, but LineString needs at least two points
  78. if steps == 0:
  79. steps = 1
  80. frac = 1.0 / steps
  81. # print length, steps, frac
  82. for i in range(steps):
  83. point = component.point(i * frac)
  84. x, y = point.real, point.imag
  85. if len(points) == 0 or points[-1] != (x, y):
  86. points.append((x, y))
  87. end = component.point(1.0)
  88. points.append((end.real, end.imag))
  89. continue
  90. # Move
  91. if isinstance(component, Move):
  92. if not points:
  93. continue
  94. else:
  95. rings.append(points)
  96. points = []
  97. continue
  98. log.warning("I don't know what this is: %s" % str(component))
  99. continue
  100. # if there are still points in points then add them to the last ring
  101. if points:
  102. rings.append(points)
  103. rings = MultiLineString(rings)
  104. if len(rings) > 0:
  105. if len(rings) == 1:
  106. # Polygons are closed and require more than 2 points
  107. if Point(rings[0][0]).almost_equals(Point(rings[0][-1])) and len(rings[0]) > 2:
  108. geo_element = Polygon(rings[0])
  109. else:
  110. geo_element = LineString(rings[0])
  111. else:
  112. try:
  113. geo_element = Polygon(rings[0], rings[1:])
  114. except Exception as e:
  115. coords = list()
  116. for line in rings:
  117. coords.append(line.coords[0])
  118. coords.append(line.coords[1])
  119. geo_element = Polygon(coords)
  120. geometry.append(geo_element)
  121. return geometry
  122. def svgrect2shapely(rect, n_points=32):
  123. """
  124. Converts an SVG rect into Shapely geometry.
  125. :param rect: Rect Element
  126. :type rect: xml.etree.ElementTree.Element
  127. :return: shapely.geometry.polygon.LinearRing
  128. """
  129. w = svgparselength(rect.get('width'))[0]
  130. h = svgparselength(rect.get('height'))[0]
  131. x_obj = rect.get('x')
  132. if x_obj is not None:
  133. x = svgparselength(x_obj)[0]
  134. else:
  135. x = 0
  136. y_obj = rect.get('y')
  137. if y_obj is not None:
  138. y = svgparselength(y_obj)[0]
  139. else:
  140. y = 0
  141. rxstr = rect.get('rx')
  142. rystr = rect.get('ry')
  143. if rxstr is None and rystr is None: # Sharp corners
  144. pts = [
  145. (x, y), (x + w, y), (x + w, y + h), (x, y + h), (x, y)
  146. ]
  147. else: # Rounded corners
  148. rx = 0.0 if rxstr is None else svgparselength(rxstr)[0]
  149. ry = 0.0 if rystr is None else svgparselength(rystr)[0]
  150. n_points = int(n_points / 4 + 0.5)
  151. t = np.arange(n_points, dtype=float) / n_points / 4
  152. x_ = (x + w - rx) + rx * np.cos(2 * np.pi * (t + 0.75))
  153. y_ = (y + ry) + ry * np.sin(2 * np.pi * (t + 0.75))
  154. lower_right = [(x_[i], y_[i]) for i in range(n_points)]
  155. x_ = (x + w - rx) + rx * np.cos(2 * np.pi * t)
  156. y_ = (y + h - ry) + ry * np.sin(2 * np.pi * t)
  157. upper_right = [(x_[i], y_[i]) for i in range(n_points)]
  158. x_ = (x + rx) + rx * np.cos(2 * np.pi * (t + 0.25))
  159. y_ = (y + h - ry) + ry * np.sin(2 * np.pi * (t + 0.25))
  160. upper_left = [(x_[i], y_[i]) for i in range(n_points)]
  161. x_ = (x + rx) + rx * np.cos(2 * np.pi * (t + 0.5))
  162. y_ = (y + ry) + ry * np.sin(2 * np.pi * (t + 0.5))
  163. lower_left = [(x_[i], y_[i]) for i in range(n_points)]
  164. pts = [(x + rx, y), (x - rx + w, y)] + \
  165. lower_right + \
  166. [(x + w, y + ry), (x + w, y + h - ry)] + \
  167. upper_right + \
  168. [(x + w - rx, y + h), (x + rx, y + h)] + \
  169. upper_left + \
  170. [(x, y + h - ry), (x, y + ry)] + \
  171. lower_left
  172. return Polygon(pts).buffer(0)
  173. # return LinearRing(pts)
  174. def svgcircle2shapely(circle):
  175. """
  176. Converts an SVG circle into Shapely geometry.
  177. :param circle: Circle Element
  178. :type circle: xml.etree.ElementTree.Element
  179. :return: Shapely representation of the circle.
  180. :rtype: shapely.geometry.polygon.LinearRing
  181. """
  182. # cx = float(circle.get('cx'))
  183. # cy = float(circle.get('cy'))
  184. # r = float(circle.get('r'))
  185. cx = svgparselength(circle.get('cx'))[0] # TODO: No units support yet
  186. cy = svgparselength(circle.get('cy'))[0] # TODO: No units support yet
  187. r = svgparselength(circle.get('r'))[0] # TODO: No units support yet
  188. # TODO: No resolution specified.
  189. return Point(cx, cy).buffer(r)
  190. def svgellipse2shapely(ellipse, n_points=64):
  191. """
  192. Converts an SVG ellipse into Shapely geometry
  193. :param ellipse: Ellipse Element
  194. :type ellipse: xml.etree.ElementTree.Element
  195. :param n_points: Number of discrete points in output.
  196. :return: Shapely representation of the ellipse.
  197. :rtype: shapely.geometry.polygon.LinearRing
  198. """
  199. cx = svgparselength(ellipse.get('cx'))[0] # TODO: No units support yet
  200. cy = svgparselength(ellipse.get('cy'))[0] # TODO: No units support yet
  201. rx = svgparselength(ellipse.get('rx'))[0] # TODO: No units support yet
  202. ry = svgparselength(ellipse.get('ry'))[0] # TODO: No units support yet
  203. t = np.arange(n_points, dtype=float) / n_points
  204. x = cx + rx * np.cos(2 * np.pi * t)
  205. y = cy + ry * np.sin(2 * np.pi * t)
  206. pts = [(x[i], y[i]) for i in range(n_points)]
  207. return Polygon(pts).buffer(0)
  208. # return LinearRing(pts)
  209. def svgline2shapely(line):
  210. """
  211. :param line: Line element
  212. :type line: xml.etree.ElementTree.Element
  213. :return: Shapely representation on the line.
  214. :rtype: shapely.geometry.polygon.LinearRing
  215. """
  216. x1 = svgparselength(line.get('x1'))[0]
  217. y1 = svgparselength(line.get('y1'))[0]
  218. x2 = svgparselength(line.get('x2'))[0]
  219. y2 = svgparselength(line.get('y2'))[0]
  220. return LineString([(x1, y1), (x2, y2)])
  221. def svgpolyline2shapely(polyline):
  222. ptliststr = polyline.get('points')
  223. points = parse_svg_point_list(ptliststr)
  224. return LineString(points)
  225. def svgpolygon2shapely(polygon):
  226. ptliststr = polygon.get('points')
  227. points = parse_svg_point_list(ptliststr)
  228. return Polygon(points).buffer(0)
  229. # return LinearRing(points)
  230. def getsvggeo(node, object_type, root=None):
  231. """
  232. Extracts and flattens all geometry from an SVG node
  233. into a list of Shapely geometry.
  234. :param node: xml.etree.ElementTree.Element
  235. :return: List of Shapely geometry
  236. :rtype: list
  237. """
  238. if root is None:
  239. root = node
  240. kind = re.search('(?:\{.*\})?(.*)$', node.tag).group(1)
  241. geo = []
  242. # Recurse
  243. if len(node) > 0:
  244. for child in node:
  245. subgeo = getsvggeo(child, object_type, root)
  246. if subgeo is not None:
  247. geo += subgeo
  248. # Parse
  249. elif kind == 'path':
  250. log.debug("***PATH***")
  251. P = parse_path(node.get('d'))
  252. P = path2shapely(P, object_type)
  253. # for path, the resulting geometry is already a list so no need to create a new one
  254. geo = P
  255. elif kind == 'rect':
  256. log.debug("***RECT***")
  257. R = svgrect2shapely(node)
  258. geo = [R]
  259. elif kind == 'circle':
  260. log.debug("***CIRCLE***")
  261. C = svgcircle2shapely(node)
  262. geo = [C]
  263. elif kind == 'ellipse':
  264. log.debug("***ELLIPSE***")
  265. E = svgellipse2shapely(node)
  266. geo = [E]
  267. elif kind == 'polygon':
  268. log.debug("***POLYGON***")
  269. poly = svgpolygon2shapely(node)
  270. geo = [poly]
  271. elif kind == 'line':
  272. log.debug("***LINE***")
  273. line = svgline2shapely(node)
  274. geo = [line]
  275. elif kind == 'polyline':
  276. log.debug("***POLYLINE***")
  277. pline = svgpolyline2shapely(node)
  278. geo = [pline]
  279. elif kind == 'use':
  280. log.debug('***USE***')
  281. # href= is the preferred name for this[1], but inkscape still generates xlink:href=.
  282. # [1] https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use#Attributes
  283. href = node.attrib['href'] if 'href' in node.attrib else node.attrib['{http://www.w3.org/1999/xlink}href']
  284. ref = root.find(".//*[@id='%s']" % href.replace('#', ''))
  285. if ref is not None:
  286. geo = getsvggeo(ref, object_type, root)
  287. else:
  288. log.warning("Unknown kind: " + kind)
  289. geo = None
  290. # ignore transformation for unknown kind
  291. if geo is not None:
  292. # Transformations
  293. if 'transform' in node.attrib:
  294. trstr = node.get('transform')
  295. trlist = parse_svg_transform(trstr)
  296. # log.debug(trlist)
  297. # Transformations are applied in reverse order
  298. for tr in trlist[::-1]:
  299. if tr[0] == 'translate':
  300. geo = [translate(geoi, tr[1], tr[2]) for geoi in geo]
  301. elif tr[0] == 'scale':
  302. geo = [scale(geoi, tr[1], tr[2], origin=(0, 0))
  303. for geoi in geo]
  304. elif tr[0] == 'rotate':
  305. geo = [rotate(geoi, tr[1], origin=(tr[2], tr[3]))
  306. for geoi in geo]
  307. elif tr[0] == 'skew':
  308. geo = [skew(geoi, tr[1], tr[2], origin=(0, 0))
  309. for geoi in geo]
  310. elif tr[0] == 'matrix':
  311. geo = [affine_transform(geoi, tr[1:]) for geoi in geo]
  312. else:
  313. raise Exception('Unknown transformation: %s', tr)
  314. return geo
  315. def getsvgtext(node, object_type, units='MM'):
  316. """
  317. Extracts and flattens all geometry from an SVG node
  318. into a list of Shapely geometry.
  319. :param node: xml.etree.ElementTree.Element
  320. :return: List of Shapely geometry
  321. :rtype: list
  322. """
  323. kind = re.search('(?:\{.*\})?(.*)$', node.tag).group(1)
  324. geo = []
  325. # Recurse
  326. if len(node) > 0:
  327. for child in node:
  328. subgeo = getsvgtext(child, object_type, units=units)
  329. if subgeo is not None:
  330. geo += subgeo
  331. # Parse
  332. elif kind == 'tspan':
  333. current_attrib = node.attrib
  334. txt = node.text
  335. style_dict = {}
  336. parrent_attrib = node.getparent().attrib
  337. style = parrent_attrib['style']
  338. try:
  339. style_list = style.split(';')
  340. for css in style_list:
  341. style_dict[css.rpartition(':')[0]] = css.rpartition(':')[-1]
  342. pos_x = float(current_attrib['x'])
  343. pos_y = float(current_attrib['y'])
  344. # should have used the instance from FlatCAMApp.App but how? without reworking everything ...
  345. pf = ParseFont()
  346. pf.get_fonts_by_types()
  347. font_name = style_dict['font-family'].replace("'", '')
  348. if style_dict['font-style'] == 'italic' and style_dict['font-weight'] == 'bold':
  349. font_type = 'bi'
  350. elif style_dict['font-weight'] == 'bold':
  351. font_type = 'bold'
  352. elif style_dict['font-style'] == 'italic':
  353. font_type = 'italic'
  354. else:
  355. font_type = 'regular'
  356. # value of 2.2 should have been 2.83 (conversion value from pixels to points)
  357. # but the dimensions from Inkscape did not corelate with the ones after importing in FlatCAM
  358. # so I adjusted this
  359. font_size = svgparselength(style_dict['font-size'])[0] * 2.2
  360. geo = [pf.font_to_geometry(txt,
  361. font_name=font_name,
  362. font_size=font_size,
  363. font_type=font_type,
  364. units=units,
  365. coordx=pos_x,
  366. coordy=pos_y)
  367. ]
  368. geo = [(scale(g, 1.0, -1.0)) for g in geo]
  369. except Exception as e:
  370. log.debug(str(e))
  371. else:
  372. geo = None
  373. # ignore transformation for unknown kind
  374. if geo is not None:
  375. # Transformations
  376. if 'transform' in node.attrib:
  377. trstr = node.get('transform')
  378. trlist = parse_svg_transform(trstr)
  379. # log.debug(trlist)
  380. # Transformations are applied in reverse order
  381. for tr in trlist[::-1]:
  382. if tr[0] == 'translate':
  383. geo = [translate(geoi, tr[1], tr[2]) for geoi in geo]
  384. elif tr[0] == 'scale':
  385. geo = [scale(geoi, tr[1], tr[2], origin=(0, 0))
  386. for geoi in geo]
  387. elif tr[0] == 'rotate':
  388. geo = [rotate(geoi, tr[1], origin=(tr[2], tr[3]))
  389. for geoi in geo]
  390. elif tr[0] == 'skew':
  391. geo = [skew(geoi, tr[1], tr[2], origin=(0, 0))
  392. for geoi in geo]
  393. elif tr[0] == 'matrix':
  394. geo = [affine_transform(geoi, tr[1:]) for geoi in geo]
  395. else:
  396. raise Exception('Unknown transformation: %s', tr)
  397. return geo
  398. def parse_svg_point_list(ptliststr):
  399. """
  400. Returns a list of coordinate pairs extracted from the "points"
  401. attribute in SVG polygons and polyline's.
  402. :param ptliststr: "points" attribute string in polygon or polyline.
  403. :return: List of tuples with coordinates.
  404. """
  405. pairs = []
  406. last = None
  407. pos = 0
  408. i = 0
  409. for match in re.finditer(r'(\s*,\s*)|(\s+)', ptliststr.strip(' ')):
  410. val = float(ptliststr[pos:match.start()])
  411. if i % 2 == 1:
  412. pairs.append((last, val))
  413. else:
  414. last = val
  415. pos = match.end()
  416. i += 1
  417. # Check for last element
  418. val = float(ptliststr[pos:])
  419. if i % 2 == 1:
  420. pairs.append((last, val))
  421. else:
  422. log.warning("Incomplete coordinates.")
  423. return pairs
  424. def parse_svg_transform(trstr):
  425. """
  426. Parses an SVG transform string into a list
  427. of transform names and their parameters.
  428. Possible transformations are:
  429. * Translate: translate(<tx> [<ty>]), which specifies
  430. a translation by tx and ty. If <ty> is not provided,
  431. it is assumed to be zero. Result is
  432. ['translate', tx, ty]
  433. * Scale: scale(<sx> [<sy>]), which specifies a scale operation
  434. by sx and sy. If <sy> is not provided, it is assumed to be
  435. equal to <sx>. Result is: ['scale', sx, sy]
  436. * Rotate: rotate(<rotate-angle> [<cx> <cy>]), which specifies
  437. a rotation by <rotate-angle> degrees about a given point.
  438. If optional parameters <cx> and <cy> are not supplied,
  439. the rotate is about the origin of the current user coordinate
  440. system. Result is: ['rotate', rotate-angle, cx, cy]
  441. * Skew: skewX(<skew-angle>), which specifies a skew
  442. transformation along the x-axis. skewY(<skew-angle>), which
  443. specifies a skew transformation along the y-axis.
  444. Result is ['skew', angle-x, angle-y]
  445. * Matrix: matrix(<a> <b> <c> <d> <e> <f>), which specifies a
  446. transformation in the form of a transformation matrix of six
  447. values. matrix(a,b,c,d,e,f) is equivalent to applying the
  448. transformation matrix [a b c d e f]. Result is
  449. ['matrix', a, b, c, d, e, f]
  450. Note: All parameters to the transformations are "numbers",
  451. i.e. no units present.
  452. :param trstr: SVG transform string.
  453. :type trstr: str
  454. :return: List of transforms.
  455. :rtype: list
  456. """
  457. trlist = []
  458. assert isinstance(trstr, str)
  459. trstr = trstr.strip(' ')
  460. integer_re_str = r'[+-]?[0-9]+'
  461. number_re_str = r'(?:[+-]?[0-9]*\.[0-9]+(?:[Ee]' + integer_re_str + ')?' + r')|' + \
  462. r'(?:' + integer_re_str + r'(?:[Ee]' + integer_re_str + r')?)'
  463. # num_re_str = r'[\+\-]?[0-9\.e]+' # TODO: Negative exponents missing
  464. comma_or_space_re_str = r'(?:(?:\s+)|(?:\s*,\s*))'
  465. translate_re_str = r'translate\s*\(\s*(' + \
  466. number_re_str + r')(?:' + \
  467. comma_or_space_re_str + \
  468. r'(' + number_re_str + r'))?\s*\)'
  469. scale_re_str = r'scale\s*\(\s*(' + \
  470. number_re_str + r')' + \
  471. r'(?:' + comma_or_space_re_str + \
  472. r'(' + number_re_str + r'))?\s*\)'
  473. skew_re_str = r'skew([XY])\s*\(\s*(' + \
  474. number_re_str + r')\s*\)'
  475. rotate_re_str = r'rotate\s*\(\s*(' + \
  476. number_re_str + r')' + \
  477. r'(?:' + comma_or_space_re_str + \
  478. r'(' + number_re_str + r')' + \
  479. comma_or_space_re_str + \
  480. r'(' + number_re_str + r'))?\s*\)'
  481. matrix_re_str = r'matrix\s*\(\s*' + \
  482. r'(' + number_re_str + r')' + comma_or_space_re_str + \
  483. r'(' + number_re_str + r')' + comma_or_space_re_str + \
  484. r'(' + number_re_str + r')' + comma_or_space_re_str + \
  485. r'(' + number_re_str + r')' + comma_or_space_re_str + \
  486. r'(' + number_re_str + r')' + comma_or_space_re_str + \
  487. r'(' + number_re_str + r')\s*\)'
  488. while len(trstr) > 0:
  489. match = re.search(r'^' + translate_re_str, trstr)
  490. if match:
  491. trlist.append([
  492. 'translate',
  493. float(match.group(1)),
  494. float(match.group(2)) if (match.group(2) is not None) else 0.0
  495. ])
  496. trstr = trstr[len(match.group(0)):].strip(' ')
  497. continue
  498. match = re.search(r'^' + scale_re_str, trstr)
  499. if match:
  500. trlist.append([
  501. 'scale',
  502. float(match.group(1)),
  503. float(match.group(2)) if (match.group(2) is not None) else float(match.group(1))
  504. ])
  505. trstr = trstr[len(match.group(0)):].strip(' ')
  506. continue
  507. match = re.search(r'^' + skew_re_str, trstr)
  508. if match:
  509. trlist.append([
  510. 'skew',
  511. float(match.group(2)) if match.group(1) == 'X' else 0.0,
  512. float(match.group(2)) if match.group(1) == 'Y' else 0.0
  513. ])
  514. trstr = trstr[len(match.group(0)):].strip(' ')
  515. continue
  516. match = re.search(r'^' + rotate_re_str, trstr)
  517. if match:
  518. trlist.append([
  519. 'rotate',
  520. float(match.group(1)),
  521. float(match.group(2)) if match.group(2) else 0.0,
  522. float(match.group(3)) if match.group(3) else 0.0
  523. ])
  524. trstr = trstr[len(match.group(0)):].strip(' ')
  525. continue
  526. match = re.search(r'^' + matrix_re_str, trstr)
  527. if match:
  528. trlist.append(['matrix'] + [float(x) for x in match.groups()])
  529. trstr = trstr[len(match.group(0)):].strip(' ')
  530. continue
  531. # raise Exception("Don't know how to parse: %s" % trstr)
  532. log.error("[ERROR] Don't know how to parse: %s" % trstr)
  533. return trlist
  534. # if __name__ == "__main__":
  535. # tree = ET.parse('tests/svg/drawing.svg')
  536. # root = tree.getroot()
  537. # ns = re.search(r'\{(.*)\}', root.tag).group(1)
  538. # print(ns)
  539. # for geo in getsvggeo(root):
  540. # print(geo)