Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed #1280: BitmapFontMultiLineAlignment test can't work correctly. #953

Merged
merged 3 commits into from
May 31, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cocos2dx/label_nodes/CCLabelBMFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ static bool isspace_unicode(unsigned short ch)

static void cc_utf8_trim_ws(std::vector<unsigned short>* str)
{
using namespace std;
int len = str->size();

if ( len <= 0 )
Expand Down Expand Up @@ -321,14 +320,14 @@ cc_utf8_get_char (const char * p)
}

/*
* cc_utf8_from_cstr:
* cc_utf16_from_utf8:
* @str_old: pointer to the start of a C string.
*
* Creates a utf8 string from a cstring.
*
* Return value: the newly created utf8 string.
* */
static unsigned short* cc_utf8_from_cstr(const char* str_old)
static unsigned short* cc_utf16_from_utf8(const char* str_old)
{
int len = cc_utf8_strlen(str_old, -1);

Expand All @@ -344,14 +343,15 @@ static unsigned short* cc_utf8_from_cstr(const char* str_old)
return str_new;
}

static std::vector<unsigned short> cc_utf8_vec_from_cstr(const unsigned short* str)
static std::vector<unsigned short> cc_utf16_vec_from_utf16_str(const unsigned short* str)
{
int len = cc_wcslen(str);
std::vector<unsigned short> str_new;

for (int i = 0; i < len; ++i)
{
str_new.push_back(str[i]);

}
return str_new;
}

Expand Down Expand Up @@ -790,7 +790,7 @@ bool CCLabelBMFont::initWithString(const char *theString, const char *fntFile, f
m_tImageOffset = imageOffset;
m_fWidth = width;
CC_SAFE_DELETE_ARRAY(m_sString);
m_sString = cc_utf8_from_cstr(theString);
m_sString = cc_utf16_from_utf8(theString);
m_cOpacity = 255;
m_tColor = ccWHITE;
m_tContentSize = CCSizeZero;
Expand Down Expand Up @@ -943,7 +943,7 @@ void CCLabelBMFont::createFontChars()
tmpSize.height = (float) totalHeight;

this->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize));

}

//LabelBMFont - CCLabelProtocol protocol
Expand All @@ -955,15 +955,14 @@ void CCLabelBMFont::setString(const char *newString)
void CCLabelBMFont::setString(const char *newString, bool fromUpdate)
{
CC_SAFE_DELETE_ARRAY(m_sString);
m_sString = cc_utf8_from_cstr(newString);
m_sString = cc_utf16_from_utf8(newString);
m_sString_initial = newString;

updateString(fromUpdate);
}

void CCLabelBMFont::updateString(bool fromUpdate)
{

if (m_pChildren && m_pChildren->count() != 0)
{
CCObject* child;
Expand Down Expand Up @@ -1076,10 +1075,12 @@ void CCLabelBMFont::setAnchorPoint(const CCPoint& point)
// LabelBMFont - Alignment
void CCLabelBMFont::updateLabel()
{
this->setString(m_sString_initial.c_str(), true);

if (m_fWidth > 0)
{
// Step 1: Make multiline
vector<unsigned short> str_whole = cc_utf8_vec_from_cstr(m_sString);
vector<unsigned short> str_whole = cc_utf16_vec_from_utf16_str(m_sString);
unsigned int stringLength = str_whole.size();
vector<unsigned short> multiline_string;
multiline_string.reserve( stringLength );
Expand Down