如何将 FormattedText 字符串转换为基于几何的对象?
我认为这个问题不需要太多解释,我想不出还有很多其他细节我可以提供......
我只需要将 FormattedText 转换为我可以在数学上(几何上)使用的东西。
任何建议表示赞赏!
如何将 FormattedText 字符串转换为基于几何的对象?
我认为这个问题不需要太多解释,我想不出还有很多其他细节我可以提供......
我只需要将 FormattedText 转换为我可以在数学上(几何上)使用的东西。
任何建议表示赞赏!
您可能正在寻找FormattedText.BuildGeometry Method
或FormattedText.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));