FormattedText text = new FormattedText("Hello World", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); Geometry textGeometry = text.BuildGeometry(new Point(0, 0));
FormattedText text = new FormattedText("Make it bold!", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Times New Roman"), 16, Brushes.Black); text.SetFontWeight(FontWeights.Bold); Geometry textGeometry = text.BuildGeometry(new Point(0, 0));In this example, we create a FormattedText object with the string "Make it bold!", using the Times New Roman font and a size of 16 points. We then set the font weight to bold using the SetFontWeight method. Finally, we call the BuildGeometry method as before to obtain the Geometry object representing the bold text. The System.Windows.Media namespace is included in the PresentationCore library, which is part of the .NET Framework.