/ awk
awk
1 #!/run/current-system/sw/bin/awk -f 2 3 # ./awk -v myVar="myVal" <file> 4 5 # get vars passed to this script, set FS to C (split on C) & add it back at the end by setting OFS to C as well 6 BEGIN { 7 angleDeg=angleDeg 8 angleRad=angleDeg % 360 * (3.141592 / 180) 9 centerx=centerx 10 centery=centery 11 FS = "[C]" 12 OFS = "C" 13 } 14 15 /<path id="(Vector|Vector_[0-9])" d=/ { 16 v=1 # found a Vector tag! 17 } 18 19 !v { 20 # no Vector tag found -> just print 21 print 22 } 23 24 v { 25 # Vector tag found -> chaos ensues 26 # we need to rotate the M (moveto) & C (cubic bezier curve) SVG commands around the center of the circle 27 # see https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands 28 29 # $1, $2, etc. contain the segments divided by 'C' making up the current line (FS is C, see BEGIN) 30 31 # $1 contains the segment with the moveto command, get everything after the M: 32 mcommand = substr($1, match($1, /M/)) 33 split(mcommand, mvals, " |M") # split on spaces & M, number values will be at indexes 2 & 3 34 # rotate the moveto point around the centerpoint of the circle 35 mnewvals = "" 36 mnewvals = mnewvals " " (mvals[2] - centerx) * cos(angleRad) - (mvals[3] - centery) * sin(angleRad) + centerx 37 mnewvals = mnewvals " " (mvals[3] - centery) * cos(angleRad) + (mvals[2] - centerx) * sin(angleRad) + centery 38 # replace the 2 numbers 39 sub(/([0-9]+(\.[0-9]+)? )+([0-9]+(\.[0-9]+)?)/, mnewvals, $1) 40 41 42 # iterate on all of the segments starting from the second one (the first C command) 43 for(i=2; i<=NF; i++) { 44 if (i>9) { 45 break # we don't have more than 8 C commands & we start at index 2 46 } 47 48 split($i, cvals, " |Z"); # split list of numbers on spaces, make sure to not include the trailing Z SVG command 49 50 # rotate all of the points of the C command around the center 51 newvals = "" 52 newvals = newvals " " (cvals[1] - centerx) * cos(angleRad) - (cvals[2] - centery) * sin(angleRad) + centerx 53 newvals = newvals " " (cvals[2] - centery) * cos(angleRad) + (cvals[1] - centerx) * sin(angleRad) + centery 54 newvals = newvals " " (cvals[3] - centerx) * cos(angleRad) - (cvals[4] - centery) * sin(angleRad) + centerx 55 newvals = newvals " " (cvals[4] - centery) * cos(angleRad) + (cvals[3] - centerx) * sin(angleRad) + centery 56 newvals = newvals " " (cvals[5] - centerx) * cos(angleRad) - (cvals[6] - centery) * sin(angleRad) + centerx 57 newvals = newvals " " (cvals[6] - centery) * cos(angleRad) + (cvals[5] - centerx) * sin(angleRad) + centery 58 59 # replace the numbers in the current segment with the newly calculated ones 60 sub(/([0-9]+(\.[0-9]+)? )+([0-9]+(\.[0-9]+)?)/, newvals, $i) 61 } 62 # print the line with rotated points 63 print $0 64 v=0 65 }