FormattedText.BuildGeometry(Point) 메서드

정의

모든 문자 모양과 텍스트 장식을 포함하여 서식 있는 텍스트를 나타내는 Geometry 개체를 반환합니다.

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

매개 변수

origin
Point

결과 도형의 왼쪽 위 원점입니다.

반환

Geometry

서식 있는 텍스트의 Geometry 개체 표현입니다.

예제

다음 예제에서는 개체를 FormattedText 만들고 서식이 지정된 텍스트와 해당 경계 상자의 기하 도형을 검색하는 방법을 보여 있습니다.

/// <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 highlight.
    if (Highlight == true)
    {
        _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

설명

텍스트가 개체로 Geometry 변환되면 더 이상 문자 컬렉션이 아닙니다. 텍스트 문자열의 문자를 수정할 수 없습니다. 그러나 스트로크와 채우기 속성을 수정하여 변환된 텍스트의 모양에 영향을 줄 수 있습니다.

다음 예제에서는 변환된 텍스트의 스트로크 및 채우기를 수정하여 시각적 효과를 만드는 여러 가지 방법을 보여 줍니다.

채우기 및 스트로크에 다른 색이 있는 텍스트 스트로크 및 채우기를 다른 색으로 설정하는 예제

스트로크에 이미지 브러시가 적용된 텍스트 스트로크에 적용된 이미지 브러시의 예

개체로 Geometry 변환되고 렌더링되는 텍스트는 직접 렌더링된 텍스트와 같지 않을 수 있습니다.

  • 개체로 Geometry 변환된 텍스트는 ClearType을 사용하여 렌더링되지 않습니다. 또한 변환된 기준선은 전체 디스플레이 픽셀에 스냅되지 않습니다.

  • 본문 텍스트에 일반적으로 사용되는 글꼴과 같은 작은 글꼴은 가독성을 잃고 흐리게 표시되며 모양이 달라질 수 있습니다.

적용 대상