2014-12-02 4 views
0
HDC hdc = GetDC(NULL); 
    LOGFONT lf = { 0 }; 
    lf.lfCharSet = DEFAULT_CHARSET; 
    auto proc = [](const LOGFONT *lpelfe, const TEXTMETRIC *lpntme, 
     DWORD FontType, LPARAM lParam) { 
     s_faceNames_.push_back(lpelfe->lfFaceName); 
     return 1; 
    }; 
    EnumFontFamiliesEx(hdc, &lf, proc, NULL, 0); 
    ReleaseDC(NULL, hdc); 

이어서 출력 결과 facenames :Windows의 서체 "터미널"과 "@ 터미널"의 연결은 무엇입니까?

[21:09:16:324] index = 0, facename: Terminal, lfweigt: 400, italic: false fullname:Terminal, charset:255 (simpletest.cpp:71:SimpleTest::testFontEnum) 
[21:09:16:324] index = 1, facename: @Terminal, lfweigt: 400, italic: false fullname:@Terminal, charset:134 (simpletest.cpp:71:SimpleTest::testFontEnum) 

이 두 글꼴 안녕하세요을 그리려면

HFONT CreateFont(const std::wstring& fontName, int fontSize, int* charset = NULL) 
{ 
    LOGFONT lf; 
    memset(&lf, 0, sizeof(lf)); 
    StringCchCopy(lf.lfFaceName, LF_FACESIZE, fontName.c_str()); 
    if (charset) { 
     lf.lfCharSet = *charset; 
    } else { 
     lf.lfCharSet = DEFAULT_CHARSET; 
    } 

    auto proc = [](const LOGFONT *lpelfe, const TEXTMETRIC *lpntme, 
     DWORD FontType, LPARAM lParam) { 
     LPENUMLOGFONTEX fontEx = (LPENUMLOGFONTEX)(lpelfe); 
     PLOGFONT ret = (PLOGFONT)(lParam); 
     *ret = fontEx->elfLogFont; 
     return 0; 
    }; 
    HDC dc = GetDC(NULL); 
    EnumFontFamiliesEx(dc, &lf, proc, (LPARAM)&lf, 0); 
    ReleaseDC(NULL, dc); 
    lf.lfWidth = 0; 
    lf.lfHeight = -std::abs(fontSize); 
    if (charset) { 
     *charset = lf.lfCharSet; 
    } 
    return CreateFontIndirect(&lf); 
} 

WM_PAINT 핸들러 :

case WM_PAINT: 
{ 
    hdc = BeginPaint(hWnd, &ps); 

    WCHAR buff[MAX_PATH] = { 0 }; 
    { 
     int charset = DEFAULT_CHARSET; 
     HFONT hf = CreateFont(L"Terminal", 12, &charset); 
     HFONT hOld = (HFONT)SelectObject(hdc, hf); 
     StringCchPrintf(buff, MAX_PATH, L"hello, world charset: %d", charset); 
     TextOut(hdc, 0, 0, buff, wcslen(buff)); 
     SelectObject(hdc, hOld); 
    } 
    { 
     int charset = DEFAULT_CHARSET; 
     HFONT hf = CreateFont(L"@Terminal", 12, &charset); 
     HFONT hOld = (HFONT)SelectObject(hdc, hf); 
     StringCchPrintf(buff, MAX_PATH, L"hello, world charset: %d", charset); 
     TextOut(hdc, 0, 20, buff, wcslen(buff)); 
     SelectObject(hdc, hOld); 
    } 
    EndPaint(hWnd, &ps); 
    break; 
} 

결과 : terminal_font_render_result

렌더링 된 텍스트는 나중에 더 넓은 char 너비를 갖기 때문에 유사합니다. 따라서 이러한 서체/글꼴 사이에 이름 변환 또는 링크가 있거나 첫 번째 글꼴은 비트 맵 글꼴이고 이후 글꼴은 벡터 글꼴입니까?

+1

http://blogs.msdn.com/b/oldnewthing/archive/2012/07/19/10331400.aspx –

+0

@HansPassant : thx. – Jichao

답변

0
void drawText(HDC hdc, int startx1, const std::wstring& fontName, const std::wstring& text) 
{ 
    int degree = 270; 
    int startx2 = startx1 + 200; 
    int starty = 200; 
    MoveToEx(hdc, startx1, 0, NULL); 
    LineTo(hdc, startx1, 700); 
    MoveToEx(hdc, startx2, 0, NULL); 
    LineTo(hdc, startx2, 700); 

    WCHAR buff[MAX_PATH] = { 0 }; 
    { 
     { 
      int charset = DEFAULT_CHARSET; 
      HFONT hf = CreateFont(fontName.c_str(), 12, degree, &charset); 
      FASSERT(hf); 
      HFONT hOld = (HFONT)SelectObject(hdc, hf); 
      auto str1 = fontName + text; 
      StringCchPrintf(buff, MAX_PATH, str1.c_str(), charset); 
      TextOut(hdc, startx1, starty, buff, wcslen(buff)); 
      SelectObject(hdc, hOld); 
     } 
      { 
       std::wstring fontName2 = L"@" + fontName; 
       int charset = DEFAULT_CHARSET; 
       HFONT hf = CreateFont(fontName2.c_str(), 12, degree, &charset); 
       FASSERT(hf); 
       auto str2 = fontName2.c_str() + text; 
       HFONT hOld = (HFONT)SelectObject(hdc, hf); 
       StringCchPrintf(buff, MAX_PATH, str2.c_str(), charset); 
       TextOut(hdc, startx2, starty, buff, wcslen(buff)); 
       SelectObject(hdc, hOld); 
      } 
    } 
} 

WM_PAINT 핸들러 :

case WM_PAINT: 
{ 
    hdc = BeginPaint(hWnd, &ps); 
    drawText(hdc, 200, L"SimSun", L"我跟你什么仇什么怨?"); 
    drawText(hdc, 600, L"Termainl", L"What hatred, what emity"); 
    EndPaint(hWnd, &ps); 
    break; 
} 

결과 : enter image description here

결론 @simsun 수직 텍스트를 지원 수직 폰트이고; simsun은 세로 텍스트를 지원하지 않는 세로 글꼴이 아닙니다.

그래서 simsun은 단지 텍스트를 회전시키고 변환을하지 않으며 @simsun이 수행했습니다.