Share via


FormattedText.BuildGeometry(Point) Método

Definición

Devuelve un objeto Geometry que representa el texto con formato, incluidos todos los glifos y decoraciones del texto.

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

Parámetros

origin
Point

Origen superior izquierdo de la geometría resultante.

Devoluciones

Representación del objeto Geometry del texto con formato.

Ejemplos

En el ejemplo siguiente se muestra cómo crear un FormattedText objeto y recuperar las geometrías del texto con formato y su cuadro de límite.

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

Comentarios

Cuando el texto se convierte en un Geometry objeto , ya no es una colección de caracteres, no se pueden modificar los caracteres de la cadena de texto. Sin embargo, puede afectar a la apariencia del texto convertido modificando sus propiedades de trazo y relleno.

En los ejemplos siguientes se muestran varias maneras de crear efectos visuales modificando el trazo y el relleno del texto convertido.

Texto con diferentes colores para relleno y trazo Ejemplo de establecimiento de trazo y relleno en diferentes colores

Texto con pincel de imagen aplicado al trazo Ejemplo de pincel de imagen aplicado al trazo

El texto que se convierte en y se representa como un Geometry objeto puede no tener el mismo aspecto que el texto representado directamente:

  • El texto convertido en un Geometry objeto no se representa mediante ClearType. Además, la línea base del convertido no se ajusta a un píxel de pantalla completo.

  • Las fuentes pequeñas, como las que se usan normalmente en el texto del cuerpo, pueden perder legibilidad, aparecer borrosas y variar en apariencia.

Se aplica a