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

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

Poznámky

Při převodu Geometry textu na objekt už není kolekce znaků – znaky v textovém řetězci nelze upravit. Můžete ovlivnit vzhled převedeného textu úpravou jeho vlastností tahu a 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 text tahu 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 a 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 objektu přichycený k celému pixelu zobrazení.

  • Malá písma, jako jsou ta, která se běžně používají v základním textu, můžou ztratit čitelnost, zobrazovat rozmazaná a měnit vzhled.

Platí pro