Page 1 of 1

Font Error

Posted: Tue Jun 05, 2012 4:30 pm
by 15661493
When my charting application encounters problems it records the call stack in a file and eventually sends that error message to me. Periodically I see errors coming through from customers that are the result of setting a font. It seems that, say, the Verdan font on one machine is not exactly like the Verdana font on another. Here is a sample call stack from the error that I am seeing. If you could trap the error in the code so the control does not blow up if a user sets some font that does not happen to work quite right, I would really appreciate it.

In this case the user's system does not support a Regular style for the Verdana font. The result is that the control either crashes entirely or becomes a window with a big X through it. Trapping the error and/or replacing it with a very generic font if an error occurs would be very useful.

FONT 'VERDANA' DOES NOT SUPPORT STYLE 'REGULAR'.

AT SYSTEM.DRAWING.FONT.CREATENATIVEFONT()
AT SYSTEM.DRAWING.FONT.INITIALIZE(FONTFAMILY FAMILY SINGLE EMSIZE FONTSTYLE STYLE GRAPHICSUNIT UNIT BYTE GDICHARSET BOOLEAN GDIVERTICALFONT)
AT SYSTEM.DRAWING.FONT.INITIALIZE(STRING FAMILYNAME SINGLE EMSIZE FONTSTYLE STYLE GRAPHICSUNIT UNIT BYTE GDICHARSET BOOLEAN GDIVERTICALFONT)
AT SYSTEM.DRAWING.FONT..CTOR(STRING FAMILYNAME SINGLE EMSIZE FONTSTYLE STYLE)
AT STEEMA.TEECHART.DRAWING.CHARTFONT.SETDRAWINGFONT()
AT STEEMA.TEECHART.DRAWING.CHARTFONT.GET_DRAWINGFONT()
AT STEEMA.TEECHART.DRAWING.GRAPHICS3DGDIPLUS.MEASURESTRING(CHARTFONT F STRING TEXT)
AT STEEMA.TEECHART.DRAWING.GRAPHICS3D.TEXTHEIGHT(STRING TEXT)
AT STEEMA.TEECHART.DRAWING.GRAPHICS3D.GET_FONTHEIGHT()
AT STEEMA.TEECHART.TITLE.CALCTITLESIZE(GRAPHICS3D G RECTANGLE RECT)
AT STEEMA.TEECHART.CHART.DRAWTITLEFOOT(RECTANGLE& RECT BOOLEAN CUSTOMONLY)
AT STEEMA.TEECHART.CHART.DRAWTITLESANDLEGEND(GRAPHICS G RECTANGLE& TMP BOOLEAN BEFORESERIES)
AT STEEMA.TEECHART.CHART.INTERNALDRAW(GRAPHICS G BOOLEAN NOTOOLS)
AT STEEMA.TEECHART.CHART.INTERNALDRAW(GRAPHICS G)
AT STEEMA.TEECHART.TCHART.DRAW(GRAPHICS G)
AT STEEMA.TEECHART.TCHART.ONPAINT(PAINTEVENTARGS PE)
AT SYSTEM.WINDOWS.FORMS.CONTROL.PAINTWITHERRORHANDLING(PAINTEVENTARGS E INT16 LAYER)
AT SYSTEM.WINDOWS.FORMS.CONTROL.WMPAINT(MESSAGE& M)
AT SYSTEM.WINDOWS.FORMS.CONTROL.WNDPROC(MESSAGE& M)
AT SYSTEM.WINDOWS.FORMS.CONTROL.CONTROLNATIVEWINDOW.ONMESSAGE(MESSAGE& M)
AT SYSTEM.WINDOWS.FORMS.CONTROL.CONTROLNATIVEWINDOW.WNDPROC(MESSAGE& M)
AT SYSTEM.WINDOWS.FORMS.NATIVEWINDOW.CALLBACK(INTPTR HWND INT32 MSG INTPTR WPARAM INTPTR LPARAM)

Re: Font Error

Posted: Wed Jun 06, 2012 12:25 pm
by 10050769
Hello DaveR,

TeeChart use the FontStyle that use .Net Framework as you can see in next link and default font of TeeChart should work fine and its FontStyles too. But, to solve your problem I suggest you change the default font of Chart when you create your application using next line of code:

Code: Select all

Steema.TeeChart.Texts.DefaultFontName = "Arial";
And if you prefer, you can change the font to form using next line of code:

Code: Select all

this.Font = new Font("Arial", 12);
On the other hand, if you don't like my suggestion, I would be very grateful if you can explain me as you expect TeeChart work, when find problems of compatibility of tipical fonts to be try to treat it for next maitenace releases of TeeChartFor.Net

Thanks,

Re: Font Error

Posted: Thu Jun 07, 2012 1:35 pm
by 15661493
Thank you for your suggestion. I will certainly change that default font. I had seen the TChart.DefaultFonts property, but it was read only. In my code, the first thing I did was set fonts for the title, axes, etc. to Arial. That still did not fix the problem. Hopefully, the Texts setting will work.

I am not sure just which point of the process of creating or drawing the chart is causing this error since it does not happen on my machines. Given that I change fonts to Arial first thing in the Form_Load event, I suspect this fails at the point where the control is being instantiated. I Googled the error and see that it is fairly common across many products. The cause seems to be missing font files or fonts that some other software might have modified. Also, not all fonts support each of the typical styles.

At any rate, some Try-Catch around the ponts where you are setting fonts might be a good thing.

As always, I appreciate your assistance.

Re: Font Error

Posted: Thu Jun 07, 2012 1:49 pm
by 15661493
Here is a quick followup to my other reply. There is a function called IsStyleAvailable that can be used to test for this issue prior to trying to set the font.

Public Sub IsStyleAvailable_Example(ByVal e As PaintEventArgs)

' Create a FontFamily object.
Dim myFontFamily As New FontFamily("Arial")

' Test whether myFontFamily is available in Italic.
If myFontFamily.IsStyleAvailable(FontStyle.Italic) Then

' Create a Font object using myFontFamily.
Dim familyFont As New Font(myFontFamily, 16, FontStyle.Italic)

' Use familyFont to draw text to the screen.
e.Graphics.DrawString(myFontFamily.Name & _
" is available in Italic", familyFont, Brushes.Black, _
New PointF(0, 0))
End If
End Sub

Re: Font Error

Posted: Thu Jun 07, 2012 3:15 pm
by 10050769
Hello DaveR,

Thanks for your information, It will be very helpful for us and other clients. We consider it to as a possible solution to problems we can find with fonts.

Thank you,