Windows apps
Collapse the table of content
Expand the table of content
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 (Point)

 

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.

Text with different colors for fill and stroke

Example of setting stroke and fill to different colors

Text with image brush applied to stroke

Example of an image brush applied to the 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
Available since 3.0
Return to top
Show:
© 2016 Microsoft