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

fix missing spaces in RichText #5116

Merged
merged 8 commits into from Aug 16, 2019
28 changes: 15 additions & 13 deletions cocos2d/core/utils/text-utils.js
Expand Up @@ -76,7 +76,7 @@ var textUtils = {
while (allWidth > maxWidth && text.length > 1) {

var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0;
var tmpText = text.substr(fuzzyLen);
var tmpText = text.substring(fuzzyLen);
jareguo marked this conversation as resolved.
Show resolved Hide resolved
var width = allWidth - measureText(tmpText);
var sLine = tmpText;
var pushNum = 0;
Expand All @@ -88,7 +88,7 @@ var textUtils = {
while (width > maxWidth && checkWhile++ < checkCount) {
fuzzyLen *= maxWidth / width;
fuzzyLen = fuzzyLen | 0;
tmpText = text.substr(fuzzyLen);
tmpText = text.substring(fuzzyLen);
width = allWidth - measureText(tmpText);
}

Expand All @@ -103,17 +103,18 @@ var textUtils = {
}

fuzzyLen = fuzzyLen + pushNum;
tmpText = text.substr(fuzzyLen);
tmpText = text.substring(fuzzyLen);
width = allWidth - measureText(tmpText);
}

fuzzyLen -= pushNum;
if (fuzzyLen === 0) {
fuzzyLen = 1;
sLine = sLine.substr(1);
sLine = sLine.substring(1);
}

var sText = text.substr(0, fuzzyLen), result;
// fuzzyLen means end index here
var sText = text.substring(0, fuzzyLen), result;

//symbol in the first
if (this.label_wrapinspection) {
Expand All @@ -122,8 +123,9 @@ var textUtils = {
fuzzyLen -= result ? result[0].length : 0;
if (fuzzyLen === 0) fuzzyLen = 1;

sLine = text.substr(fuzzyLen);
sText = text.substr(0, fuzzyLen);
sLine = text.substring(fuzzyLen);
// fuzzyLen means end index here
sText = text.substring(0, fuzzyLen);
jareguo marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -133,8 +135,9 @@ var textUtils = {
result = this.label_lastEmoji.exec(sText);
if (result && sText !== result[0]) {
fuzzyLen -= result[0].length;
sLine = text.substr(fuzzyLen);
sText = text.substr(0, fuzzyLen);
sLine = text.substring(fuzzyLen);
// fuzzyLen means end index here
sText = text.substring(0, fuzzyLen);
}
}

Expand All @@ -143,8 +146,9 @@ var textUtils = {
result = this.label_lastEnglish.exec(sText);
if (result && sText !== result[0]) {
fuzzyLen -= result[0].length;
sLine = text.substr(fuzzyLen);
sText = text.substr(0, fuzzyLen);
sLine = text.substring(fuzzyLen);
// fuzzyLen means end index here
sText = text.substring(0, fuzzyLen);
}
}

Expand All @@ -153,7 +157,6 @@ var textUtils = {
wrappedWords.push(sText);
}
else {
sText = sText.trim();
jareguo marked this conversation as resolved.
Show resolved Hide resolved
if (sText.length > 0) {
wrappedWords.push(sText);
}
Expand All @@ -166,7 +169,6 @@ var textUtils = {
wrappedWords.push(text);
}
else {
text = text.trim();
if (text.length > 0) {
wrappedWords.push(text);
}
Expand Down