开发者

Using TextOptions.TextFormattingMode with FormattedText

开发者 https://www.devze.com 2022-12-25 18:23 出处:网络
With WPF4 you can have non-blurry text by adding TextOptions.TextFormattingMode=\"Display\" and TextOptions.TextRenderingMode=\"Aliased\" to your xaml:

With WPF4 you can have non-blurry text by adding TextOptions.TextFormattingMode="Display" and TextOptions.TextRenderingMode="Aliased" to your xaml:

<Window
   TextOptions.TextFormattingMode="Display"
   TextOptions.TextRenderingMode="Aliased">

This works fine for me except for when I draw text with DrawingContext.DrawText like this:

void DrawText(DrawingContext dc)
{
  FormattedText ft = new FormattedText("Hello World",
    System.Globalization.CultureInfo.CurrentCulture,
    System.Windows.FlowDirection.LeftToRight,
    new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
    FontSize,
    brush);
  dc.DrawText(ft, new Point(rect.Left, rect.Top));
}

How can I draw non-blurry text wit开发者_StackOverflow中文版h FormattedText? ie I want TextOptions.TextFormattingMode="Display" and TextOptions.TextRenderingMode="Aliased" to be used.


There's an overloaded constructor for FormattedText that allows specifying a TextFormattingMode: http://msdn.microsoft.com/en-us/library/ee474866.aspx

void DrawText(DrawingContext dc)
{
  FormattedText ft = new FormattedText("Hello World",
    System.Globalization.CultureInfo.CurrentCulture,
    System.Windows.FlowDirection.LeftToRight,
    new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
    FontSize,
    brush,
    null,
    TextFormattingMode.Display);
  dc.DrawText(ft, new Point(rect.Left, rect.Top));
}


Follow the example here for Advanced Text Formatting and create a TextFormatter object and use TextLine.Draw()

0

精彩评论

暂无评论...
验证码 换一张
取 消