Reputation: 500
How can i convert the following Android Path representation to SVG Path representation? This points are used by the Android Path class to draw free form entries, how can i convert them to SVG Path tag?
"pointList":
[
{
"x": 822.94635,
"y": 266.12482
},
{
"x": 824.1951,
"y": 266.12482
},
...
{
"x": 979.0439,
"y": 186.02078
},
{
"x": 979.0439,
"y": 186.02078
}
]
Upvotes: 1
Views: 2015
Reputation: 23637
I'm assuming the points are to be drawn in a sequence with straight lines. In this case, you have to generate one move-to (M
) command, followed by several line-to (L
) commands and separate them with spaces to generate the SVG path d
attribute.
You start with move-to generating
var d = "M" + pointList[0].x + "," + pointList[0].y;
Then the others in a pointList.length - 1
loop with line-to, adding spaces between the commands:
d += " " + "L" + pointList[i].x + "," + pointList[i].y;
And you'll have a the data for the SVG path.
You should be aware that the positions are relative to the view port definitions.
Upvotes: 2