如何将FormattedText字符串转换为基于几何的对象?

时间:2009-07-15 19:16:32

标签: .net wpf .net-3.5 geometry formatted-text

如何将FormattedText字符串转换为基于几何的对象?

我认为这个问题不需要太多解释,我想不出我能提供的其他细节......

我只需要将FormattedText转换为我可以数学(几何)使用的东西。

感谢任何建议!

1 个答案:

答案 0 :(得分:7)

您可能正在寻找FormattedText.BuildGeometry MethodFormattedText.BuildHighlightGeometry Method;这两个MSDN链接也都有通常的例子。

基本使用模式如下:

// 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));