Edit

Share via


FormattedText.BuildHighlightGeometry Method

Definition

Returns a Geometry object that represents the highlight bounding box of the formatted text.

Overloads

BuildHighlightGeometry(Point)

Returns a Geometry object that represents the highlight bounding box of the formatted text.

BuildHighlightGeometry(Point, Int32, Int32)

Returns a Geometry object that represents the highlight bounding box for a specified substring of the formatted text.

BuildHighlightGeometry(Point)

Returns a Geometry object that represents the highlight bounding box of the formatted text.

public:
 System::Windows::Media::Geometry ^ BuildHighlightGeometry(System::Windows::Point origin);
public System.Windows.Media.Geometry BuildHighlightGeometry (System.Windows.Point origin);
member this.BuildHighlightGeometry : System.Windows.Point -> System.Windows.Media.Geometry
Public Function BuildHighlightGeometry (origin As Point) As Geometry

Parameters

origin
Point

The origin of the highlight region.

Returns

The Geometry object that represents the highlight bounding box of the formatted text.

Examples

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) fontWeight = FontWeights.Bold;
    if (Italic) 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 highlight.
    if (Highlight)
    {
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(new System.Windows.Point(0, 0));
    }
}
''' <summary>
''' Create the outline geometry based on the formatted text.
''' </summary>
Public Sub CreateText()
    Dim fontStyle As FontStyle = FontStyles.Normal
    Dim fontWeight As FontWeight = FontWeights.Medium

    If Bold = True Then
        fontWeight = FontWeights.Bold
    End If
    If Italic = True Then
        fontStyle = FontStyles.Italic
    End If

    ' Create the formatted text based on the properties set.
    Dim formattedText As New FormattedText(Text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface(Font, fontStyle, fontWeight, FontStretches.Normal), FontSize, 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 Point(0, 0))

    ' Build the geometry object that represents the text highlight.
    If Highlight = True Then
        _textHighLightGeometry = formattedText.BuildHighlightGeometry(New Point(0, 0))
    End If
End Sub

Remarks

The bounding box region contains the entire formatted text area starting at the point specified by origin. The returned Geometry object contains only the bounding box of the highlighted text and does not contain any rendered text.

The following example illustrates a way to creating visual effects by modifying the stroke and highlight of converted text.

Text with image brush applied to stroke Example of an image brush applied to the stroke and highlight

Applies to

BuildHighlightGeometry(Point, Int32, Int32)

Returns a Geometry object that represents the highlight bounding box for a specified substring of the formatted text.

public:
 System::Windows::Media::Geometry ^ BuildHighlightGeometry(System::Windows::Point origin, int startIndex, int count);
public System.Windows.Media.Geometry BuildHighlightGeometry (System.Windows.Point origin, int startIndex, int count);
member this.BuildHighlightGeometry : System.Windows.Point * int * int -> System.Windows.Media.Geometry
Public Function BuildHighlightGeometry (origin As Point, startIndex As Integer, count As Integer) As Geometry

Parameters

origin
Point

The origin of the highlight region.

startIndex
Int32

The index of the initial character the highlight bounds should be obtained for.

count
Int32

The number of characters the highlight bounds should contain.

Returns

The Geometry object that represents the highlight bounding box of the formatted text substring.

Remarks

The returned Geometry object contains only the bounding box of the highlighted text and does not contain any rendered text.

Applies to