XML中的Font节点添加id属性,支持font自定义,同时兼容过去的索引方式
This commit is contained in:
parent
e817180f3c
commit
d709e24707
@ -2,7 +2,7 @@
|
||||
<Global>
|
||||
<!--所有字体-->
|
||||
<!--0-->
|
||||
<Font name="system" size="10"/>
|
||||
<Font name="system" size="12"/>
|
||||
<!--1-->
|
||||
<Font name="system" size="12"/>
|
||||
<!--2-->
|
||||
|
@ -225,7 +225,7 @@ void CheckBoxTemplate<InheritType>::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<typename InheritType>
|
||||
|
@ -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<typename InheritType>
|
||||
LabelTemplate<InheritType>::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<InheritType>::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<InheritType>::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<InheritType>::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<InheritType>::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<InheritType>::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<typename InheritType>
|
||||
@ -387,15 +387,15 @@ void LabelTemplate<InheritType>::SetStateTextColor(ControlStateType stateType, c
|
||||
}
|
||||
|
||||
template<typename InheritType>
|
||||
int LabelTemplate<InheritType>::GetFont() const
|
||||
std::wstring LabelTemplate<InheritType>::GetFont() const
|
||||
{
|
||||
return m_iFont;
|
||||
return m_sFontId;
|
||||
}
|
||||
|
||||
template<typename InheritType>
|
||||
void LabelTemplate<InheritType>::SetFont(int index)
|
||||
void LabelTemplate<InheritType>::SetFont(const std::wstring& strFontId)
|
||||
{
|
||||
m_iFont = index;
|
||||
m_sFontId = strFontId;
|
||||
this->Invalidate();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -14,7 +14,7 @@ CreateControlCallback GlobalManager::m_createControlCallback;
|
||||
GlobalManager::MapStringToImagePtr GlobalManager::m_mImageHash;
|
||||
std::map<std::wstring, DWORD> GlobalManager::m_mapTextColor;
|
||||
std::map<std::wstring, std::wstring> GlobalManager::m_mGlobalClass;
|
||||
std::vector<TFontInfo*> GlobalManager::m_aCustomFonts;
|
||||
std::map<std::wstring, TFontInfo*> 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<TFontInfo*>(m_aCustomFonts[index]);
|
||||
}
|
||||
|
||||
auto iter = m_mCustomFonts.find(strFontId);
|
||||
ASSERT(iter != m_mCustomFonts.end());
|
||||
|
||||
TFontInfo* pFontInfo = static_cast<TFontInfo*>(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<TFontInfo*>(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<TFontInfo*>(m_aCustomFonts[index]);
|
||||
auto iter = m_mCustomFonts.find(strFontId);
|
||||
if (iter == m_mCustomFonts.end()) return false;
|
||||
|
||||
TFontInfo* pFontInfo = static_cast<TFontInfo*>(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()
|
||||
|
@ -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<std::wstring, DWORD> m_mapTextColor;
|
||||
static std::map<std::wstring, std::wstring> m_mGlobalClass;
|
||||
static std::vector<TFontInfo*> m_aCustomFonts;
|
||||
static std::map<std::wstring, TFontInfo*> m_mCustomFonts;
|
||||
|
||||
static short m_H;
|
||||
static short m_S;
|
||||
|
@ -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") ) {
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user