Page 1 of 1

WPF blurry text

Posted: Mon Sep 03, 2012 1:39 pm
by 15662946
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?

Re: WPF blurry text

Posted: Tue Sep 04, 2012 10:02 am
by 10050769
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,

Re: WPF blurry text

Posted: Tue Sep 04, 2012 11:48 am
by 15662946
hi,

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

Re: WPF blurry text

Posted: Tue Sep 04, 2012 2:53 pm
by 15662946
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.

Re: WPF blurry text

Posted: Wed Sep 05, 2012 9:00 am
by 10050769
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,

Re: WPF blurry text

Posted: Wed Sep 05, 2012 9:33 am
by narcis
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 12847 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.

Re: WPF blurry text

Posted: Tue Nov 06, 2012 8:38 am
by 15662946
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 :)

Re: WPF blurry text

Posted: Tue Nov 13, 2012 2:24 pm
by 10050769
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 12781 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,