Files
2026-06-01 12:46:52 +02:00

345 lines
9.2 KiB
C++

#ifndef __KTEXTRENDER__H
#define __KTEXTRENDER__H
#include "KRenderObject.h"
#include <toolkit/khash.h>
#include "KSmartPtr.h"
#ifdef _COUNTRY_ME_
#include "KTextEmoticonRender.h"
#include "Localization/MiddleEast.h"
class KTextParser;
#endif
DECL_SPTR(K3DTexture)
class KSpritePrimitive; // 2011.03.23 - servantes
class KTextRender
{
public:
static const char *KDEFAULT_FONT_NAME;
/// 2010.11.05 KDEFAULT_FONT_NAME과 키값은 틀리지만 데이타가 중복되기는 하나, 데이타를 서로 공유해서
/// 쓰도록 하면 수정할게 많아 지기 때문에 같은 데이타가 중복되도록 한다.(부하는 별로 안 될것 같아서,)
/// 키값 "font_default" 추가됨 - prodongi
static const char *KDEFAULT_FONT_NAME2;
static const int KDEFAULT_FONT_SIZE;
static const char *KDEFAULT_FONT_01;
static const char *KDEFAULT_FONT_02;
static const char *KDEFAULT_FONT_03; // 2010.08.26 - prodongi
#ifdef _COUNTRY_ME_
friend KTextParser;
KTextRender( KTextParagraph* pString, DWORD dwWidth, DWORD dwHeight, DWORD dwLineGap, DWORD dwAlign, bool bRandomColor=false );
static void InitTextRender(K3DRenderDevice * pDevice,int nCodePage, LPCTSTR lpszFontName );
static PangoLayout* Layout( KTextParagraph* pParagraph, int nWidth = -1 );
static KFontManager s_fontManager;
#else
/// 2011.02.23 isSpriteScroll 추가 - prodongi
KTextRender(LPCSTR lpszText, KColor color, LPCSTR lpszFontName, int nSize,
DWORD & dwWidth, DWORD & dwHeight,DWORD dwAlign, DWORD dwFlag, bool bStaticSize, KColor color_fx, float fZPos=0.0f, bool bRandomColor=false, bool bUseEmoticonFilter = true, bool isSpriteScroll = false );
static void InitTextRender(K3DRenderDevice * pDevice);
#endif
virtual ~KTextRender();
/// 2010.05.06 - prodongi
void modifyEmoticonSize(std::string const& aniName, int width, int height);
/// 2011.01.18 - prodongi
void setSpriteScroll(bool scroll, DWORD type, float v, float margin);
KSpritePrimitive* GetSpritePrimitive() { return m_prSprite; } // 2011.03.23 - servantes
void Clear();
void Render( KViewportObject *viewport, bool isFront = false );
void SetPosition( float fXPos, float fYPos, float nZPos);
void SetVisibility( float vis );
void SetClipRect(const KRect & rcRect);
DWORD GetWidth() {return m_dwWidth; }
DWORD GetHeight() { return m_dwHeight; }
// 이 작업이 이루어 지기 전에는 어떤 작업도 할 수 없다.
/// 모든 작업이 끝났을때
static void DestroyAll();
/// 특정 String의 Rect를 구해준다.
static void GetStringSize(LPCSTR lpszFontName, int nFontSize, BOOL bBold, LPCSTR lpszString, int nStringLen,
DWORD * pStrWidth, DWORD * pStrHeight);
struct StringTableHandler
{
virtual const char* getString( int nId ) = 0;
};
static void SetStringTable( StringTableHandler *pHandler ) { s_pStringTableHandler = pHandler; }
static const char* GetString( int nId ) { if( s_pStringTableHandler ) return s_pStringTableHandler->getString( nId ); return NULL; }
static void AddFont(LPCSTR lpszFontName, int nFontSize );
/*static void*/static bool AddFreeTypeFont( LPCSTR lpszFontName, LPCSTR lpszFontFileName );
static void SetFontHinting( LPCSTR lpszFontName, bool bHinting );
static HDC GetStaticDC() { return m_hDC; };
static int GetFontHeight( int nFontSize );
static void EnableEnglishGrow() { m_bIncreaseEnglishFontSize = true; }
// MIMI 2005/08/16
static const int GetTextSize( const char* szBuf );
static void GetEmoticonFilterText( std::string & strBuf );
//추가
static int CalcCarretPos( const char *szAlias, const wchar_t *wszString, int x,int nFontSize=13, int ft=0 );
static void GetFreeTypeTextWidth( const wchar_t *text, size_t len, LPSIZE lpSize );
static void SetFreeTypeRatio( float fRatio ) { m_fFreeTypeSizeRatio = fRatio; }
static void SetFreeTypeYOffset( int offset ) { m_nFreeTypeYOffset = offset; }
static void SetOSandLocale( bool bIsVista, const char* pLocale )
{
s_bIsOsVista = bIsVista;
s_strLocale = pLocale;
}
//
static void GenerateRandColor();
static unsigned char GetNextRandColor();
static void SetDefaultCodePage( int nDefCodePage )
{
m_nDefaultCodePage = nDefCodePage;
}
static int GetDefaultCodePage()
{
return m_nDefaultCodePage;
}
enum
{
KTFLAG_UNDER = 1,
KTFLAG_STRIKE = 2,
KTFLAG_INVERSE = 4,
KTFLAG_BOLD = 8,
KTFLAG_SHADOW = 16,
KTFLAG_OUTLINE = 32,
KTFLAG_GLOW = 64,
KTFLAG_GLOW2X = 128,
} FONT_FLAG;
enum
{
KTALIGN_LEFT = DT_LEFT,
KTALIGN_RIGHT = DT_RIGHT,
KTALIGN_HCENTER = DT_CENTER,
KTALIGN_VCENTER = DT_VCENTER,
KTALIGN_TOP = DT_TOP,
KTALIGN_BOTTOM = DT_BOTTOM,
} FONT_ALIGN;
protected:
struct TEXT_FONT_INFO
{
bool bIsFreeType;
bool bHinting;
TEXT_FONT_INFO()
{
bIsFreeType = false;
bHinting = false;
}
void SetHinting( bool _bHinting )
{
bHinting = _bHinting;
}
virtual ~TEXT_FONT_INFO()
{
}
};
struct FREETYPE_TEXT_FONT_INFO : public TEXT_FONT_INFO
{
FREETYPE_TEXT_FONT_INFO( const char *szAlias, const char *szFontFileName,bool *returnSuccess=NULL );
virtual ~FREETYPE_TEXT_FONT_INFO()
{
delete [] pFontStream;
}
char *pFontStream;
};
struct WIN32_TEXT_FONT_INFO : public TEXT_FONT_INFO
{
HFONT hDefaultFont;
HFONT hBoldFont;
HFONT hUnderLineFont;
HFONT hStrikeOutFont;
virtual ~WIN32_TEXT_FONT_INFO()
{
//Bound Checker에서 경고 뜸, 확인 요망.
DeleteObject(hDefaultFont);
DeleteObject(hBoldFont);
DeleteObject(hUnderLineFont);
DeleteObject(hStrikeOutFont);
}
static WIN32_TEXT_FONT_INFO * CreateTextFont()
{
return new WIN32_TEXT_FONT_INFO;
}
private:
// Do Not Use For stack object (local)
WIN32_TEXT_FONT_INFO() : hDefaultFont(NULL), hBoldFont(NULL), hUnderLineFont(NULL), hStrikeOutFont(NULL)
{
bIsFreeType = false;
}
};
struct hashPr_font
{
struct Key
{
Key() { m_pStr = NULL; m_bIsDeepCopy = false; m_nFontSize = 0; }
Key( const Key& str )
{
strcpy( m_pStr = new char[strlen(str.m_pStr)+1], str.m_pStr );
m_bIsDeepCopy = true;
m_nFontSize = str.m_nFontSize;
}
Key( const char* pStr, int nFontSize )
{ m_pStr = const_cast< char* >( pStr ); m_nFontSize = nFontSize; m_bIsDeepCopy = false; }
~Key() { if( m_bIsDeepCopy ) delete[] m_pStr; }
char* m_pStr;
int m_nFontSize;
bool m_bIsDeepCopy;
};
static inline unsigned int getindex( const Key &keystr, int nCapacity )
{
unsigned int key;
const char *str = keystr.m_pStr;
for ( key = 0; *str; str++ )
key = key * 32 - key + *str;
return key % nCapacity;
}
static inline bool isequal( const Key &str1, const Key &str2 )
{
if( _stricmp( str1.m_pStr, str2.m_pStr ) != 0 ) return false;
if( str1.m_nFontSize == -1 || str2.m_nFontSize == -1 ) return true;
return ( str1.m_nFontSize == str2.m_nFontSize );
}
static inline bool isless( const Key &str1, const Key &str2 )
{
if( _stricmp( str1.m_pStr, str2.m_pStr ) < 0 ) return true;
if ( str1.m_nFontSize == -1 || str2.m_nFontSize == -1 ) return false;
return str1.m_nFontSize < str2.m_nFontSize;
}
};
static TEXT_FONT_INFO * _FindFont(LPCSTR lpszFontName, int nFontSize);
DWORD m_dwWidth;
DWORD m_dwHeight;
KResSpriteSPtr m_spResSprite;
class KSpritePrimitive* m_prSprite;
KRect m_rcClipRect;
K3DTextureSPtr m_spTexture;
typedef KHash< TEXT_FONT_INFO*, hashPr_font > FontMap;
static struct XFreeType * s_pFreeType;
static K3DRenderDevice * m_pDevice;
static int m_nDefaultCodePage;
static float m_fFreeTypeSizeRatio;
static bool m_bIncreaseEnglishFontSize;
static int m_nFreeTypeYOffset;
static StringTableHandler* s_pStringTableHandler;
static unsigned char s_randColor[1024];
static int s_nColorValue;
// 이미 만든 Font도 공유
static FontMap m_mapFontInfo;
static HDC m_hDC;
static bool s_bIsOsVista;
static std::string s_strLocale;
// MIMI 2005/08/10
class KTextEmoticonRender* m_pEmoticonLayerRender;
void CheckEmoticon( std::string & strText, LPCSTR lpszFontName, int nFontSize, DWORD dwFlag, DWORD & dwWidth, DWORD & dwHeight, bool bStaticSize, float fZPos );
};
class KTextPhrase;
class KDebugRenderer : public KRenderObject
{
public:
enum KDEBUG_RENDERER_ENUM
{
KDRE_HEIGHT = 16,
KDRE_WIDTH = 250,
KDRE_RENDER_LAYER = 2,
};
KDebugRenderer();
~KDebugRenderer()
{
Clear();
}
void Clear();
static KDebugRenderer & GetInstance();
void Render(KViewportObject * pViewport, DWORD flag = KRenderObject::RENDEREFX_NONE, const K3DMatrix * pAttachMat = NULL );
bool AddDebugItem(LPCSTR lpszDebugName, LPCSTR lpszDebugInfo);
bool AddDebugItem(LPCSTR lpszDebugName, double DebugInfo);
bool RemoveDebugItem(LPCSTR lpszDebugName);
bool ModifyDebugItem(LPCSTR lpszDebugName, LPCSTR lpszDebugInfo);
bool ModifyDebugItem(LPCSTR lpszDebugName, double DebugInfo);
struct DEBUG_ITEM
{
std::string sDebugName;
KTextPhrase * pTextPharse;
DEBUG_ITEM()
{
pTextPharse = NULL;
}
void Destroy();
void SetDebugInfo(LPCSTR lpszDebugName, LPCSTR lpszDebugInfo);
void SetPosition(float fXPos, float fYPos, float fZPos);
void Render(KViewportObject * pViewportObject );
};
std::vector<DEBUG_ITEM> m_vtDebugItem;
protected: ;
static KDebugRenderer * s_pDebugRenderer;
int _FindDebugItem(LPCSTR lpszDebugName);
};
#endif