From f05803820fdbf8a63be76f2c0089200c5a2e7dd9 Mon Sep 17 00:00:00 2001 From: Harikrushna Parmar Date: Wed, 29 May 2024 12:23:39 +0530 Subject: [PATCH 01/10] MGG-1299 [#ccc] svgpathtools: Remove arc from ellipse2pathd function and add cubic curve instead 'arc' command in path-data is not supported in vglite toolkit Signed-off-by: Harikrushna Parmar --- svgpathtools/svg_to_paths.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 65591af2..ad29b196 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -46,12 +46,18 @@ def ellipse2pathd(ellipse): cx = float(cx) cy = float(cy) - d = '' - d += 'M' + str(cx - rx) + ',' + str(cy) - d += 'a' + str(rx) + ',' + str(ry) + ' 0 1,0 ' + str(2 * rx) + ',0' - d += 'a' + str(rx) + ',' + str(ry) + ' 0 1,0 ' + str(-2 * rx) + ',0' + PATH_KAPPA = 0.552284 + rxKappa = rx * PATH_KAPPA; + ryKappa = ry * PATH_KAPPA; - return d + 'z' + d = '' + d += 'M ' + str(cx) + ' ' + str(cy - ry) + d += ' C ' + str(cx + rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx + rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx + rx) + ' ' + str(cy) + d += ' C ' + str(cx + rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx + rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx) + ' ' + str(cy + ry) + d += ' C ' + str(cx - rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx - rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx - rx) + ' ' + str(cy) + d += ' C ' + str(cx - rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx - rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx) + ' ' + str(cy - ry) + + return d + ' Z' def polyline2pathd(polyline, is_polygon=False): From 4c4cb51016b7f3eba2d620e2c445ee60ec03017e Mon Sep 17 00:00:00 2001 From: Nilam Gaikwad Date: Wed, 9 Oct 2024 19:33:19 +0530 Subject: [PATCH 02/10] MGG-1299 [#ccc] svgpathtools: Changes to properly parse command There needs to be a space between command and point data so that we can split draw commands and its arguments correctly. Signed-off-by: Nilam Gaikwad --- svgpathtools/svg_to_paths.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index ad29b196..dcf4c22e 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -77,9 +77,9 @@ def polyline2pathd(polyline, is_polygon=False): if is_polygon and closed: points.append(points[0]) - d = 'M' + 'L'.join('{0} {1}'.format(x,y) for x,y in points) + d = 'M ' + ' L '.join('{0} {1}'.format(x,y) for x,y in points) if is_polygon or closed: - d += 'z' + d += ' z' return d @@ -127,7 +127,7 @@ def rect2pathd(rect): x2, y2 = x + w, y + h x3, y3 = x, y + h - d = ("M{} {} L {} {} L {} {} L {} {} z" + d = ("M {} {} L {} {} L {} {} L {} {} z" "".format(x0, y0, x1, y1, x2, y2, x3, y3)) return d From 405baa9e03dcb861962fa16dd737a133cb84da08 Mon Sep 17 00:00:00 2001 From: Kratika Jain Date: Sat, 24 Aug 2024 14:57:23 +0530 Subject: [PATCH 03/10] MGG-1407 [#ccc] svgpathtools: bugfix: Handle cases where shapes have missing or empty values Signed-off-by: Kratika Jain --- svgpathtools/svg_to_paths.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index dcf4c22e..f1a11c2d 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -31,8 +31,8 @@ def ellipse2pathd(ellipse): """converts the parameters from an ellipse or a circle to a string for a Path object d-attribute""" - cx = ellipse.get('cx', 0) - cy = ellipse.get('cy', 0) + cx = (ellipse.get('cx', 0) or 0) + cy = (ellipse.get('cy', 0) or 0) rx = ellipse.get('rx', None) ry = ellipse.get('ry', None) r = ellipse.get('r', None) @@ -40,8 +40,8 @@ def ellipse2pathd(ellipse): if r is not None: rx = ry = float(r) else: - rx = float(rx) - ry = float(ry) + rx = float(rx or 0) + ry = float(ry or 0) cx = float(cx) cy = float(cy) @@ -66,7 +66,11 @@ def polyline2pathd(polyline, is_polygon=False): if isinstance(polyline, str): points = polyline else: - points = COORD_PAIR_TMPLT.findall(polyline.get('points', '')) + raw_points = polyline.get('points', '') + if not raw_points: + points = [(0,0)] + else: + points = COORD_PAIR_TMPLT.findall(raw_points) closed = (float(points[0][0]) == float(points[-1][0]) and float(points[0][1]) == float(points[-1][1])) @@ -97,8 +101,8 @@ def rect2pathd(rect): The rectangle will start at the (x,y) coordinate specified by the rectangle object and proceed counter-clockwise.""" - x, y = float(rect.get('x', 0)), float(rect.get('y', 0)) - w, h = float(rect.get('width', 0)), float(rect.get('height', 0)) + x, y = float(rect.get('x', 0) or 0), float(rect.get('y', 0) or 0) + w, h = float(rect.get('width', 0) or 0), float(rect.get('height', 0) or 0) if 'rx' in rect or 'ry' in rect: # if only one, rx or ry, is present, use that value for both From 0ec4f998cecaeb2ce9ed874c858cbb3b3056cbbe Mon Sep 17 00:00:00 2001 From: Harikrushna Parmar Date: Mon, 2 Sep 2024 10:19:44 +0530 Subject: [PATCH 04/10] MGG-1402 [#ccc] svgpathtools:bugfix: Skip the end path in a polyline if no dedicated end path is provided Introduce an 'is_polygon' flag in 'polygon2pathd' function to handle the end path in polyline and polygon Signed-off-by: Harikrushna Parmar --- svgpathtools/svg_to_paths.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index f1a11c2d..0d5f47e4 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -87,13 +87,13 @@ def polyline2pathd(polyline, is_polygon=False): return d -def polygon2pathd(polyline): +def polygon2pathd(polyline, is_polygon): """converts the string from a polygon points-attribute to a string for a Path object d-attribute. 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). """ - return polyline2pathd(polyline, True) + return polyline2pathd(polyline, is_polygon) def rect2pathd(rect): @@ -214,7 +214,7 @@ def dom2dict(element): # path strings, add to list if convert_polygons_to_paths: pgons = [dom2dict(el) for el in doc.getElementsByTagName('polygon')] - d_strings += [polygon2pathd(pg) for pg in pgons] + d_strings += [polygon2pathd(pg, True) for pg in pgons] attribute_dictionary_list += pgons if convert_lines_to_paths: From 302071a07087bad22078fcc339684875425f26fe Mon Sep 17 00:00:00 2001 From: Harikrushna Parmar Date: Mon, 30 Sep 2024 13:41:41 +0530 Subject: [PATCH 05/10] MGG-1448 [#ccc] svgpathtools: bugfix: Handle polyline path correctly if path string or is_polygon flag is enableed then append path given in input if path string and is_polygon flag is enable then append 'z' path Signed-off-by: Harikrushna Parmar --- svgpathtools/svg_to_paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 0d5f47e4..824d062b 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -78,7 +78,7 @@ def polyline2pathd(polyline, is_polygon=False): # The `parse_path` call ignores redundant 'z' (closure) commands # e.g. `parse_path('M0 0L100 100Z') == parse_path('M0 0L100 100L0 0Z')` # This check ensures that an n-point polygon is converted to an n-Line path. - if is_polygon and closed: + if is_polygon or closed: points.append(points[0]) d = 'M ' + ' L '.join('{0} {1}'.format(x,y) for x,y in points) From d7927a7453941c3bd024ef585feaaa64f825a1f7 Mon Sep 17 00:00:00 2001 From: Harikrushna Parmar Date: Wed, 9 Oct 2024 13:25:38 +0530 Subject: [PATCH 06/10] MGG-1481 [#ccc] svgpathtools: bugfix: Start ellipse path from rightmost point and draw clockwise Signed-off-by: Harikrushna Parmar --- svgpathtools/svg_to_paths.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 824d062b..218f036b 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -50,12 +50,21 @@ def ellipse2pathd(ellipse): rxKappa = rx * PATH_KAPPA; ryKappa = ry * PATH_KAPPA; + #According to the SVG specification (https://lists.w3.org/Archives/Public/www-archive/2005May/att-0005/SVGT12_Main.pdf), + #Section 9.4, "The 'ellipse' element": "The arc of an 'ellipse' element begins at the "3 o'clock" point on + #the radius and progresses towards the "9 o'clock". Therefore, the ellipse begins at the rightmost point + #and progresses clockwise. d = '' - d += 'M ' + str(cx) + ' ' + str(cy - ry) - d += ' C ' + str(cx + rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx + rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx + rx) + ' ' + str(cy) + # Move to the rightmost point + d += 'M ' + str(cx + rx) + ' ' + str(cy) + # Draw bottom-right quadrant d += ' C ' + str(cx + rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx + rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx) + ' ' + str(cy + ry) + # Draw bottom-left quadrant d += ' C ' + str(cx - rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx - rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx - rx) + ' ' + str(cy) + # Draw top-left quadrant d += ' C ' + str(cx - rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx - rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx) + ' ' + str(cy - ry) + # Draw top-right quadrant + d += ' C ' + str(cx + rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx + rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx + rx) + ' ' + str(cy) return d + ' Z' From 833a0a64c034cfe101196a47c6aab3683815bd9e Mon Sep 17 00:00:00 2001 From: Nilam Gaikwad Date: Thu, 24 Oct 2024 11:53:54 +0530 Subject: [PATCH 07/10] NXPG-896 [#ccc]: Add Modified by NXP Copyright note Add Modified by NXP Copyright Signed-off-by: Nilam Gaikwad --- svgpathtools/svg_to_paths.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 218f036b..dcb03bc2 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -1,3 +1,6 @@ +# +# Modified by NXP 2024 +# """This submodule contains tools for creating path objects from SVG files. The main tool being the svg2paths() function.""" From a70e494f1c3d0331e32a71697fc367d196f23fad Mon Sep 17 00:00:00 2001 From: NGExplorer Date: Mon, 5 May 2025 15:25:43 +0530 Subject: [PATCH 08/10] Update svgpathtools/svg_to_paths.py Hello @mathandy , We have incorporated this suggestion. We'll upstream our changes in this PR in 1-2 days. Co-authored-by: Andrew Port --- svgpathtools/svg_to_paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index dcb03bc2..11ed5ff8 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -99,7 +99,7 @@ def polyline2pathd(polyline, is_polygon=False): return d -def polygon2pathd(polyline, is_polygon): +def polygon2pathd(polyline, is_polygon=True): """converts the string from a polygon points-attribute to a string for a Path object d-attribute. Note: For a polygon made from n points, the resulting path will be From c71b2577d376745c10830eb3e26853acd8a99917 Mon Sep 17 00:00:00 2001 From: Harikrushna Parmar Date: Mon, 5 May 2025 17:15:46 +0530 Subject: [PATCH 09/10] MGG-1656 [#ccc] svgpathtools: bugfix: Make arc as default Add `use_cubics` flag to optionally select between arc and cubic Signed-off-by: Harikrushna Parmar --- svgpathtools/svg_to_paths.py | 48 +++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 11ed5ff8..98466e76 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -30,7 +30,7 @@ def path2pathd(path): return path.get('d', '') -def ellipse2pathd(ellipse): +def ellipse2pathd(ellipse, use_cubics=False): """converts the parameters from an ellipse or a circle to a string for a Path object d-attribute""" @@ -49,25 +49,33 @@ def ellipse2pathd(ellipse): cx = float(cx) cy = float(cy) - PATH_KAPPA = 0.552284 - rxKappa = rx * PATH_KAPPA; - ryKappa = ry * PATH_KAPPA; - - #According to the SVG specification (https://lists.w3.org/Archives/Public/www-archive/2005May/att-0005/SVGT12_Main.pdf), - #Section 9.4, "The 'ellipse' element": "The arc of an 'ellipse' element begins at the "3 o'clock" point on - #the radius and progresses towards the "9 o'clock". Therefore, the ellipse begins at the rightmost point - #and progresses clockwise. - d = '' - # Move to the rightmost point - d += 'M ' + str(cx + rx) + ' ' + str(cy) - # Draw bottom-right quadrant - d += ' C ' + str(cx + rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx + rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx) + ' ' + str(cy + ry) - # Draw bottom-left quadrant - d += ' C ' + str(cx - rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx - rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx - rx) + ' ' + str(cy) - # Draw top-left quadrant - d += ' C ' + str(cx - rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx - rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx) + ' ' + str(cy - ry) - # Draw top-right quadrant - d += ' C ' + str(cx + rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx + rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx + rx) + ' ' + str(cy) + if use_cubics: + + PATH_KAPPA = 0.552284 + rxKappa = rx * PATH_KAPPA; + ryKappa = ry * PATH_KAPPA; + + #According to the SVG specification (https://lists.w3.org/Archives/Public/www-archive/2005May/att-0005/SVGT12_Main.pdf), + #Section 9.4, "The 'ellipse' element": "The arc of an 'ellipse' element begins at the "3 o'clock" point on + #the radius and progresses towards the "9 o'clock". Therefore, the ellipse begins at the rightmost point + #and progresses clockwise. + d = '' + # Move to the rightmost point + d += 'M ' + str(cx + rx) + ' ' + str(cy) + # Draw bottom-right quadrant + d += ' C ' + str(cx + rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx + rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx) + ' ' + str(cy + ry) + # Draw bottom-left quadrant + d += ' C ' + str(cx - rxKappa) + ' ' + str(cy + ry) + ' ' + str(cx - rx) + ' ' + str(cy + ryKappa) + ' ' + str(cx - rx) + ' ' + str(cy) + # Draw top-left quadrant + d += ' C ' + str(cx - rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx - rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx) + ' ' + str(cy - ry) + # Draw top-right quadrant + d += ' C ' + str(cx + rxKappa) + ' ' + str(cy - ry) + ' ' + str(cx + rx) + ' ' + str(cy - ryKappa) + ' ' + str(cx + rx) + ' ' + str(cy) + else: + d = '' + d += 'M' + str(cx - rx) + ',' + str(cy) + d += 'a' + str(rx) + ',' + str(ry) + ' 0 1,0 ' + str(2 * rx) + ',0' + d += 'a' + str(rx) + ',' + str(ry) + ' 0 1,0 ' + str(-2 * rx) + ',0' + return d + ' Z' From 1396f997f1716c93d995e6677a28e608971eae23 Mon Sep 17 00:00:00 2001 From: Harikrushna Parmar Date: Mon, 5 May 2025 17:18:38 +0530 Subject: [PATCH 10/10] MGG-1656 [#ccc] svgpathtools: bugfix: Avoid rendering of empty point data in polylines and polygons Signed-off-by: Harikrushna Parmar --- svgpathtools/svg_to_paths.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 98466e76..58bf7799 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -86,11 +86,7 @@ def polyline2pathd(polyline, is_polygon=False): if isinstance(polyline, str): points = polyline else: - raw_points = polyline.get('points', '') - if not raw_points: - points = [(0,0)] - else: - points = COORD_PAIR_TMPLT.findall(raw_points) + points = COORD_PAIR_TMPLT.findall(polyline.get('points', '')) closed = (float(points[0][0]) == float(points[-1][0]) and float(points[0][1]) == float(points[-1][1]))