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 オブジェクト表現。

次の例は、 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) 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

注釈

テキストが Geometry オブジェクトに変換されるとき、テキストは文字のコレクションではなくなります。テキスト文字列内の文字を変更することはできません。 ただし、ストロークと塗りつぶしのプロパティを変更することで、変換されたテキストの外観に影響を与えることができます。

次の例は、変換されたテキストのストロークと塗りつぶしを変更して視覚効果を作成するいくつかの方法を示しています。

塗りつぶしとストロークの色が異なるテキスト 塗りつぶし ストロークと塗りつぶしをさまざまな色に設定する例

ストロークにイメージ ブラシを適用したテキスト:イメージ ストロークに適用されるイメージ ブラシの例

Geometry オブジェクトに変換され、レンダリングされるテキストは、直接レンダリングされるテキストと同じようには見えない場合があります。

  • Geometry オブジェクトに変換されたテキストは、ClearType を使用してレンダリングされません。 さらに、変換されたベースラインは表示ピクセル全体にスナップされません。

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

適用対象