FormattedText.BuildGeometry(Point) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve um Geometry objeto que representa o texto formatado, incluindo todos os glifos e decorações do 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
A origem no canto superior esquerdo da geometria resultante.
Devoluções
A Geometry representação do objeto do texto formatado.
Exemplos
O exemplo seguinte mostra como criar um FormattedText objeto e recuperar as geometrias do texto formatado e da sua caixa delimitadora.
/// <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
Observações
Quando o texto é convertido num Geometry objeto, deixa de ser uma coleção de caracteres – não se podem modificar os caracteres na cadeia de texto. No entanto, você pode afetar a aparência do texto convertido modificando suas propriedades de traçado e preenchimento.
Os exemplos seguintes ilustram várias formas de criar efeitos visuais modificando o traço e preenchimento do texto convertido.
Exemplo de definir traço e preenchimento para cores diferentes
Exemplo de um pincel de imagem aplicado ao traço
Texto convertido e renderizado como Geometry objeto pode não parecer igual ao texto renderizado diretamente:
O texto convertido num Geometry objeto não é renderizado usando o ClearType. Além disso, a linha de base do convertido não está ligada a um pixel inteiro do ecrã.
Fontes pequenas, como as comumente usadas no corpo do texto, podem perder legibilidade, parecer desfocadas e variar na aparência.