如何将自己的字体添加到 DirectX?
我想添加新字体并在屏幕上绘制文本。
但是当我使用这种字体绘制文本时,文本字体是Arial。
我不知道原因。
这是我的代码。
请看看并帮助我。
HANDLE hFind;
WIN32_FIND_DATA wfd;
WCHAR szFontPath[MAX_PATH];
int nNum;
swprintf(szFontPath, L"%s\\Fonts\\*.*", m_szAppPath);
hFind = FindFirstFile(szFontPath, &wfd);
if(hFind == INVALID_HANDLE_VALUE)
return;
do
{
if(wfd.cFileName[0] == L'.')
continue;
swprintf(szFontPath, L"%s\\Fonts\\%s", m_szAppPath, wfd.cFileName);
nNum = AddFontResource(szFontPath);
}
while(FindNextFile(hFind, &wfd));
PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
FindClose(hFind);
---------------------- 其他参考功能中------------------------ --------
int nHeight;
LPDIRECT3DSURFACE9 pSurface;
HDC hDC;
m_pDevice = pDevice;
m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface);
pSurface->GetDC(&hDC);
nHeight = -MulDiv( dwSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 );
pSurface->ReleaseDC(hDC);
m_hFont = CreateFont( nHeight, 0, 0, 0, bBold, bItalic, false, false,
HANGUL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
DEFAULT_PITCH/* | FF_DONTCARE*/, L"Helvetica-Condensed-Black-Se");
pSurface->Release();
I want to add new font and draw text on the screen.
But When I draw text by use this font, the text font is Arial.
I don't know the reason.
Here is my code.
Please see and help me.
HANDLE hFind;
WIN32_FIND_DATA wfd;
WCHAR szFontPath[MAX_PATH];
int nNum;
swprintf(szFontPath, L"%s\\Fonts\\*.*", m_szAppPath);
hFind = FindFirstFile(szFontPath, &wfd);
if(hFind == INVALID_HANDLE_VALUE)
return;
do
{
if(wfd.cFileName[0] == L'.')
continue;
swprintf(szFontPath, L"%s\\Fonts\\%s", m_szAppPath, wfd.cFileName);
nNum = AddFontResource(szFontPath);
}
while(FindNextFile(hFind, &wfd));
PostMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
FindClose(hFind);
---------------------- In other reference function--------------------------------
int nHeight;
LPDIRECT3DSURFACE9 pSurface;
HDC hDC;
m_pDevice = pDevice;
m_pDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pSurface);
pSurface->GetDC(&hDC);
nHeight = -MulDiv( dwSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 );
pSurface->ReleaseDC(hDC);
m_hFont = CreateFont( nHeight, 0, 0, 0, bBold, bItalic, false, false,
HANGUL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
DEFAULT_PITCH/* | FF_DONTCARE*/, L"Helvetica-Condensed-Black-Se");
pSurface->Release();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否可以指定字体的路径。您可能需要通过将其复制到 c:\windows\fonts (或 xp 同等版本)来“安装”它
i'm not sure you are allowed to specify a path for your font. you may need to "install" it by copying it to c:\windows\fonts (or the xp equivalent)
好像这个字体不支持HANGUL_CHARSET。尝试使用DEFAULT_CHARSET。
Seems that this font can not support HANGUL_CHARSET. Try to use DEFAULT_CHARSET.