📄 cfont.cpp
字号:
// cFont.cpp: implementation of the cFont class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "cFont.h"
extern HWND _g_hWnd;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
GLOBALTON(cFont);
cFont::cFont()
{
for(int i=0;i<FONTMAX;i++)
{
m_pFont[i]=NULL;
//KES 030915
m_hFont[i]=NULL;
}
}
cFont::~cFont()
{
Release();
}
void cFont::Release()
{
for(int i=0;i<FONTMAX;i++)
{
SAFE_RELEASE(m_pFont[i]);
//KES 030915
if( m_hFont[i] )
DeleteObject( m_hFont[i] );
}
}
BOOL cFont::CreateFontObject(LOGFONT * pFont, WORD idx)
{
if(idx > FONTMAX || idx < 0) return FALSE;
m_pFont[idx] = g_pExecutive->GetRenderer()->CreateFontObject(pFont,SS3D_FONT);//D3DX_FONT);
//KES 030915
m_hFont[idx] = CreateFontIndirect( pFont );
// Getfont
//tmp
// m_FontDesc[idx].wWidth = 6;
m_FontDesc[idx].wWidth = (unsigned short)pFont->lfWidth;
m_FontDesc[idx].wHeight = (unsigned short)(-pFont->lfHeight);
return TRUE;
}
LONG cFont::GetTextExtent(WORD hFIdx, char * str, LONG strSize)
{
if(hFIdx > FONTMAX || hFIdx < 0) return 0;
WORD wid = m_FontDesc[hFIdx].wWidth;
WORD DBCNT = 0;
WORD SBCNT = 0;
for(int i = 0 ; i < strSize ; i++)
{
if(str[i] & 0x80)
{
DBCNT++;
i++;
}
else
{
SBCNT++;
}
}
LONG TextWidth = SBCNT*wid+DBCNT*2*wid;
return TextWidth;
}
LONG cFont::GetTextExtentEx( WORD hFIdx, char* str, int strLen )
{
// 奔覆眉迄飘甫 荤侩窃..
/*
HDC hdc = GetDC( _g_hWnd );
HFONT OldFont = (HFONT)SelectObject( hdc, m_hFont[hFIdx] );
SIZE size;
GetTextExtentPoint32( hdc, str, strLen, &size );
SelectObject( hdc, OldFont );
ReleaseDC( _g_hWnd, hdc );
return size.cx;
*/
if(hFIdx > FONTMAX || hFIdx < 0) return 0;
WORD wid = m_FontDesc[hFIdx].wWidth;
WORD DBCNT = 0;
WORD SBCNT = 0;
for(int i = 0 ; i < strLen ; i++)
{
if(str[i] & 0x80)
{
DBCNT++;
i++;
}
else
{
SBCNT++;
}
}
LONG TextWidth = SBCNT*wid+DBCNT*2*wid;
return TextWidth;
}
void cFont::RenderFont(WORD wFontIdx, char * text, int size, RECT * pRect, DWORD color)
{
if(wFontIdx>FONTMAX||wFontIdx<0) return ;
if(!m_pFont[wFontIdx])
return ;
//KES啊 荐沥沁澜 040722
pRect->right = pRect->left + GetTextExtent( wFontIdx, text, size ) + GetTextWidth( wFontIdx ) / 4;
pRect->bottom = pRect->top + GetTextHeight( wFontIdx ) + 1; //+1救窍搁 关临捞 救唱柯促.
//KES 040722 眠啊
if( pRect->left > 1024 || pRect->right < 0 || pRect->bottom < 0 || pRect->top > 768 )
return;
if(*text)
{
g_pExecutive->GetGeometry()->RenderFont(m_pFont[wFontIdx],text,size,pRect,color,CHAR_CODE_TYPE_ASCII,0,0);
// g_pExecutive->GetGeometry()->RenderFont(m_pFont[wFontIdx],text,size,pRect,color,CHAR_CODE_TYPE_UNICODE,0,0);
//m_pFont[wFontIdx]->DrawText(text, size, pRect,color, CHAR_CODE_TYPE_ASCII,0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -