FormattedText.BuildGeometry(Point) Metodo

Definizione

Restituisce un oggetto Geometry che rappresenta il testo formattato, inclusi tutti i glifi e le decorazioni di testo.

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

Parametri

origin
Point

Origine superiore sinistra della geometria risultante.

Restituisce

Rappresentazione dell'oggetto Geometry del testo formattato.

Esempio

Nell'esempio seguente viene illustrato come creare un FormattedText oggetto e recuperare le geometrie del testo formattato e del relativo rettangolo di selezione.

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

Commenti

Quando il testo viene convertito in un Geometry oggetto, non è più una raccolta di caratteri. Non è possibile modificare i caratteri nella stringa di testo. Tuttavia, è possibile intervenire sull'aspetto del testo convertito modificandone le proprietà del tratto e del riempimento.

Gli esempi seguenti illustrano diversi modi per creare effetti visivi modificando il tratto e il riempimento del testo convertito.

Testo con colori diversi per riempimento e tratto Esempio di impostazione del tratto e del riempimento in colori diversi

Testo con pennello immagine applicato al tratto Esempio di pennello immagine applicato al tratto

Il testo convertito e sottoposto a rendering come Geometry oggetto potrebbe non essere simile al rendering diretto del testo:

  • Il rendering del testo convertito in un Geometry oggetto non viene eseguito usando ClearType. Inoltre, la linea di base dell'oggetto convertito non viene ritagliata in un pixel di visualizzazione intero.

  • I tipi di carattere piccoli, ad esempio quelli comunemente usati nel testo del corpo, possono perdere la leggibilità, apparire sfocati e variare nell'aspetto.

Si applica a