开发者

Why are my font edges not smooth when drawn with the DrawText API?

When I draw text on an dc, the text comes out with rough edges, and on the multiple windows that this WindowProc handles, the text between each of them look different, which looks unprofessional. Is there a way to draw it so it comes out with crisp, smooth edges?

    case WM_PAINT:
    {
    GetClientRect(hwnd, &rect);
    hdc = BeginPaint(hwnd, &p开发者_开发知识库s);
    hdcmem = CreateCompatibleDC(hdc);
    BITMAP bm;      
    HBITMAP hbmold =  (HBITMAP)SelectObject(hdcmem, gbutton);
    GetObject(gbutton, sizeof(bm), &bm);
    SetBkMode(hdcmem, TRANSPARENT);
    SetTextColor(hdcmem, RGB(74,88,91));
    HFONT hf = CreateFont(30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Myriad Pro");
    HFONT hfold = (HFONT)SelectObject(hdcmem, hf);
    //the next line works fine, but with rough text edges.
    DrawText(hdcmem, L"Drag a\r\nFile\r\nHere", -1, &rect, DT_CENTER | DT_VCENTER  );
    SelectObject(hdcmem, hfold);

    BitBlt(hdc, 0,0,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
    SelectObject(hdcmem, hbmold);
    DeleteDC(hdcmem);
    EndPaint(hwnd, &ps);
    break;
    }


Myriad Pro is an OpenType font, not supported by GDI. Pick a TrueType font instead.


  1. Specify a nonzero qualify for your font.
  2. Make sure your CreateFont call is succeeding -- if it fails you'll be failing back to the (jagged) SYSTEM font.

General notes about your example code:

  1. You're leaking the HFONT.
  2. You should probably static_cast the HFONT rather than the C style cast.


You probably want to pass ANTIALIASED_QUALITY or CLEARTYPE_QUALITY for the fdwQuality parameter (third to last parameter).


Ensure that ClearType is enabled in Display Settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜