Reputation: 690
I was wondering if there was a tool to convert a path data like "M 0 0 l 10 10" to it's equivalent line/curve segment code.
Currently I'm using:
string pathXaml = "<Path xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" Data=\"M 0 0 l 10 10\"/>";
Path path = (Path)System.Windows.Markup.XamlReader.Load(pathXaml);
It appears to me that calling XamlParser is much slower than explicitly creating the line segments. However converting a lot of paths by hand is very tedious.
Upvotes: 4
Views: 1964
Reputation: 690
This program will do the conversion: http://stringtopathgeometry.codeplex.com/
Upvotes: 4
Reputation: 74842
There's nothing built-in to generate C# or VB code from the geometry minilanguage, but you could create one as follows:
PathFigureCollection.Parse
on your path string. This will return a PathFigureCollection
instance.Whether this is more or less tedious than converting the paths by hand is something only you can decide, though... it probably depends on how many different kinds of segment you need to handle (i.e. how many different kinds of segment appear in your path strings), since you will have to write separate code for LineSegments, ArcSegments, etc.
EDIT: Thanks to Anvaka in comments for simplifying the original answer by drawing my attention to PathFigureCollection.Parse.
Upvotes: 2