views:

375

answers:

2

How do I convert a FormattedText string into a geometry-based object?

I don't think this question requires much explanation, and I can't think if very many other details I could give ...

I just need to convert the FormattedText into something I can use mathematically (geometrically).

Any advice is appreciated!

A: 

http://msdn.microsoft.com/en-us/library/ms752098.aspx

Atal123 Studio
Hmm ... This article has a section on geometry that shows that it CAN be done - but it doesn't explain the process or any of the details at all. What am I supposed to DO with the FormattedText object to convert it into a geometry?
Giffyguy
+2  A: 

You are probably looking for FormattedText.BuildGeometry Method or FormattedText.BuildHighlightGeometry Method; both MSDN links are featuring the usual examples too.

The basic usage pattern is like so:

// Create sample formatted text.
FormattedText formattedText = new FormattedText("Sample",
    CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight,
    new Typeface("Verdana"), 16, System.Windows.Media.Brushes.Black);

// Build geometry object that represents the text.
Geometry normalGeometry = formattedText.BuildGeometry(
    new System.Windows.Point(0, 0));

// Build geometry object that represents the highlight bounding box of the text.
Geometry highLightGeometry = formattedText.BuildHighlightGeometry(
    new System.Windows.Point(0, 0));
Steffen Opel