Share via


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 轉譯。 此外,轉換的基準不會貼齊到整個顯示圖元。

  • 小型字型,例如通常用於本文中的字型,可能會失去可讀性、顯示模糊,以及外觀不同。

適用於