Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

FormattedText.BuildGeometry Method

Returns a Geometry object that represents the formatted text, including all glyphs and text decorations.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

public Geometry BuildGeometry(
	Point origin
)

Parameters

origin
Type: System.Windows.Point

The top-left origin of the resulting geometry.

Return Value

Type: System.Windows.Media.Geometry
The Geometry object representation of the formatted text.

When text is converted to a Geometry object, it is no longer a collection of characters—you cannot modify the characters in the text string. However, you can affect the appearance of the converted text by modifying its stroke and fill properties.

The following examples illustrate several ways of creating visual effects by modifying the stroke and fill of converted text.

Example of setting stroke and fill to different colors

Text with different colors for fill and stroke
Example of an image brush applied to the stroke

Text with image brush applied to stroke

Text that is converted to and rendered as a Geometry object may not look the same as text rendered directly:

  • Text converted to a Geometry object is not rendered using ClearType. In addition, the baseline of the converted is not snapped to a whole display pixel.

  • Small fonts, such as those commonly used in body text, may lose legibility, appear blurred, and vary in appearance.

The following example shows how to create a FormattedText object and to retrieve the geometries of the formatted text and its bounding box.

/// <summary> 
/// Create the outline geometry based on the formatted text. 
/// </summary> 
public void CreateText()
{
    System.Windows.FontStyle fontStyle = FontStyles.Normal;
    FontWeight fontWeight = FontWeights.Medium;

    if (Bold == true) fontWeight = FontWeights.Bold;
    if (Italic == true) fontStyle = FontStyles.Italic;

    // Create the formatted text based on the properties set.
    FormattedText formattedText = new FormattedText(
        Text,
        CultureInfo.GetCultureInfo("en-us"),
        FlowDirection.LeftToRight,
        new Typeface(
            Font,
            fontStyle,
            fontWeight,
            FontStretches.Normal),
        FontSize,
        System.Windows.Media.Brushes.Black // This brush does not matter since we use the geometry of the text. 
        );

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

    // Build the geometry object that represents the text hightlight. 
    if (Highlight == true)
    {
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft