Another Strange Font Rendering Issue RRS feed

  • Question

  • Hi.  A while back I got the solution to a problem with fonts rendering differently on different machines.  Today I found an even stranger problem.  When rendering fonts to a bitmap and comparing the MD5 of the resulting file with what is expected, I noticed that occasionally, they would mismatch.  Upon investigating this further, I found that occasionally, a glyph would be rendered with it's colors inverted.  I put my program (c# console program) into an endless loop of rendering the same thing over and over again and printing whether it passes or fails the render test.  What I noticed was that if I just sit and watch the window, it renders perfectly every time.  If I move around the console window that the program is running on, it will occasionally mess up a render.  I added some debug code to see if some of the properties of the Graphics object changed when it messed up a render, but so far that part looks good.

    My theory is that when I render a glyph (using TextRenderer.DrawText), it uses a Graphics object, which uses some lower level drawing code.  If the window is in the middle of a Paint event, some of the properties may be in a state that affects font rendering.  Is this possible?  Any ideas on how to make font rendering work every time?


    UPDATE: I am running this on a laptop with the desktop extended to an LCD.  I discovered that it only messes up if the window is being moved on the secondary display.

    • Edited by jhofer Friday, August 1, 2008 7:30 PM another discovery
    Friday, August 1, 2008 6:54 PM

All replies

  • I wonder if ClearType font smoothing would affect rendering to a bitmap?  Perhaps the low-level drawing code accidentally refers to the window position at some point, even though it's rendering to a bitmap.  ClearType would generate slightly different color distributions depending on where the text is rendered to an LCD screen.

    Saturday, August 2, 2008 6:02 AM
  • I had a problem with this a little while back that was answered here.  I was seeing the same application render fonts differently one different machines.  The problem was that machines with ClearType enabled were messing it up.  I changed that property from "whatever the system is set to" to a specific value.  I also set a lot of other properties that could vary from system to system.  Since the machines that this will run on do not have dual displays, this probably won't be a problem but still - I would really like to know what is going on.



    Saturday, August 2, 2008 2:42 PM