Given a System.Windows.Media.Geometry class instance, is there an easy way to convert this to a list of outlines and points? For example, how could I simply break this down into a list of LineSegments for custom rendering.
FormattedText formattedText = new FormattedText( "Hello", ...);
Geometry textGeometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));
How to list each of the outlines (where O would be an inside/outside circle) and each of the points on each outline?
As per the answer below;
var flatten = textGeometry.GetFlattenedPathGeometry();
PathFigureCollection pfc = flatten.Figures;
foreach (PathFigure pf in pfc)
{
foreach (PathSegment ps in pf.Segments)
{
if (ps is LineSegment)
On the
Geometryclass, you can useGetFlattenedPathGeometry(),GetOutlinedPathGeometry()(or related – decide what you actually want) to get aPathGeometryand then query theFiguresto get a list of figures. Each of thesePathFigureobjects has the segments (which may be line segments, bezier, etc).Note that in doing this, you may lose some information if you do it naively – if any arbitrary Geometry can be given, you will probably need to do more than just call FlattenedPathGeometry to not lose things like fill information.