81 lines
2.0 KiB
C++
81 lines
2.0 KiB
C++
#include "stdafx.h"
|
|
#ifdef _COUNTRY_ME_
|
|
|
|
#include "KFontManager.h"
|
|
#include <kfile/KStream.h>
|
|
#include <kfile/KFileManager.h>
|
|
#include "SDebug_Util.h"
|
|
|
|
|
|
const char *KFontManager::KDEFAULT_FONT_NAME = "Default";
|
|
const int KFontManager::KDEFAULT_FONT_SIZE = 10;
|
|
|
|
bool KFontManager::Create( LPCTSTR strDefaultFontFace )
|
|
{
|
|
Destroy();
|
|
m_strDefaultFontFace = strDefaultFontFace;
|
|
|
|
AddFont( KDEFAULT_FONT_NAME, strDefaultFontFace );
|
|
return true;
|
|
}
|
|
|
|
|
|
void KFontManager::Destroy()
|
|
{
|
|
m_mapFonts.clear();
|
|
}
|
|
|
|
|
|
int CALLBACK FontEnumerator(ENUMLOGFONT *lpelf, // logical-font data
|
|
NEWTEXTMETRIC *lpntm, // physical-font data
|
|
DWORD FontType, // type of font
|
|
LPARAM lParam // application-defined data
|
|
)
|
|
{
|
|
std::string* pStringFaceName = reinterpret_cast < std::string *>(lParam);
|
|
|
|
*pStringFaceName = lpelf->elfLogFont.lfFaceName;
|
|
return 0;
|
|
}
|
|
|
|
|
|
LPCSTR KFontManager::AddFont( LPCSTR lpszName, LPCSTR lpszTypeFaceName )
|
|
{
|
|
ifontmap itor = m_mapFonts.find( lpszName );
|
|
if ( itor == m_mapFonts.end() )
|
|
{
|
|
LOGFONT logFont;
|
|
ZeroMemory( &logFont, sizeof( logFont ) );
|
|
|
|
logFont.lfCharSet = DEFAULT_CHARSET;
|
|
strcpy_s( logFont.lfFaceName, LF_FACESIZE, lpszTypeFaceName );
|
|
|
|
std::string strFaceName = m_strDefaultFontFace;
|
|
|
|
EnumFontFamiliesEx( GetDC( NULL ), &logFont, (FONTENUMPROC)FontEnumerator, (LPARAM)&strFaceName, 0 );
|
|
|
|
m_mapFonts.insert( fontmap::value_type( lpszName, strFaceName.c_str() ) );
|
|
/// 지역 변수 strFaceName를 리턴하고 있어서 기존 코드를 유기 하기 위해 static을 추가해서 리턴함
|
|
static std::string tempStr;
|
|
tempStr = strFaceName;
|
|
return tempStr.c_str();
|
|
}
|
|
else
|
|
return (itor->second).c_str();
|
|
}
|
|
|
|
|
|
std::string KFontManager::GetFaceName( LPCSTR lpszFontName )
|
|
{
|
|
/*
|
|
ifontmap itor = m_mapFonts.find( lpszFontName );
|
|
if ( itor == m_mapFonts.end() )
|
|
return AddFont( lpszFontName, lpszFontName );
|
|
else
|
|
return (itor->second).c_str();
|
|
return lpszFontName;
|
|
*/
|
|
return ENV().GetString( "default_font", "Tahoma" );
|
|
}
|
|
|
|
#endif |