Force Antialiasing mode for font

SyntaxEditor for Windows Forms Forum

Posted 12 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 12.1.0300
Avatar

Hello,

is it possible to force an antialiasing mode? The OnRender() method only covers the line number margin, OnPaint() is sealed and the paint event is never called.

I have the problem that under Windows XP the "Consolas" font sometimes looks ugly because of the system settings for antialiasing.


Best regards, Tobias Lingemann.

Comments (5)

Answer - Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tobias,

Actually, everything is rendered within the OnRender hierarchy.  That in turn calls into the various SyntaxEditorRenderer methods.  The DrawLineNumberMarginDisplayLine method on that renderer draws line numbers using e.Graphics.DrawString.  But for our own text rendering in the text area, we couldn't use that method due to measuring issues it has.  So we use Windows API to render text in the text area, such as this method:

private static extern void DrawText(IntPtr hdc, string lpStr, int nCount, RECT lpRect, int wFormat); 

 If you can set your anti-alias mode somehow via API, then that should get picked up when we call our API methods.


Actipro Software Support

Posted 12 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Well, all I got so far is that you can set a flag for the font, that will override the system settings for antialiasing.

Unfortunatelly I got two problems. I cannot set those flags within managed code and if I set the font via Win32 Api the SyntaxEditor still uses his own font. So I guess I cannot do it externally.

//font = CreateFont(10, 0, 0, 0, FW_NORMAL, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 
//  NONANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Consolas");
Font f = new System.Drawing.Font("MS Sans Serif", 10, FontStyle.Regular);
var font = f.ToHfont();

Win32.SendMessage(this.Handle, (int)WindowsMessages.WM_SETFONT, font, IntPtr.Zero);

If you could add an option that would force antialiasing, even if they are disabled due to the system settings, that would be great. Because thats what Visual Studio does and most of the modern fonts dont work without antialiasing.

[Modified 12 years ago]


Best regards, Tobias Lingemann.

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tobias,

When we create fonts, we do so with the API FontInfo struct.  I don't really see any way to set hinting on that, and I believe it is using the system setting.

For instance, on our Windows 7 machine it looks like it's using my default ClearType setting as is.  When I forced the line number margin (via e.Graphics.TextRenderingHint) to an anti-alias setting, the text actually looked blurry and not as crisp.


Actipro Software Support

Posted 12 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Avatar

Yeah, Vista and 7 have ClearType enabled by default, but XP hasn't. So I can't use "Consolas" as default font...


Best regards, Tobias Lingemann.

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Tobias,

Per info like this, it seems like even if we used those flags and created the font via a different method, the system still wouldn't render it correctly and it might look even worse than now on fonts like Consolas if the ClearType option was disabled in XP.  Unfortunately I'm not sure we can really do anything here.  You might be better off defaulting to Courier New on XP systems that don't have ClearType on.


Actipro Software Support

The latest build of this product (v24.1.0) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.