svg.path: ValueError: could not convert string to float: 'C'

In [3]: svg.path.parse_path("M 5 1 v 7.344 A 3.574 3.574 0 003.5 8 3.515 3.515 0 000 11.5 C 0 13.421 1.579 15 3.5 15 A 3.517 3.517 0 007 11.531 v -
   ...: 7.53 h 6 v 4.343 A 3.574 3.574 0 0011.5 8 3.515 3.515 0 008 11.5 c 0 1.921 1.579 3.5 3.5 3.5 1.9 0 3.465 -1.546 3.5 -3.437 V 1 z")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-5f3c4d12c583> in <module>
----> 1 svg.path.parse_path("M 5 1 v 7.344 A 3.574 3.574 0 003.5 8 3.515 3.515 0 000 11.5 C 0 13.421 1.579 15 3.5 15 A 3.517 3.517 0 007 11.531 v -7.53 h 6 v 4.343 A 3.574 3.574 0 0011.5 8 3.515 3.515 0 008 11.5 c 0 1.921 1.579 3.5 3.5 3.5 1.9 0 3.465 -1.546 3.5 -3.437 V 1 z")

~/.local/lib/python3.9/site-packages/svg/path/parser.py in parse_path(pathdef, current_pos)
    177             radius = float(elements.pop()) + float(elements.pop()) * 1j
    178             rotation = float(elements.pop())
--> 179             arc = float(elements.pop())
    180             sweep = float(elements.pop())
    181             end = float(elements.pop()) + float(elements.pop()) * 1j

ValueError: could not convert string to float: 'C'

Valid SVG:

<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
  <path d="M 5 1 v 7.344 A 3.574 3.574 0 003.5 8 3.515 3.515 0 000 11.5 C 0 13.421 1.579 15 3.5 15 A 3.517 3.517 0 007 11.531 v -7.53 h 6 v 4.343 A 3.574 3.574 0 0011.5 8 3.515 3.515 0 008 11.5 c 0 1.921 1.579 3.5 3.5 3.5 1.9 0 3.465 -1.546 3.5 -3.437 V 1 z" style="line-height:normal;-inkscape-font-specification:Sans;text-indent:0;text-align:start;text-decoration-line:none;text-transform:none;marker:none" color="#000" font-weight="400" font-family="Sans" overflow="visible" fill="#474747"/>
</svg>

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (14 by maintainers)

Most upvoted comments

Yeah, svgelements has that as a function approximate_arcs_as_cubics() or something like that that’ll go through and replace the damned things. My personal preference is a circular arc with a control point and endpoint. You only need 3 points to define a circle and they’d be easy to write by hand, etc. I even raised and issue at WC3 for it. No joy.