@@ -21,28 +21,56 @@ $shapeValues = @(foreach ($in in $this.input) {
2121
2222if (-not $ShapeType ) { $ShapeType = ' shape' }
2323
24- if ($ShapeType -eq ' polygon' ) {
25- return " polygon($ (
26- @ (for ($valueIndex = 0 ; $valueIndex -lt $shapeValues.Count ; $valueIndex += 2 ) {
27- @ (if ($null -ne $shapeValues [$valueIndex + 1 ]) {
28- $shapeValues [$valueIndex ]
29- $shapeValues [$valueIndex + 1 ]
30- } else {
31- $shapeValues [$valueIndex ]
32- $shapeValues [$valueIndex ]
33- }) -join ' '
34- }) -join ' , '
35- ) )"
36- }
24+ @ (
25+ " $shapeType ("
26+ switch ($shapeType ) {
27+ path {
28+ # Only paths need to be quoted
29+ " '$ ( $shapeValues -join ' ' -replace " '" , " \'" -replace [Environment ]::NewLine, ' \' ) '"
30+ }
31+ polygon {
32+ # Polygons need to be in comma separated pairs,
33+ # and could come as pairs or comma separated pairs
34+ $shapeValues = @ ($shapeValues -replace ' ,' -ne ' ' )
35+ @ (for ($valueIndex = 0 ; $valueIndex -lt $shapeValues.Count ; $valueIndex += 2 ) {
36+ @ (if ($null -ne $shapeValues [$valueIndex + 1 ]) {
37+ $shapeValues [$valueIndex ]
38+ $shapeValues [$valueIndex + 1 ]
39+ } else {
40+ $shapeValues [$valueIndex ]
41+ $shapeValues [$valueIndex ]
42+ }) -join ' '
43+ }) -join ' , '
44+ }
45+ shape {
46+ # Shapes segments start with keywords, and each segment should be separated by commas
47+
48+ $keyPattern = " ^(?>$ (
49+ ' arc' , ' curve' , ' close' , ' move' , ' [hv]?line' , ' smooth' -join ' |'
50+ ) )$"
51+
52+ $buffer = @ ()
53+ @ (
54+ for ($valueIndex = 0 ; $valueIndex -lt $shapeValues.Count ; $valueIndex ++ ) {
55+ if ($shapeValues [$valueIndex ] -match $keyPattern ) {
56+ if ($buffer ) { $buffer -join ' ' }
57+ $buffer = @ ()
58+ }
59+ if ($shapeValues [$valueIndex ] -eq ' ,' ) {
60+ continue
61+ }
62+ $buffer += $shapeValues [$valueIndex ]
63+ }
64+ if ($buffer ) {$buffer -join ' ' }
65+ ) -join ' , '
66+
67+ }
68+
69+ default {
70+ # all other shapes simply join their values with spaces
71+ $shapeValues -join ' '
72+ }
73+ }
74+ " )"
75+ ) -join ' '
3776
38- $joinWith = if ($ShapeType -notin ' shape' ) {
39- ' '
40- } else {
41- ' , '
42- }
43-
44- " $shapeType ($ (
45- @ (
46- $shapeValues
47- ) -join $joinWith
48- ) )"
0 commit comments