WPF blurry text

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

WPF blurry text

Post by MVUser6 » Mon Sep 03, 2012 1:39 pm

Hi,

we are trying to migrate from regular .NET version to WPF version.
in comparison to the regular version, in WPF we get the text(using TextOut function and also using GdiPlusCanvas.DrawText) blurry - we are using Tahoma font with size 8.

i read about it a little bit and i assume it's a general rendering problem\feature in WPF. i found that in WPF4 microsoft added a new DP called TextOptions.TextRenderingMode, to control how the text render.
after trying it on the TeeChart, nothing happen:

TextOptions.SetTextRenderingMode(Chart,TextRenderingMode.Grayscale); //Or Aliasing
Chart.Graphics3D.TextOut(tRect.Left, tRect.Top, sText);

i tried many other variations, but i couldn't find a solution to display the text clear like in regular .net version.

do you have any solutions for me?
how can i use the TextRenderingMode DP with the teechart and make it work?
are they any other ways to make the text look clear?

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: WPF blurry text

Post by Sandra » Tue Sep 04, 2012 10:02 am

Hello MVUser6,

I inform you that we have added your problem in feature request list with number [TW16016325] to be consdier its inclusion in upcoming versions of WPF. On the other hand, you need know that Blurry text has been a problem in WPF forever as you can see here, Nowadays, .net framework 4.0 we have the TextOptions class.unfortunately, this can only be applied directly to a framework element as explain in next link:
http://stackoverflow.com/questions/4095 ... t-glyphrun.
So, at the moment , the only way we're going to get this to work , is using the "FormattedText.BuildGeometry() trick" suggested in the stackoverflow thread.

I hope will help.

Thank you,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

Re: WPF blurry text

Post by MVUser6 » Tue Sep 04, 2012 11:48 am

hi,

can you post a sample code of writing text in this way?

MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

Re: WPF blurry text

Post by MVUser6 » Tue Sep 04, 2012 2:53 pm

hi,

i found a solution.

in formattedtext constructor there is a flag called TextFormattingMode. if you set it to TextFormattingMode.Display, the text looks like in GDI.
the only way to set this flag is in the constructor. this property is not exposed.

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: WPF blurry text

Post by Sandra » Wed Sep 05, 2012 9:00 am

Hello MVUser6,

I am glad that you can solve your problem. Many thanks for your information, we consider it for treat the feature request.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: WPF blurry text

Post by Narcís » Wed Sep 05, 2012 9:33 am

Hi MVUser6,

Thanks for your feedback. I don't see this makes any difference though. I tried using this code:

Code: Select all

    public MainWindow()
    {
      InitializeComponent();
      InitializeChart();
    }

    private void InitializeChart()
    {
      tChart1.AfterDraw += new Steema.TeeChart.WPF.PaintChartEventHandler(tChart1_AfterDraw);
    }

    void tChart1_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
    {
      g.Font.Size = 8;
      g.Font.Name = "Tahoma";

      g.TextOut(100, 75, "Default WPF text");

      TextOptions.SetTextRenderingMode(tChart1, TextRenderingMode.Grayscale);
      g.TextOut(100, 100, "TextRenderingMode.Grayscale");

      TextOptions.SetTextRenderingMode(tChart1, TextRenderingMode.Aliased);
      g.TextOut(100, 125, "TextRenderingMode.Aliased");

      TextOptions.SetTextRenderingMode(tChart1, TextRenderingMode.ClearType);
      g.TextOut(100, 150, "TextRenderingMode.ClearType");

      FormattedText text = new FormattedText("GDI+ text!", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, g.Font.DrawingFont, g.Font.Size * 3, g.Brush.DrawingBrush);
      g.GDIplusCanvas.DrawText(text , new Point(100, 175));

      FormattedText text2 = new FormattedText("GDI+ text!", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, g.Font.DrawingFont, g.Font.Size * 3, g.Brush.DrawingBrush, new NumberSubstitution(), TextFormattingMode.Display);
      g.GDIplusCanvas.DrawText(text2, new Point(100, 200));
    }
Which produce this chart:
WPFText.png
WPFText.png (22.29 KiB) Viewed 12929 times
I'm not able to see any difference between the two bottom text lines. Do you see any difference on it? Are you doing any modifications on the code?

Thanks in advance.
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

MVUser6
Newbie
Newbie
Posts: 30
Joined: Wed Jul 11, 2012 12:00 am

Re: WPF blurry text

Post by MVUser6 » Tue Nov 06, 2012 8:38 am

hi,
try this one:

private void TChart_AfterDraw(object sender, Steema.TeeChart.WPF.Drawing.Graphics3D g)
{
g.Font.Size = 10.6;
g.Font.Name = "Tahoma";

g.TextOut(100, 75, "Default WPF text");

TextOptions.SetTextRenderingMode(tchart1, TextRenderingMode.Grayscale);
g.TextOut(100, 100, "TextRenderingMode.Grayscale");

TextOptions.SetTextRenderingMode(tchart1, TextRenderingMode.Aliased);
g.TextOut(100, 125, "TextRenderingMode.Aliased");

TextOptions.SetTextRenderingMode(tchart1, TextRenderingMode.ClearType);
g.TextOut(100, 150, "TextRenderingMode.ClearType");


FormattedText text = new FormattedText("GDI+ text!", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, tchart1.Graphics3D.Font.DrawingFont, g.Font.Size, g.Brush.DrawingBrush);
tchart1.Graphics3D.GDIplusCanvas.DrawText(text, new Point(100, 175));

FormattedText text2 = new FormattedText("GDI+ text!", System.Globalization.CultureInfo.CurrentCulture, System.Windows.FlowDirection.LeftToRight, tchart1.Graphics3D.Font.DrawingFont, g.Font.Size, new SolidColorBrush(Color.FromArgb(255, 0, 0, 80)), new NumberSubstitution(), TextFormattingMode.Display);
tchart1.Graphics3D.GDIplusCanvas.DrawText(text2, new Point(100, 200));
}


now you will notice :)

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: WPF blurry text

Post by Sandra » Tue Nov 13, 2012 2:24 pm

Hello MVUser6,

Sorry for the delay. I have tested your code and I have gotten next image:
BlurryText.jpg
BlurryText.jpg (27.71 KiB) Viewed 12863 times
Do you get the same result as us? If you have the same results as us, please explain exactly wherewhere is the problem? On the other hand, if the result is different please attached an image with your result, because we can investigate what could be the problem.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply