Språk

FormattedText.BuildGeometry(Point) Metod

Definition

Returnerar ett Geometry objekt som representerar den formaterade texten, inklusive alla glyfer och textdekorationer.

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

Parametrar

origin
Point

Det övre vänstra ursprunget för den resulterande geometrin.

Returer

Objektrepresentationen Geometry av den formaterade texten.

Exempel

I följande exempel visas hur du skapar ett FormattedText objekt och hämtar geometrierna för den formaterade texten och dess avgränsningsruta.

/// <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

Kommentarer

När text konverteras till ett Geometry objekt är det inte längre en samling tecken . Du kan inte ändra tecknen i textsträngen. Du kan dock påverka utseendet på den konverterade texten genom att ändra dess linje- och fyllningsegenskaper.

I följande exempel visas flera sätt att skapa visuella effekter genom att ändra linje och fyllning av konverterad text.

Text med olika färger för fyllning och linje Exempel på att ange linje och fyllning i olika färger

Text med bildborste tillämpad på linjetext Exempel på en bildborste som tillämpas på strecket

Text som konverteras till och återges som ett Geometry objekt kanske inte ser likadan ut som text som återges direkt:

  • Text som konverteras till ett Geometry objekt återges inte med ClearType. Dessutom fästs inte baslinjen för den konverterade till en hel visningspixel.

  • Små teckensnitt, till exempel de som ofta används i brödtext, kan förlora läsbarhet, verka suddiga och variera i utseende.

Gäller för