mathandy / svgpathtools

A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
MIT License
558 stars 142 forks source link

Unable to read circle/ellipse when cx and cy are not specified. #77

Closed sumeet- closed 6 years ago

sumeet- commented 6 years ago

Reading a file containing below svg throws error.

<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="-100 -100 200 200">
  <circle r="100" />
 </svg>

Below is the error.

In [5]: svgpathtools.svg2paths2('disvg_output.svg')                                                                                             
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-b24a2854f246> in <module>
----> 1 svgpathtools.svg2paths2('../red-chalice/svgtransform/disvg_output.svg')

~/Data/Projects/svgpathtools/svgpathtools/svg_to_paths.py in svg2paths2(svg_file_location, return_svg_attributes, convert_circles_to_paths, convert_ellipses_to_paths, convert_lines_to_paths, convert_polylines_to_paths, convert_polygons_to_paths, convert_rectangles_to_paths)
    213                      convert_polylines_to_paths=convert_polylines_to_paths,
    214                      convert_polygons_to_paths=convert_polygons_to_paths,
--> 215                      convert_rectangles_to_paths=convert_rectangles_to_paths)

~/Data/Projects/svgpathtools/svgpathtools/svg_to_paths.py in svg2paths(svg_file_location, return_svg_attributes, convert_circles_to_paths, convert_ellipses_to_paths, convert_lines_to_paths, convert_polylines_to_paths, convert_polygons_to_paths, convert_rectangles_to_paths)
    176     if convert_circles_to_paths:
    177         circles = [dom2dict(el) for el in doc.getElementsByTagName('circle')]
--> 178         d_strings += [ellipse2pathd(c) for c in circles]
    179         attribute_dictionary_list += circles
    180 

~/Data/Projects/svgpathtools/svgpathtools/svg_to_paths.py in <listcomp>(.0)
    176     if convert_circles_to_paths:
    177         circles = [dom2dict(el) for el in doc.getElementsByTagName('circle')]
--> 178         d_strings += [ellipse2pathd(c) for c in circles]
    179         attribute_dictionary_list += circles
    180 

~/Data/Projects/svgpathtools/svgpathtools/svg_to_paths.py in ellipse2pathd(ellipse)
     37         ry = float(ry)
     38 
---> 39     cx = float(cx)
     40     cy = float(cy)
     41 

TypeError: float() argument must be a string or a number, not 'NoneType'

SVG definition says, if cx and cy are not specified consider it as "0" https://www.w3.org/TR/SVG11/shapes.html#CircleElementCXAttribute

I dig into the code and found that here default value should be 0