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 を使用してレンダリングされません。 さらに、変換されたベースラインは、表示ピクセル全体にスナップされません。

  • 本文で一般的に使用されるフォントなどの小さなフォントは、読みやすさが失われ、ぼやけて表示され、外観が異なる場合があります。

適用対象