diff --git a/bin/resources/themes/default/global.xml b/bin/resources/themes/default/global.xml index 7110b1e3..6e07a917 100644 --- a/bin/resources/themes/default/global.xml +++ b/bin/resources/themes/default/global.xml @@ -2,7 +2,7 @@ - + diff --git a/tool_kits/duilib/Control/CheckBox.h b/tool_kits/duilib/Control/CheckBox.h index d633524e..4710a3d9 100644 --- a/tool_kits/duilib/Control/CheckBox.h +++ b/tool_kits/duilib/Control/CheckBox.h @@ -225,7 +225,7 @@ void CheckBoxTemplate::PaintText(IRenderContext* pRender) std::wstring newTextColor = m_dwSelectedTextColor.empty() ? this->m_textColorMap[kControlStateNormal] : m_dwSelectedTextColor; DWORD dwTextColor = GlobalManager::GetTextColor(newTextColor); DWORD dwDisabledTextColor = GlobalManager::GetTextColor(this->m_textColorMap[kControlStateDisabled]); - pRender->DrawText(rc, this->GetText(), this->IsEnabled() ? dwTextColor : dwDisabledTextColor, this->m_iFont, this->m_uTextStyle); + pRender->DrawText(rc, this->GetText(), this->IsEnabled() ? dwTextColor : dwDisabledTextColor, this->m_sFontId, this->m_uTextStyle); } template diff --git a/tool_kits/duilib/Control/Label.h b/tool_kits/duilib/Control/Label.h index fac6ee50..b3a4b33c 100644 --- a/tool_kits/duilib/Control/Label.h +++ b/tool_kits/duilib/Control/Label.h @@ -56,14 +56,14 @@ public: * @brief »ñÈ¡µ±Ç°×ÖÌå±àºÅ * @return ·µ»Ø×ÖÌå±àºÅ£¬¸Ã±àºÅÔÚ global.xml Öбêʶ */ - int GetFont() const; + std::wstring GetFont() const; /** * @brief ÉèÖõ±Ç°×ÖÌå * @param[in] index ÒªÉèÖõÄ×ÖÌå±àºÅ£¬¸Ã±àºÅ±ØÐëÔÚ global.xml ÖдæÔÚ * @return ÎÞ */ - void SetFont(int index); + void SetFont(const std::wstring& strFontId); /** * @brief »ñÈ¡ÎÄ×ֱ߾à @@ -105,7 +105,7 @@ public: void SetLineLimit(bool bLineLimit); protected: - int m_iFont; + std::wstring m_sFontId; UINT m_uTextStyle; bool m_bSingleLine; bool m_bLineLimit; @@ -119,7 +119,7 @@ protected: template LabelTemplate::LabelTemplate() : - m_iFont(1), + m_sFontId(), m_uTextStyle(DT_LEFT | DT_TOP | DT_END_ELLIPSIS | DT_NOCLIP | DT_SINGLELINE), m_bSingleLine(true), m_bLineLimit(false), @@ -226,7 +226,7 @@ CSize LabelTemplate::EstimateText(CSize szAvailable, bool& bReEstim CSize fixedSize; if (!GetText().empty()) { auto pRender = this->m_pWindow->GetRenderContext(); - UiRect rect = pRender->MeasureText(GetText(), m_iFont, m_uTextStyle, width); + UiRect rect = pRender->MeasureText(GetText(), m_sFontId, m_uTextStyle, width); if (this->GetFixedWidth() == DUI_LENGTH_AUTO) { fixedSize.cx = rect.right - rect.left + m_rcTextPadding.left + m_rcTextPadding.right; } @@ -239,7 +239,7 @@ CSize LabelTemplate::EstimateText(CSize szAvailable, bool& bReEstim int maxWidth = szAvailable.cx - m_rcTextPadding.left - m_rcTextPadding.right; if (estimateWidth > maxWidth) { estimateWidth = maxWidth; - UiRect newRect = pRender->MeasureText(GetText(), m_iFont, m_uTextStyle, estimateWidth); + UiRect newRect = pRender->MeasureText(GetText(), m_sFontId, m_uTextStyle, estimateWidth); estimateHeight = newRect.bottom - newRect.top; } } @@ -288,7 +288,7 @@ void LabelTemplate::SetAttribute(const std::wstring& strName, const else if (strName == _T("singleline")) SetSingleLine(strValue == _T("true")); else if (strName == _T("text")) SetText(strValue); else if (strName == _T("textid")) SetTextId(strValue); - else if (strName == _T("font")) SetFont(_ttoi(strValue.c_str())); + else if (strName == _T("font")) SetFont(strValue); else if (strName == _T("normaltextcolor")) SetStateTextColor(kControlStateNormal, strValue); else if (strName == _T("hottextcolor")) SetStateTextColor(kControlStateHot, strValue); else if (strName == _T("pushedtextcolor")) SetStateTextColor(kControlStatePushed, strValue); @@ -339,14 +339,14 @@ void LabelTemplate::PaintText(IRenderContext* pRender) std::wstring clrColor = GetStateTextColor(kControlStateNormal); if (!clrColor.empty()) { DWORD dwClrColor = GlobalManager::GetTextColor(clrColor); - pRender->DrawText(rc, GetText(), dwClrColor, m_iFont, m_uTextStyle, 255, m_bLineLimit); + pRender->DrawText(rc, GetText(), dwClrColor, m_sFontId, m_uTextStyle, 255, m_bLineLimit); } if (this->m_nHotAlpha > 0) { std::wstring clrColor = GetStateTextColor(kControlStateHot); if (!clrColor.empty()) { DWORD dwClrColor = GlobalManager::GetTextColor(clrColor); - pRender->DrawText(rc, GetText(), dwClrColor, m_iFont, m_uTextStyle, (BYTE)this->m_nHotAlpha, m_bLineLimit); + pRender->DrawText(rc, GetText(), dwClrColor, m_sFontId, m_uTextStyle, (BYTE)this->m_nHotAlpha, m_bLineLimit); } } @@ -354,7 +354,7 @@ void LabelTemplate::PaintText(IRenderContext* pRender) } } - pRender->DrawText(rc, GetText(), dwClrColor, m_iFont, m_uTextStyle, 255, m_bLineLimit); + pRender->DrawText(rc, GetText(), dwClrColor, m_sFontId, m_uTextStyle, 255, m_bLineLimit); } template @@ -387,15 +387,15 @@ void LabelTemplate::SetStateTextColor(ControlStateType stateType, c } template -int LabelTemplate::GetFont() const +std::wstring LabelTemplate::GetFont() const { - return m_iFont; + return m_sFontId; } template -void LabelTemplate::SetFont(int index) +void LabelTemplate::SetFont(const std::wstring& strFontId) { - m_iFont = index; + m_sFontId = strFontId; this->Invalidate(); } diff --git a/tool_kits/duilib/Control/RichEdit.cpp b/tool_kits/duilib/Control/RichEdit.cpp index b30b04aa..c82a859a 100644 --- a/tool_kits/duilib/Control/RichEdit.cpp +++ b/tool_kits/duilib/Control/RichEdit.cpp @@ -1172,7 +1172,7 @@ RichEdit::RichEdit() : m_iCaretPosY(0), m_iCaretWidth(0), m_iCaretHeight(0), - m_iFont(0), + m_sFontId(0), m_iLimitText(0), m_lTwhStyle(ES_MULTILINE), m_textVerAlignType(kVerAlignTop), @@ -1274,16 +1274,16 @@ void RichEdit::SetWordWrap(bool bWordWrap) if( m_pTwh ) m_pTwh->SetWordWrap(bWordWrap); } -int RichEdit::GetFont() +std::wstring RichEdit::GetFont() const { - return m_iFont; + return m_sFontId; } -void RichEdit::SetFont(int index) +void RichEdit::SetFont(const std::wstring& strFontId) { - m_iFont = index; + m_sFontId = strFontId; if( m_pTwh ) { - m_pTwh->SetFont(GlobalManager::GetFont(m_iFont)); + m_pTwh->SetFont(GlobalManager::GetFont(m_sFontId)); } } @@ -2745,7 +2745,7 @@ void RichEdit::SetAttribute(const std::wstring& strName, const std::wstring& str else if (strName == _T("prompttext")) SetPromptText(strValue); else if (strName == _T("prompttextid")) SetPromptTextId(strValue); else if (strName == _T("focusedimage")) SetFocusedImage(strValue); - else if (strName == _T("font")) SetFont(_ttoi(strValue.c_str())); + else if (strName == _T("font")) SetFont(strValue); else if (strName == _T("text")) SetText(strValue.c_str()); else if (strName == _T("textid")) SetTextId(strValue.c_str()); else if (strName == _T("wanttab")) SetWantTab(strValue == _T("true")); @@ -2899,7 +2899,7 @@ void RichEdit::PaintPromptText(IRenderContext* pRender) DWORD dwClrColor = GlobalManager::GetTextColor(m_sPromptColor); UINT dwStyle = DT_NOCLIP; - pRender->DrawText(rc, strPrompt, dwClrColor, m_iFont, dwStyle); + pRender->DrawText(rc, strPrompt, dwClrColor, m_sFontId, dwStyle); } std::wstring RichEdit::GetFocusedImage() @@ -2995,23 +2995,23 @@ void RichEdit::AddLinkColorText(const std::wstring &str, const std::wstring &col GetDefaultCharFormat(cf); SetSelectionCharFormat(cf); } -void RichEdit::AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo, int font) +void RichEdit::AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo, const std::wstring& strFontId) { if (!m_bRich || str.empty() || color.empty()) { ASSERT(FALSE); return; } - int ifont = font >= 0 ? font : m_iFont; + std::string link; std::string text; std::string font_face; StringHelper::UnicodeToMBCS(linkInfo, link); StringHelper::UnicodeToMBCS(str, text); - auto hFont = GlobalManager::GetFont(ifont); + auto hFont = GlobalManager::GetFont(strFontId); if (hFont == NULL) - hFont = GlobalManager::GetFont(m_iFont); + hFont = GlobalManager::GetFont(m_sFontId); if (hFont == NULL) - hFont = GlobalManager::GetFont(0); + hFont = GlobalManager::GetFont(L""); LOGFONT lf; ::GetObject(hFont, sizeof(LOGFONT), &lf); StringHelper::UnicodeToMBCS(lf.lfFaceName, font_face); diff --git a/tool_kits/duilib/Control/RichEdit.h b/tool_kits/duilib/Control/RichEdit.h index 471aa850..da8623b6 100644 --- a/tool_kits/duilib/Control/RichEdit.h +++ b/tool_kits/duilib/Control/RichEdit.h @@ -118,14 +118,14 @@ public: * @brief »ñÈ¡µ±Ç°ÉèÖõÄ×ÖÌåË÷Òý * @return ·µ»Ø×ÖÌåË÷Òý£¨¶ÔÓ¦ global.xml ÖÐ×ÖÌåµÄ˳Ðò£© */ - int GetFont(); + std::wstring GetFont() const; /** * @brief ÉèÖÃ×ÖÌåË÷Òý * @param[in] index ÒªÉèÖõÄ×ÖÌåË÷Òý£¨¶ÔÓ¦ global.xml ÖÐ×ÖÌåµÄ˳Ðò£© * @return ÎÞ */ - void SetFont(int index); + void SetFont(const std::wstring& strFontId); void SetFont(HFONT font); /** * @brief ¸ù¾Ý×ÖÌåÃû³ÆÉèÖÃ×ÖÌå @@ -875,7 +875,7 @@ public: * @param[in] font ×ÖÌåË÷Òý * @return ÎÞ */ - void AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo = L"", int font = -1); + void AddLinkColorTextEx(const std::wstring& str, const std::wstring &color, const std::wstring &linkInfo = L"", const std::wstring& strFontId = L""); /** * @brief Ìí¼ÓÒ»¸ö·¶Î§ÓÃÓÚ hittest ÅжÏÊÇ·ñÊÇÁ´½ÓÐÅÏ¢ @@ -956,7 +956,7 @@ protected: int m_iCaretPosY; int m_iCaretWidth; int m_iCaretHeight; - int m_iFont; + std::wstring m_sFontId; int m_iLimitText; LONG m_lTwhStyle; VerAlignType m_textVerAlignType; diff --git a/tool_kits/duilib/Core/GlobalManager.cpp b/tool_kits/duilib/Core/GlobalManager.cpp index f09a7e45..aad3d4dd 100644 --- a/tool_kits/duilib/Core/GlobalManager.cpp +++ b/tool_kits/duilib/Core/GlobalManager.cpp @@ -14,7 +14,7 @@ CreateControlCallback GlobalManager::m_createControlCallback; GlobalManager::MapStringToImagePtr GlobalManager::m_mImageHash; std::map GlobalManager::m_mapTextColor; std::map GlobalManager::m_mGlobalClass; -std::vector GlobalManager::m_aCustomFonts; +std::map GlobalManager::m_mCustomFonts; short GlobalManager::m_H = 180; short GlobalManager::m_S = 100; @@ -366,8 +366,17 @@ void GlobalManager::RemoveAllImages() m_mImageHash.clear(); } -HFONT GlobalManager::AddFont(const std::wstring& strFontName, int nSize, bool bBold, bool bUnderline, bool bItalic) +HFONT GlobalManager::AddFont(const std::wstring& strFontId, const std::wstring& strFontName, int nSize, bool bBold, bool bUnderline, bool bItalic) { + std::wstring strNewFontId = strFontId; + if (strNewFontId.empty()) + { + strNewFontId = std::to_wstring(m_mCustomFonts.size()); + } + + auto iter = m_mCustomFonts.find(strNewFontId); + ASSERT(iter == m_mCustomFonts.end()); + static bool bOsOverXp = IsWindowsVistaOrGreater(); std::wstring fontName = strFontName; if ( fontName == L"system" ) { @@ -395,23 +404,32 @@ HFONT GlobalManager::AddFont(const std::wstring& strFontName, int nSize, bool bB pFontInfo->bItalic = bItalic; ::ZeroMemory(&pFontInfo->tm, sizeof(pFontInfo->tm)); - m_aCustomFonts.push_back(pFontInfo); + m_mCustomFonts.insert(std::make_pair(strNewFontId, pFontInfo)); return hFont; } -TFontInfo* GlobalManager::GetTFontInfo(std::size_t index) +TFontInfo* GlobalManager::GetTFontInfo(const std::wstring& strFontId) { - ASSERT(index >= 0 || index < m_aCustomFonts.size()); - if (index < 0 && index >= m_aCustomFonts.size()) + if (strFontId.empty()) + { + for (auto it = m_mCustomFonts.begin(); it != m_mCustomFonts.end(); it++) + { + return it->second; + } return NULL; - TFontInfo* pFontInfo = static_cast(m_aCustomFonts[index]); + } + + auto iter = m_mCustomFonts.find(strFontId); + ASSERT(iter != m_mCustomFonts.end()); + + TFontInfo* pFontInfo = static_cast(iter->second); return pFontInfo; } -HFONT GlobalManager::GetFont(std::size_t index) +HFONT GlobalManager::GetFont(const std::wstring& strFontId) { - TFontInfo* pFontInfo = GetTFontInfo(index); + TFontInfo* pFontInfo = GetTFontInfo(strFontId); if (pFontInfo) return pFontInfo->hFont; return nullptr; @@ -419,8 +437,8 @@ HFONT GlobalManager::GetFont(std::size_t index) HFONT GlobalManager::GetFont(const std::wstring& strFontName, int nSize, bool bBold, bool bUnderline, bool bItalic) { - for( auto it = m_aCustomFonts.begin(); it != m_aCustomFonts.end(); it++ ) { - auto pFontInfo = *it; + for (auto it = m_mCustomFonts.begin(); it != m_mCustomFonts.end(); it++) { + auto pFontInfo = it->second; if( pFontInfo->sFontName == strFontName && pFontInfo->iSize == nSize && pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) return pFontInfo->hFont; @@ -428,12 +446,9 @@ HFONT GlobalManager::GetFont(const std::wstring& strFontName, int nSize, bool bB return NULL; } -TFontInfo* GlobalManager::GetFontInfo(std::size_t index, HDC hDcPaint) +TFontInfo* GlobalManager::GetFontInfo(const std::wstring& strFontId, HDC hDcPaint) { - ASSERT(index >= 0 || index < m_aCustomFonts.size()); - if (index < 0 && index >= m_aCustomFonts.size()) - return NULL; - TFontInfo* pFontInfo = static_cast(m_aCustomFonts[index]); + TFontInfo* pFontInfo = GetTFontInfo(strFontId); if( pFontInfo->tm.tmHeight == 0 ) { HFONT hOldFont = (HFONT) ::SelectObject(hDcPaint, pFontInfo->hFont); ::GetTextMetrics(hDcPaint, &pFontInfo->tm); @@ -444,8 +459,8 @@ TFontInfo* GlobalManager::GetFontInfo(std::size_t index, HDC hDcPaint) TFontInfo* GlobalManager::GetFontInfo(HFONT hFont, HDC hDcPaint) { - for( auto it = m_aCustomFonts.begin(); it != m_aCustomFonts.end(); it++ ) { - auto pFontInfo = *it; + for( auto it = m_mCustomFonts.begin(); it != m_mCustomFonts.end(); it++ ) { + auto pFontInfo = it->second; if( pFontInfo->hFont == hFont ) { if( pFontInfo->tm.tmHeight == 0 ) { HFONT hOldFont = (HFONT) ::SelectObject(hDcPaint, pFontInfo->hFont); @@ -462,8 +477,8 @@ TFontInfo* GlobalManager::GetFontInfo(HFONT hFont, HDC hDcPaint) bool GlobalManager::FindFont(HFONT hFont) { - for( auto it = m_aCustomFonts.begin(); it != m_aCustomFonts.end(); it++ ) { - auto pFontInfo = *it; + for( auto it = m_mCustomFonts.begin(); it != m_mCustomFonts.end(); it++ ) { + auto pFontInfo = it->second; if( pFontInfo->hFont == hFont ) return true; } @@ -472,8 +487,8 @@ bool GlobalManager::FindFont(HFONT hFont) bool GlobalManager::FindFont(const std::wstring& strFontName, int nSize, bool bBold, bool bUnderline, bool bItalic) { - for( auto it = m_aCustomFonts.begin(); it != m_aCustomFonts.end(); it++ ) { - auto pFontInfo = *it; + for (auto it = m_mCustomFonts.begin(); it != m_mCustomFonts.end(); it++) { + auto pFontInfo = it->second; if( pFontInfo->sFontName == strFontName && pFontInfo->iSize == nSize && pFontInfo->bBold == bBold && pFontInfo->bUnderline == bUnderline && pFontInfo->bItalic == bItalic) return true; @@ -481,24 +496,28 @@ bool GlobalManager::FindFont(const std::wstring& strFontName, int nSize, bool bB return false; } -bool GlobalManager::RemoveFontAt(std::size_t index) +bool GlobalManager::RemoveFontAt(const std::wstring& strFontId) { - if( index < 0 || index >= m_aCustomFonts.size() ) return false; - TFontInfo* pFontInfo = static_cast(m_aCustomFonts[index]); + auto iter = m_mCustomFonts.find(strFontId); + if (iter == m_mCustomFonts.end()) return false; + + TFontInfo* pFontInfo = static_cast(iter->second); ::DeleteObject(pFontInfo->hFont); delete pFontInfo; - m_aCustomFonts.erase(m_aCustomFonts.begin() + index); + + m_mCustomFonts.erase(iter); + return true; } void GlobalManager::RemoveAllFonts() { - for( auto it = m_aCustomFonts.begin(); it != m_aCustomFonts.end(); it++ ) { - auto pFontInfo = *it; + for (auto it = m_mCustomFonts.begin(); it != m_mCustomFonts.end(); it++) { + auto pFontInfo = it->second; ::DeleteObject(pFontInfo->hFont); delete pFontInfo; } - m_aCustomFonts.clear(); + m_mCustomFonts.clear(); } std::wstring GlobalManager::GetDefaultDisabledTextColor() diff --git a/tool_kits/duilib/Core/GlobalManager.h b/tool_kits/duilib/Core/GlobalManager.h index d60fd2d7..24a8a8c2 100644 --- a/tool_kits/duilib/Core/GlobalManager.h +++ b/tool_kits/duilib/Core/GlobalManager.h @@ -200,6 +200,7 @@ public: /** * @brief Ìí¼ÓÒ»¸ö×ÖÌå + * @param[in] strFontId Ö¸¶¨×ÖÌåµÄID±ê¼Ç * @param[in] strFontName ×ÖÌåÃû³Æ * @param[in] nSize ×ÖÌå´óС * @param[in] bBold ÊÇ·ñ´ÖÌå @@ -207,22 +208,21 @@ public: * @param[in] bItalic ÊÇ·ñÇãб * @return ·µ»Ø×ÖÌåµÄ HFONT ¾ä±ú */ - static HFONT AddFont(const std::wstring& strFontName, int nSize, bool bBold, bool bUnderline, bool bItalic); + static HFONT AddFont(const std::wstring& strFontId, const std::wstring& strFontName, int nSize, bool bBold, bool bUnderline, bool bItalic); /** * @brief ¸ù¾ÝË÷Òý·µ»ØÒ»¸ö×ÖÌåÐÅÏ¢ - * @param[in] index ×ÖÌåË÷Òý + * @param[in] strFontId ×ÖÌåID * @return ·µ»Ø×ÖÌåµÄ TFontInfo ÐÅÏ¢ */ - static TFontInfo* GetTFontInfo(std::size_t index); + static TFontInfo* GetTFontInfo(const std::wstring& strFontId); /** - * @brief ¸ù¾ÝË÷Òý·µ»ØÒ»¸ö×ÖÌå¶ÔÏó - * @param[in] index ×ÖÌåË÷Òý + * @brief ¸ù¾Ý×ÖÌåID·µ»ØÒ»¸ö×ÖÌå¶ÔÏó + * @param[in] strFontId ×ÖÌåID * @return ·µ»Ø×ÖÌåµÄ HFONT ¾ä±ú */ - static HFONT GetFont(std::size_t index); - + static HFONT GetFont(const std::wstring& strFontId); /** * @brief ¸ù¾Ý×ÖÌåÊôÐÔ»ñÈ¡×ÖÌå¶ÔÏó * @param[in] strFontName ×ÖÌåÃû³Æ @@ -236,11 +236,11 @@ public: /** * @brief »ñÈ¡×ÖÌåÐÅÏ¢ - * @param[in] index ×ÖÌåË÷Òý + * @param[in] strFontId ×ÖÌåID * @param[in] hDcPaint É豸¾ä±ú * @return ·µ»Ø×ÖÌåµÄ TFontInfo ÐÅÏ¢ */ - static TFontInfo* GetFontInfo(std::size_t index, HDC hDcPaint); + static TFontInfo* GetFontInfo(const std::wstring& strFontId, HDC hDcPaint); /** * @brief »ñÈ¡×ÖÌåÐÅÏ¢ @@ -274,12 +274,12 @@ public: /** * @brief ¸ù¾Ý×ÖÌåË÷Òýɾ³ý×ÖÌå - * @param[in] index ×ÖÌåË÷Òý + * @param[in] strFontId ×ÖÌåID * @return ·µ»ØÊÇ·ñɾ³ý³É¹¦ * @retval true ɾ³ý³É¹¦ * @retval false ×ÖÌå²»´æÔÚ»òɾ³ýʧ°Ü */ - static bool RemoveFontAt(std::size_t index); + static bool RemoveFontAt(const std::wstring& strFontId); /** * @brief ɾ³ýËùÓÐ×ÖÌå @@ -457,7 +457,7 @@ private: static MapStringToImagePtr m_mImageHash; static std::map m_mapTextColor; static std::map m_mGlobalClass; - static std::vector m_aCustomFonts; + static std::map m_mCustomFonts; static short m_H; static short m_S; diff --git a/tool_kits/duilib/Core/WindowBuilder.cpp b/tool_kits/duilib/Core/WindowBuilder.cpp index ab959dbc..d4a50a17 100644 --- a/tool_kits/duilib/Core/WindowBuilder.cpp +++ b/tool_kits/duilib/Core/WindowBuilder.cpp @@ -193,6 +193,7 @@ Box* WindowBuilder::Create(CreateControlCallback pCallback, Window* pManager, Bo } else if( strClass == _T("Font") ) { nAttributes = node.GetAttributeCount(); + std::wstring strFontId; std::wstring strFontName; int size = 12; bool bold = false; @@ -201,7 +202,11 @@ Box* WindowBuilder::Create(CreateControlCallback pCallback, Window* pManager, Bo for( int i = 0; i < nAttributes; i++ ) { strName = node.GetAttributeName(i); strValue = node.GetAttributeValue(i); - if( strName == _T("name") ) { + if (strName == _T("id")) + { + strFontId = strValue; + } + else if( strName == _T("name") ) { strFontName = strValue; } else if( strName == _T("size") ) { @@ -221,7 +226,7 @@ Box* WindowBuilder::Create(CreateControlCallback pCallback, Window* pManager, Bo } } if( !strFontName.empty() ) { - GlobalManager::AddFont(strFontName, size, bold, underline, italic); + GlobalManager::AddFont(strFontId, strFontName, size, bold, underline, italic); } } else if( strClass == _T("Class") ) { diff --git a/tool_kits/duilib/Render/IRender.h b/tool_kits/duilib/Render/IRender.h index f713a91a..b7c92c44 100644 --- a/tool_kits/duilib/Render/IRender.h +++ b/tool_kits/duilib/Render/IRender.h @@ -204,12 +204,12 @@ public: virtual void DrawLine(const IPen* pen, int x1, int y1, int x2, int y2) = 0; virtual void DrawBezier(const IPen* pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) = 0; virtual void DrawRect(const UiRect& rc, int nSize, DWORD dwPenColor) = 0; - virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, int iFont, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) = 0; + virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) = 0; virtual void DrawEllipse(const UiRect& rc, int nSize, DWORD dwColor) = 0; virtual void FillEllipse(const UiRect& rc, DWORD dwColor) = 0; - virtual UiRect MeasureText(const std::wstring& strText, int iFont, UINT uStyle, int width = DUI_NOSET_VALUE) = 0; + virtual UiRect MeasureText(const std::wstring& strText, const std::wstring& strFontId, UINT uStyle, int width = DUI_NOSET_VALUE) = 0; virtual void DrawPath(const IPath* path, const IPen* pen) = 0; virtual void FillPath(const IPath* path, const IBrush* brush) = 0; diff --git a/tool_kits/duilib/Render/Render.cpp b/tool_kits/duilib/Render/Render.cpp index 5fbf3331..b4d453de 100644 --- a/tool_kits/duilib/Render/Render.cpp +++ b/tool_kits/duilib/Render/Render.cpp @@ -470,13 +470,13 @@ void RenderContext_GdiPlus::DrawRect(const UiRect& rc, int nSize, DWORD dwPenCol graphics.DrawRectangle(&pen, rc.left, rc.top, rc.GetWidth(), rc.GetHeight()); } -void RenderContext_GdiPlus::DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, int iFont, UINT uStyle, BYTE uFade /*= 255*/, bool bLineLimit /*= false*/) +void RenderContext_GdiPlus::DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade /*= 255*/, bool bLineLimit /*= false*/) { ASSERT(::GetObjectType(m_hDC)==OBJ_DC || ::GetObjectType(m_hDC)==OBJ_MEMDC); if( strText.empty() ) return; Gdiplus::Graphics graphics( m_hDC ); - Gdiplus::Font font(m_hDC, GlobalManager::GetFont(iFont)); + Gdiplus::Font font(m_hDC, GlobalManager::GetFont(strFontId)); Gdiplus::RectF rcPaint((Gdiplus::REAL)rc.left, (Gdiplus::REAL)rc.top, (Gdiplus::REAL)(rc.right - rc.left), (Gdiplus::REAL)(rc.bottom - rc.top)); int alpha = dwTextColor >> 24; uFade *= double(alpha) / 255; @@ -519,7 +519,7 @@ void RenderContext_GdiPlus::DrawText(const UiRect& rc, const std::wstring& strTe stringFormat.SetLineAlignment(Gdiplus::StringAlignmentNear); } else if ((uStyle & DT_VCENTER) != 0) { - TFontInfo* fontInfo = GlobalManager::GetTFontInfo(iFont); + TFontInfo* fontInfo = GlobalManager::GetTFontInfo(strFontId); if (fontInfo->sFontName == L"ÐÂËÎÌå") { if (rcPaint.Height >= fontInfo->iSize + 2) { rcPaint.Offset(0, 1); @@ -567,10 +567,10 @@ void RenderContext_GdiPlus::FillPath(const IPath* path, const IBrush* brush) graphics.FillPath(((Brush_Gdiplus*)brush)->GetBrush(), ((Path_Gdiplus*)path)->GetPath()); } -ui::UiRect RenderContext_GdiPlus::MeasureText(const std::wstring& strText, int iFont, UINT uStyle, int width /*= DUI_NOSET_VALUE*/) +ui::UiRect RenderContext_GdiPlus::MeasureText(const std::wstring& strText, const std::wstring& strFontId, UINT uStyle, int width /*= DUI_NOSET_VALUE*/) { Gdiplus::Graphics graphics(m_hDC); - Gdiplus::Font font(m_hDC, GlobalManager::GetFont(iFont)); + Gdiplus::Font font(m_hDC, GlobalManager::GetFont(strFontId)); Gdiplus::RectF bounds; Gdiplus::StringFormat stringFormat = Gdiplus::StringFormat::GenericTypographic(); diff --git a/tool_kits/duilib/Render/Render.h b/tool_kits/duilib/Render/Render.h index 9b8f1041..5d59df6d 100644 --- a/tool_kits/duilib/Render/Render.h +++ b/tool_kits/duilib/Render/Render.h @@ -51,12 +51,12 @@ public: virtual void DrawLine(const IPen* pen, int x1, int y1, int x2, int y2) override; virtual void DrawBezier(const IPen* pen, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4) override; virtual void DrawRect(const UiRect& rc, int nSize, DWORD dwPenColor) override; - virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, int iFont, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) override; + virtual void DrawText(const UiRect& rc, const std::wstring& strText, DWORD dwTextColor, const std::wstring& strFontId, UINT uStyle, BYTE uFade = 255, bool bLineLimit = false) override; virtual void DrawEllipse(const UiRect& rc, int nSize, DWORD dwColor) override; virtual void FillEllipse(const UiRect& rc, DWORD dwColor) override; - virtual UiRect MeasureText(const std::wstring& strText, int iFont, UINT uStyle, int width = DUI_NOSET_VALUE) override; + virtual UiRect MeasureText(const std::wstring& strText, const std::wstring& strFontId, UINT uStyle, int width = DUI_NOSET_VALUE) override; virtual void DrawPath(const IPath* path, const IPen* pen) override; virtual void FillPath(const IPath* path, const IBrush* brush) override;