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;
}
결과 :
렌더링 된 텍스트는 나중에 더 넓은 char 너비를 갖기 때문에 유사합니다. 따라서 이러한 서체/글꼴 사이에 이름 변환 또는 링크가 있거나 첫 번째 글꼴은 비트 맵 글꼴이고 이후 글꼴은 벡터 글꼴입니까?
http://blogs.msdn.com/b/oldnewthing/archive/2012/07/19/10331400.aspx –
@HansPassant : thx. – Jichao