FormattedText.BuildGeometry(Point) Metoda

Definice

Geometry Vrátí objekt, který představuje formátovaný text, včetně všech glyfů a textových dekorací.

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

Parametry

origin
Point

Levý horní začátek výsledné geometrie.

Návraty

Geometry

Reprezentace Geometry objektu formátovaného textu.

Příklady

Následující příklad ukazuje, jak vytvořit FormattedText objekt a načíst geometrie formátovaného textu a jeho ohraničujícího pole.

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

Poznámky

Když je text převeden na Geometry objekt, už není kolekcí znaků – nelze změnit znaky v textovém řetězci. Vzhled převedeného textu ale můžete ovlivnit úpravou jeho tahů a vlastností výplně.

Následující příklady ilustrují několik způsobů vytváření vizuálních efektů úpravou tahu a výplně převedeného textu.

Text s různými barvami pro výplň a tah Příklad nastavení tahu a výplně na různé barvy

Text s štětcem obrázku použitým na tah Příklad štětce obrázku použitého na tah

Text převedený na objekt nebo vykreslený jako Geometry objekt nemusí vypadat stejně jako text vykreslený přímo:

  • Text převedený na Geometry objekt není vykreslen pomocí ClearType. Kromě toho není směrný plán převedeného obrazu přichycený k celému pixelu zobrazení.

  • Malá písma, jako jsou ty, které se běžně používají v základním textu, můžou ztratit čitelnost, jsou rozmazaná a liší se ve vzhledu.

Platí pro