Question

I have a Win32 GUI application that uses GDI havily. It needs to draw text over a bitmap at specified coordinates and later erase it and substitute with the original bitmap.

I proceed as follows:

  • select font (GetStockObject( DEFAULT_GUI_FONT)), brush, other stuff into the device context
  • call GetTextExtentPoint32() to compute the size of the text
  • now having the text starting point I can compute the expected text rectangle and store it
  • call TextOut() for the same device context with the same starting point and the same text

and later restore the bitmap for the store rectangle.

It works fine when ClearType antialiasing is off. But with ClearType on the size returned by GetTextExtentPoint32() is slightly smaller than the size actually occupied by the text when TextOut() is called. So when I later restore the original bitmap some small stripes of the text remain in place and I have artifacts.

Is there any cure to this without disabling ClearType?

Was it helpful?

Solution

You could also try DrawText with DT_CALCRECT to compute the string size. Maybe it works better.

Also you can then write the string with DrawText inside a rectangle with the sizes equal to the one you get with DT_CALCRECT and it will clip the text in case it is a bit larger.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top