views:

32

answers:

2

I'm writing a C# (ActiveX) plugin for an application that uses SetCompatibleTextRenderingDefault(true) (forces .net 1.1 text rendering style) This setting mangles some of the text I output with Graphics.DrawString() causing it to look slightly smudged and bolded. Unlike individual controls neither the Graphics class nor the BitMap don't have UseCompatibleTextRendering proerties that can be used to override the individual behavior. Short of fiddling around to try and figure out what's special about the places where I'm drawing text that doesn't get mangled is there anything I can do about this?

The app my plugin is for belongs to a third party so simply changing the SetCompatibleTextRenderingDefault call it inflicts one me is not an option.

Edit: The 'special' thing appears to be the color of the background and how it's affecting the anti-aliasing used; so fiddling to fix it by how I setup the rectangles doesn't seem to be an option.

A: 

I'd advise using TextRenderer.DrawText instead of Graphics.DrawString - even with compatible text rendering disabled, it seems to produce crisper, more consistent results.

Bradley Smith
That doesn't seem to help, text rendering is unchanged. I'm getting identical rendering except that I need to pick the colors manually. I'm drawing on two different colored backgrounds. Dark blue and light yellow. Graphics.DrawString picks white and black text for them respectively. The white text has sub-pixel anti-aliasing. The Black text is all or nothing. TextRenderer.DrawText lets me draw the text colors on the opposite backgrounds, but the anti-aliasing is the same (based on text color); except that white text on a yellow background is unreadable.
Dan Neely
DrawString picks a color???
Hans Passant
Nevermind; looking up the call chain (not originally my code); the color is coming from a `Brush`.
Dan Neely
A: 

I found a fix for my problem by changing the TextRenderingHint to SingleBitPerPixelGridFit which is the default when not using compatible text rendering. When it's instead set to true it uses a the ClearType enumeration except that for whatever reason unlike normal cleartype text the results are ugly and extremely hard to read.

textGraphics.TextRenderingHint = 
             System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
Dan Neely