PRB: Cannot Draw Anti-aliased Text on a Windows DIB Section (306198)



The information in this article applies to:

  • Microsoft Windows 95
  • Microsoft Windows 98
  • Microsoft Windows 98 Second Edition
  • Microsoft Windows Millennium Edition
  • Microsoft Windows XP Professional
  • the operating system: Microsoft Windows XP 64-Bit Edition

This article was previously published under Q306198

SYMPTOMS

When an application tries to draw anti-aliased text to a memory device context that has a DIB (device-independent bitmap) section as the drawing surface, the output is drawn without being anti-aliased.

CAUSE

The DIB engine that draws onto DIB sections was not designed to support the device-level font definition that is used by device drivers to render anti-aliased text.

RESOLUTION

To draw anti-aliased text into a memory device context (DC), either create the memory DC by using a device-dependent bitmap (DDB) or ensure that the HFONT that references the TrueType font that is to be anti-aliased is first selected into the real screen DC before it is used anywhere else.

STATUS

This behavior is by design.

MORE INFORMATION

Attempts to draw anti-aliased text onto a memory DC backed by a DIB section on Windows 95, Windows 98, Windows 98 SE, or Windows Millennium can result in aliased text output when anti-aliased text output was expected.

It does not matter whether the request for anti-aliased text originates in the application or is the result of system settings.

Applications can request that a TrueType font be drawn with anti-aliasing of character edges through the use of the ANTIALIASED_QUALITY flag in the LOGFONT structure's lfQuality member. An application's API call to draw text can be anti-aliased without the knowledge of the application when the global system setting for smoothing edges of screen fonts is activated in the Display properties dialog box.

The aliased text is drawn because the DIB Engine that draws onto the DIB section is not designed to support the device driver-level font definition that is used with an anti-aliased TrueType font.

An application can work around this limitation by drawing the text to a DDB-backed memory DC.

Alternatively, the text can be drawn onto the DIB section by the Graphics Device Interface (GDI) rather than by the DIB engine if the HFONT for the anti-aliased TrueType font is first selected into a screen DC. Note that the requirement for the HFONT to be selected into a screen DC is absolute and application-wide. If the HFONT for the TrueType font has ever previously been selected into a DIB section-based memory DC, the anti-aliasing of the text drawn onto the DIB Section will not occur. NOTE: Because of this requirement, this workaround may not be reliable.

The following code demonstrates an easy replacement for the CreateFontIndirect and CreateFont function calls that can be used throughout an application to implement the latter work-around.
HFONT CreateFontIndirectAAFix(LOGFONT *plf)
{
     HDC hScreenIC = CreateIC("DISPLAY", NULL, NULL, NULL);
     HFONT hFont, hOldFont;

     hFont = CreateFontIndirect(plf);
     if (hFont)
     {
          hOldFont = (HFONT)SelectObject(hScreenIC, hFont);
          SelectObject(hScreenIC, hOldFont);
          DeleteDC(hScreenIC);
     }

     return hFont;
}
				

REFERENCES

For additional information regarding anti-aliased text in applications, click the article number below to view the article in the Microsoft Knowledge Base:

197076 INFO: Controlling Anti-aliased Text via the LOGFONT Structure


Modification Type:MinorLast Reviewed:5/17/2006
Keywords:kbDSWGDI2003Swept kbDevContext kbDibSect kbFont kbprb KB306198