FormattedText.BuildGeometry(Point) Méthode

Définition

Renvoie un objet Geometry qui représente le texte mis en forme, dont tous les glyphes et décorations de texte.

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

Paramètres

origin
Point

L'origine supérieure gauche de la géométrie résultante.

Retours

La représentation d'objet Geometry du texte mis en forme.

Exemples

L’exemple suivant montre comment créer un FormattedText objet et récupérer les géométries du texte mis en forme et de son cadre englobant.

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

Remarques

Lorsque le texte est converti en objet Geometry , il ne s’agit plus d’une collection de caractères. Vous ne pouvez pas modifier les caractères de la chaîne de texte. Vous pouvez néanmoins modifier l’apparence du texte converti en changeant ses propriétés de trait et de remplissage.

Les exemples suivants illustrent plusieurs façons de créer des effets visuels en modifiant le trait et le remplissage du texte converti.

Texte avec des couleurs différentes pour le remplissage et le trait Exemple de définition d’un trait et d’un remplissage sur différentes couleurs

Texte avec pinceau d’image appliqué au trait Exemple de pinceau d’image appliqué au trait

Le texte converti en objet et rendu en tant qu’objet Geometry peut ne pas ressembler au texte rendu directement :

  • Le texte converti en objet Geometry n’est pas rendu à l’aide de ClearType. En outre, la base de référence du converti n’est pas alignée sur un pixel d’affichage entier.

  • Les petites polices, telles que celles couramment utilisées dans le corps du texte, peuvent perdre en lisibilité, apparaître floues et varier en apparence.

S’applique à