mirror of https://github.com/axmolengine/axmol.git
Fixed system font can't display the proper text when the text contains '&' on win32.
This commit is contained in:
parent
7baf84c232
commit
05db3bfd72
|
@ -246,6 +246,7 @@ public:
|
||||||
{
|
{
|
||||||
int nRet = 0;
|
int nRet = 0;
|
||||||
wchar_t * pwszBuffer = 0;
|
wchar_t * pwszBuffer = 0;
|
||||||
|
wchar_t* fixedText = nullptr;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
CC_BREAK_IF(! pszText);
|
CC_BREAK_IF(! pszText);
|
||||||
|
@ -276,7 +277,37 @@ public:
|
||||||
memset(pwszBuffer, 0, sizeof(wchar_t)*nBufLen);
|
memset(pwszBuffer, 0, sizeof(wchar_t)*nBufLen);
|
||||||
nLen = MultiByteToWideChar(CP_UTF8, 0, pszText, nLen, pwszBuffer, nBufLen);
|
nLen = MultiByteToWideChar(CP_UTF8, 0, pszText, nLen, pwszBuffer, nBufLen);
|
||||||
|
|
||||||
SIZE newSize = sizeWithText(pwszBuffer, nLen, dwFmt, tSize.cx);
|
if (strchr(pszText, '&'))
|
||||||
|
{
|
||||||
|
fixedText = new wchar_t[nLen * 2 + 1];
|
||||||
|
int fixedIndex = 0;
|
||||||
|
for (int index = 0; index < nLen; ++index)
|
||||||
|
{
|
||||||
|
if (pwszBuffer[index] == '&')
|
||||||
|
{
|
||||||
|
fixedText[fixedIndex] = '&';
|
||||||
|
fixedText[fixedIndex + 1] = '&';
|
||||||
|
fixedIndex += 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fixedText[fixedIndex] = pwszBuffer[index];
|
||||||
|
fixedIndex += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fixedText[fixedIndex] = '\0';
|
||||||
|
nLen = fixedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
SIZE newSize;
|
||||||
|
if (fixedText)
|
||||||
|
{
|
||||||
|
newSize = sizeWithText(fixedText, nLen, dwFmt, tSize.cx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newSize = sizeWithText(pwszBuffer, nLen, dwFmt, tSize.cx);
|
||||||
|
}
|
||||||
|
|
||||||
RECT rcText = {0};
|
RECT rcText = {0};
|
||||||
// if content width is 0, use text size as content size
|
// if content width is 0, use text size as content size
|
||||||
|
@ -343,13 +374,23 @@ public:
|
||||||
SetTextColor(_DC, RGB(255, 255, 255)); // white color
|
SetTextColor(_DC, RGB(255, 255, 255)); // white color
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
|
if (fixedText)
|
||||||
|
{
|
||||||
|
nRet = DrawTextW(_DC, fixedText, nLen, &rcText, dwFmt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
nRet = DrawTextW(_DC, pwszBuffer, nLen, &rcText, dwFmt);
|
nRet = DrawTextW(_DC, pwszBuffer, nLen, &rcText, dwFmt);
|
||||||
|
}
|
||||||
|
|
||||||
//DrawTextA(_DC, pszText, nLen, &rcText, dwFmt);
|
//DrawTextA(_DC, pszText, nLen, &rcText, dwFmt);
|
||||||
|
|
||||||
SelectObject(_DC, hOldBmp);
|
SelectObject(_DC, hOldBmp);
|
||||||
SelectObject(_DC, hOldFont);
|
SelectObject(_DC, hOldFont);
|
||||||
} while (0);
|
} while (0);
|
||||||
CC_SAFE_DELETE_ARRAY(pwszBuffer);
|
CC_SAFE_DELETE_ARRAY(pwszBuffer);
|
||||||
|
delete[] fixedText;
|
||||||
|
|
||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1537,11 +1537,7 @@ TTFFontShadowAndStroke::TTFFontShadowAndStroke()
|
||||||
strokeShaodwTextDef._fontFillColor = tintColorBlue;
|
strokeShaodwTextDef._fontFillColor = tintColorBlue;
|
||||||
|
|
||||||
// shadow + stroke label
|
// shadow + stroke label
|
||||||
#if CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
|
||||||
auto fontStrokeAndShadow = LabelTTF::createWithFontDefinition("Stroke && Shadow Blue Text", strokeShaodwTextDef);
|
|
||||||
#else
|
|
||||||
auto fontStrokeAndShadow = LabelTTF::createWithFontDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef);
|
auto fontStrokeAndShadow = LabelTTF::createWithFontDefinition("Stroke & Shadow Blue Text", strokeShaodwTextDef);
|
||||||
#endif
|
|
||||||
|
|
||||||
// add label to the scene
|
// add label to the scene
|
||||||
this->addChild(fontStrokeAndShadow);
|
this->addChild(fontStrokeAndShadow);
|
||||||
|
|
Loading…
Reference in New Issue