#ifdef _COUNTRY_ME_ #pragma once #include //#include #include "KTextLayout.h" #include "KFontManager.h" std::string utf8_to_multibyte( const std::string& strUTF8 ); std::string multibyte_to_utf8( const std::string& strMultibyte); std::wstring multibyte_to_wide( const std::string& strMultibyte ); std::string wide_to_multibyte( const std::wstring& strWide ); struct KParagraphAttr { std::string strFontName; int nFontSize; DWORD dwColor; bool bShadow; bool bBold; bool bGlow; KParagraphAttr() : strFontName( KFontManager::GetInstance()->GetFaceName( KFontManager::KDEFAULT_FONT_NAME ) ), nFontSize( KFontManager::KDEFAULT_FONT_SIZE ), dwColor( 0xffffff ), bShadow( false ), bBold( false ), bGlow( false ) {} KParagraphAttr( const KParagraphAttr& other ) : strFontName( other.strFontName ), nFontSize( other.nFontSize ), dwColor( other.dwColor ), bShadow( other.bShadow ), bBold( other.bBold ), bGlow( other.bGlow ) {} }; class KTextParagraph { public: 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; template < class T > struct KTextAttr; struct KTextAttrBase { enum TEXT_ATTRIBUTE { TA_FONT = 0, TA_SIZE = 1, TA_FCOLOR = 2, TA_BCOLOR = 3, TA_BOLD = 4, TA_INVERSE = 5, TA_STRIKE = 6, TA_SHADOW = 7, TA_OUTLINE = 8, TA_GLOW = 9, TA_UNDERLINE = 10 }; KTextAttrBase( TEXT_ATTRIBUTE type_, int nIndex_ ) : type( type_ ), nIndex( nIndex_ ) {} template const T& GetAttr() { return static_cast < KTextAttr < T > *> ( this )->attr; } TEXT_ATTRIBUTE type; int nIndex; }; template < class T > struct KTextAttr : public KTextAttrBase { KTextAttr( TEXT_ATTRIBUTE ta, int nIndex_, T attr_ ) : KTextAttrBase( ta, nIndex_ ), attr( attr_ ) {} T attr; }; typedef std::list < KTextAttrBase* > listAttr; typedef listAttr::iterator ilistAttr; /* KTextParagraph() : m_dwOffsetX( 0 ), m_dwOffsetY( 0 ), m_bLineBreak( false ) { } */ KTextParagraph( const KParagraphAttr& attr ) : m_attr( attr ), m_dwOffsetX( 0 ), m_dwOffsetY( 0 ), m_bLineBreak( false ), m_bEmoticon( false ) {} ~KTextParagraph() { for ( ilistAttr itor = m_listAttr.begin(); itor != m_listAttr.end(); ++itor ) delete *itor; } size_t GetLength() { return m_strText.length(); } DWORD GetOffsetX() { return m_dwOffsetX; } DWORD GetOffsetY() { return m_dwOffsetY; } void SetOffsetX( DWORD dwOffsetX ) { m_dwOffsetX = dwOffsetX; } void SetOffsetY( DWORD dwOffsetY ) { m_dwOffsetY = dwOffsetY; } void SetLineBreak( bool bEnable ) { m_bLineBreak = true; } bool GetLineBreak() { return m_bLineBreak; } const std::string& GetString() { return m_strText; } std::string GetMultibyteString(); void AddString( const std::string& strText ); template < class T > void AddAttribute( KTextAttrBase::TEXT_ATTRIBUTE ta, T attr ) { KTextAttr * pAttr = new KTextAttr ( ta, m_strText.length(), attr ); m_listAttr.push_back( pAttr ); } KParagraphAttr* GetAttr() { return &m_attr; } PangoAttrList* GetPangoAttrList(); PangoAttrList* GetPangoAttrListWithoutColor(); DWORD GetAttrHash(); KParagraphAttr m_attr; listAttr m_listAttr; DWORD m_dwOffsetX; DWORD m_dwOffsetY; bool m_bLineBreak; std::string m_strText; bool m_bEmoticon; }; #endif