fix polyline and polygon conversion (#85)

* fix polyline and polygon conversion

* update version

* revert version
pull/114/head
NataliaTs 2020-06-20 06:32:01 +03:00 committed by GitHub
parent b714ff872d
commit b503b9b3a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -47,10 +47,10 @@ def ellipse2pathd(ellipse):
return d return d
def polyline2pathd(polyline_d, is_polygon=False): def polyline2pathd(polyline, is_polygon=False):
"""converts the string from a polyline points-attribute to a string for a """converts the string from a polyline points-attribute to a string for a
Path object d-attribute""" Path object d-attribute"""
points = COORD_PAIR_TMPLT.findall(polyline_d) points = COORD_PAIR_TMPLT.findall(polyline.get('points', ''))
closed = (float(points[0][0]) == float(points[-1][0]) and closed = (float(points[0][0]) == float(points[-1][0]) and
float(points[0][1]) == float(points[-1][1])) float(points[0][1]) == float(points[-1][1]))
@ -66,13 +66,13 @@ def polyline2pathd(polyline_d, is_polygon=False):
return d return d
def polygon2pathd(polyline_d): def polygon2pathd(polyline):
"""converts the string from a polygon points-attribute to a string """converts the string from a polygon points-attribute to a string
for a Path object d-attribute. for a Path object d-attribute.
Note: For a polygon made from n points, the resulting path will be Note: For a polygon made from n points, the resulting path will be
composed of n lines (even if some of these lines have length zero). composed of n lines (even if some of these lines have length zero).
""" """
return polyline2pathd(polyline_d, True) return polyline2pathd(polyline, True)
def rect2pathd(rect): def rect2pathd(rect):
@ -157,14 +157,14 @@ def svg2paths(svg_file_location,
# path strings, add to list # path strings, add to list
if convert_polylines_to_paths: if convert_polylines_to_paths:
plins = [dom2dict(el) for el in doc.getElementsByTagName('polyline')] plins = [dom2dict(el) for el in doc.getElementsByTagName('polyline')]
d_strings += [polyline2pathd(pl['points']) for pl in plins] d_strings += [polyline2pathd(pl) for pl in plins]
attribute_dictionary_list += plins attribute_dictionary_list += plins
# Use minidom to extract polygon strings from input SVG, convert to # Use minidom to extract polygon strings from input SVG, convert to
# path strings, add to list # path strings, add to list
if convert_polygons_to_paths: if convert_polygons_to_paths:
pgons = [dom2dict(el) for el in doc.getElementsByTagName('polygon')] pgons = [dom2dict(el) for el in doc.getElementsByTagName('polygon')]
d_strings += [polygon2pathd(pg['points']) for pg in pgons] d_strings += [polygon2pathd(pg) for pg in pgons]
attribute_dictionary_list += pgons attribute_dictionary_list += pgons
if convert_lines_to_paths: if convert_lines_to_paths: