当我从 Windows 请求"Miriam"字体时,我得到的是"Arial"字体。这怎么可能,因为字体文件"mriam.ttf"存在于我的系统中?
When I solicit a "Miriam" font from Windows, I get an "Arial" font. How is this possible, as the font file "mriam.ttf" exists in my system?
在下面的代码中,Miriam
字体是在WM_CREATE
中创建的,其姓氏是在静态OUTLINETEXTMETRIC struct
中获取的,由s_potm
指向。然后我在WM_PAINT
中展示了这个结构的成员otmpFamilyName
,我得到Arial
打印在窗口工作区上的字符串,而不是Miriam
。但是没有理由进行这种字体替换,因为字体文件mriam.ttf
存在于Windows 7中。任何解释?
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, UINT, LONG);
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int nCmdShow)
{
WNDCLASSEX wndclassx;
wndclassx.cbSize = sizeof(WNDCLASSEX);
wndclassx.style = CS_HREDRAW | CS_VREDRAW;
wndclassx.lpfnWndProc = WndProc;
wndclassx.cbClsExtra = 0;
wndclassx.cbWndExtra = 0;
wndclassx.hInstance = hInstance;
wndclassx.hIcon = 0;
wndclassx.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclassx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclassx.lpszMenuName = 0;
wndclassx.lpszClassName = L"WndProc";
wndclassx.hIconSm = 0;
if( !RegisterClassEx(&wndclassx) ) return 0;
HWND hWnd = CreateWindow(L"WndProc", 0, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
0, 0, hInstance, 0);
ShowWindow(hWnd, SW_SHOWNORMAL);
UpdateWindow(hWnd);
MSG msg;
while( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// Retorna msg.wParam
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
static OUTLINETEXTMETRIC* s_potm;
switch ( message )
{
case WM_CREATE:
{
HDC hDC;
if( !(hDC = CreateIC(L"Display", nullptr, nullptr, nullptr)) ) return -1;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT));
lf.lfHeight = 20;
lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
wcscpy_s(lf.lfFaceName, LF_FACESIZE, L"Miriam");
HFONT hFont;
if( !(hFont = CreateFontIndirect(&lf)) )
{
DeleteDC(hDC);
return -1;
}
hFont = (HFONT)SelectObject(hDC, hFont);
int ix = GetOutlineTextMetrics(hDC, 0, nullptr);
s_potm = (OUTLINETEXTMETRIC*)new char[ix];
GetOutlineTextMetrics(hDC, ix, s_potm);
DeleteObject(SelectObject(hDC, hFont));
DeleteDC(hDC);
}
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
wchar_t* p = (wchar_t*)((BYTE*)s_potm + (int)s_potm->otmpFamilyName);
TextOut(ps.hdc, 10, 20, p, wcslen(p));
EndPaint(hwnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
编辑 :字体MT Extra
也会发生同样的事情
当您向 Windows 请求字体时,它会尽力匹配您在 LOGFONT 结构中列出的所有条件。某些字段优先于其他字段。您已将大部分值保留为零。
我认为在这种情况下,是lfCharSet
领域让你失望。 零等同于ANSI_CHARSET
,但Miriam看起来不像ANSI字体。
MSDN 文档说lfCharSet
:
此参数在字体映射过程中很重要。要确保结果一致,请指定特定的字符集。如果在 lfFaceName 成员中指定字体名称,请确保 lfCharSet 值与 lfFaceName 中指定的字体的字符集匹配。
相关文章:
- C++模板来检查友元函数的存在
- 在C++中测量postscript字体宽度
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- g++ 说函数不存在,即使包含正确的标头
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 有了gcc,是否可以链接库,但前提是它存在
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- 如何在Directwrite中获得给定字体的可用OpenType功能
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- C++Builder中的OnClick事件签名存在问题
- 如何正确地将分支添加到已存在的树中
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 如何检查QList中是否存在值
- 根据某个函数是否存在启用模板
- 当我从 Windows 请求"Miriam"字体时,我得到的是"Arial"字体。这怎么可能,因为字体文件"mriam.ttf"存在于我的系统中?
- 为什么基于不存在的FontFamily创建字体有效