Langage

FormattedText.BuildGeometry(Point) Méthode

Définition

Renvoie un Geometry objet qui représente le texte mis en forme, y compris 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

Origine supérieure gauche de la géométrie résultante.

Retours

Représentation Geometry d’objet 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 sa zone englobante.

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

Remarques

Lorsque le texte est converti en Geometry objet, il ne s’agit plus d’une collection de caractères. Vous ne pouvez plus modifier les caractères de la chaîne de texte. Toutefois, vous pouvez affecter l’apparence du texte converti en modifiant 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 différentes couleurs pour le texte de remplissage et de Exemple de définition d’un trait et d’un remplissage à différentes couleurs

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

Le texte qui est converti en objet et rendu Geometry peut ne pas ressembler directement au texte affiché :

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

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

S’applique à