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上的字體「終端」和「@Terminal」之間的連接是什麼?
[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)
要使用此兩種字體繪製的Hello World:
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;
}
結果:
呈現的文字是相似的,除了後面有更寬的字符寬度,所以這些字體/字體之間是否有任何命名轉換或鏈接,或者第一個是位圖字體,後面是矢量字體?
http://blogs.msdn.com/b/oldnewthing/archive/2012/07/19/10331400.aspx – 2014-12-02 14:35:09
@HansPassant:thx。 – Jichao 2014-12-03 06:21:33