2013-07-19 04:13:41 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 Zynga Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-07-19 04:13:41 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
#include <vector>
|
2013-07-12 05:41:03 +08:00
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "ccUTF8.h"
|
2013-07-19 04:13:41 +08:00
|
|
|
#include "CCLabelTextFormatter.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCLabel.h"
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-01-22 14:57:11 +08:00
|
|
|
bool LabelTextFormatter::multilineText(Label *theLabel)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
2014-03-07 14:58:44 +08:00
|
|
|
//int strLen = theLabel->getStringLength();
|
|
|
|
auto limit = theLabel->_limitShowCount;
|
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
auto strWhole = theLabel->_currentUTF16String;
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
vector<unsigned short> multiline_string;
|
2014-03-07 14:58:44 +08:00
|
|
|
multiline_string.reserve( limit );
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
vector<unsigned short> last_word;
|
2014-03-07 14:58:44 +08:00
|
|
|
last_word.reserve( 25 );
|
2014-01-21 17:55:49 +08:00
|
|
|
|
|
|
|
bool isStartOfLine = false, isStartOfWord = false;
|
|
|
|
float startOfLine = -1, startOfWord = -1;
|
|
|
|
|
|
|
|
int skip = 0;
|
|
|
|
|
|
|
|
int tIndex = 0;
|
2014-01-22 14:57:11 +08:00
|
|
|
float scalsX = theLabel->getScaleX();
|
2014-02-19 20:26:14 +08:00
|
|
|
float lineWidth = theLabel->_maxLineWidth;
|
|
|
|
bool breakLineWithoutSpace = theLabel->_lineBreakWithoutSpaces;
|
|
|
|
Label::LetterInfo* info = nullptr;
|
2014-01-21 17:55:49 +08:00
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
for (int j = 0; j+skip < limit; j++)
|
2014-01-21 17:55:49 +08:00
|
|
|
{
|
2014-02-19 20:26:14 +08:00
|
|
|
info = & theLabel->_lettersInfo.at(j+skip);
|
2014-01-21 17:55:49 +08:00
|
|
|
|
|
|
|
unsigned int justSkipped = 0;
|
|
|
|
|
|
|
|
while (info->def.validDefinition == false)
|
|
|
|
{
|
|
|
|
justSkipped++;
|
|
|
|
tIndex = j+skip+justSkipped;
|
|
|
|
if (strWhole[tIndex-1] == '\n')
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
|
|
|
cc_utf8_trim_ws(&last_word);
|
2014-01-21 17:55:49 +08:00
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
last_word.push_back('\n');
|
|
|
|
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
|
|
|
last_word.clear();
|
2013-09-13 11:46:46 +08:00
|
|
|
isStartOfWord = false;
|
|
|
|
isStartOfLine = false;
|
2013-07-11 02:59:05 +08:00
|
|
|
startOfWord = -1;
|
|
|
|
startOfLine = -1;
|
|
|
|
}
|
2014-03-07 14:58:44 +08:00
|
|
|
if(tIndex < limit)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
2014-02-19 20:26:14 +08:00
|
|
|
info = & theLabel->_lettersInfo.at( tIndex );
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
2014-01-21 17:55:49 +08:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
skip += justSkipped;
|
|
|
|
tIndex = j + skip;
|
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
if (tIndex >= limit)
|
2014-01-21 17:55:49 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
unsigned short character = strWhole[tIndex];
|
|
|
|
|
|
|
|
if (!isStartOfWord)
|
|
|
|
{
|
2014-01-22 14:57:11 +08:00
|
|
|
startOfWord = info->position.x * scalsX;
|
2014-01-21 17:55:49 +08:00
|
|
|
isStartOfWord = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isStartOfLine)
|
|
|
|
{
|
|
|
|
startOfLine = startOfWord;
|
|
|
|
isStartOfLine = true;
|
|
|
|
}
|
2014-02-08 15:05:36 +08:00
|
|
|
|
|
|
|
// 1) Whitespace.
|
|
|
|
// 2) This character is non-CJK, but the last character is CJK
|
2014-02-10 11:21:54 +08:00
|
|
|
bool isspace = isspace_unicode(character);
|
2014-02-10 12:38:32 +08:00
|
|
|
bool isCJK = false;
|
|
|
|
if(!isspace)
|
|
|
|
{
|
|
|
|
isCJK = iscjk_unicode(character);
|
|
|
|
}
|
|
|
|
|
2014-02-10 11:21:54 +08:00
|
|
|
if (isspace ||
|
2014-02-20 10:24:35 +08:00
|
|
|
(!last_word.empty() && iscjk_unicode(last_word.back()) && !isCJK))
|
2014-01-21 17:55:49 +08:00
|
|
|
{
|
2014-02-08 15:05:36 +08:00
|
|
|
// if current character is white space, put it into the current word
|
2014-02-10 11:21:54 +08:00
|
|
|
if (isspace) last_word.push_back(character);
|
2014-01-21 17:55:49 +08:00
|
|
|
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
|
|
|
last_word.clear();
|
|
|
|
isStartOfWord = false;
|
|
|
|
startOfWord = -1;
|
2014-02-08 15:05:36 +08:00
|
|
|
// put the CJK character in the last word
|
|
|
|
// and put the non-CJK(ASCII) character in the current word
|
2014-02-10 11:21:54 +08:00
|
|
|
if (!isspace) last_word.push_back(character);
|
2014-01-21 17:55:49 +08:00
|
|
|
continue;
|
|
|
|
}
|
2014-02-08 15:05:36 +08:00
|
|
|
|
2014-01-22 14:57:11 +08:00
|
|
|
float posRight = (info->position.x + info->contentSize.width) * scalsX;
|
2014-01-21 17:55:49 +08:00
|
|
|
// Out of bounds.
|
2014-01-22 14:57:11 +08:00
|
|
|
if (posRight - startOfLine > lineWidth)
|
2014-01-21 17:55:49 +08:00
|
|
|
{
|
2014-02-10 12:38:32 +08:00
|
|
|
if (!breakLineWithoutSpace && !isCJK)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
2014-02-08 15:18:18 +08:00
|
|
|
last_word.push_back(character);
|
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
int found = cc_utf8_find_last_not_char(multiline_string, ' ');
|
|
|
|
if (found != -1)
|
|
|
|
cc_utf8_trim_ws(&multiline_string);
|
2013-07-11 02:59:05 +08:00
|
|
|
else
|
2014-01-21 17:55:49 +08:00
|
|
|
multiline_string.clear();
|
|
|
|
|
|
|
|
if (multiline_string.size() > 0)
|
|
|
|
multiline_string.push_back('\n');
|
|
|
|
|
|
|
|
isStartOfLine = false;
|
|
|
|
startOfLine = -1;
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-21 17:55:49 +08:00
|
|
|
cc_utf8_trim_ws(&last_word);
|
|
|
|
|
|
|
|
last_word.push_back('\n');
|
2014-02-08 15:05:36 +08:00
|
|
|
|
2014-01-21 17:55:49 +08:00
|
|
|
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
|
|
|
last_word.clear();
|
|
|
|
isStartOfWord = false;
|
|
|
|
isStartOfLine = false;
|
|
|
|
startOfWord = -1;
|
|
|
|
startOfLine = -1;
|
|
|
|
--j;
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
|
|
|
}
|
2014-01-21 17:55:49 +08:00
|
|
|
else
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
2014-01-21 17:55:49 +08:00
|
|
|
// Character is normal.
|
|
|
|
last_word.push_back(character);
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
2013-07-23 02:40:39 +08:00
|
|
|
}
|
2014-01-21 17:55:49 +08:00
|
|
|
|
|
|
|
multiline_string.insert(multiline_string.end(), last_word.begin(), last_word.end());
|
|
|
|
|
|
|
|
size_t size = multiline_string.size();
|
|
|
|
unsigned short* strNew = new unsigned short[size + 1];
|
|
|
|
|
|
|
|
for (size_t j = 0; j < size; ++j)
|
2013-07-23 02:40:39 +08:00
|
|
|
{
|
2014-01-21 17:55:49 +08:00
|
|
|
strNew[j] = multiline_string[j];
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
2014-01-21 17:55:49 +08:00
|
|
|
|
|
|
|
strNew[size] = 0;
|
2014-02-19 20:26:14 +08:00
|
|
|
theLabel->setCurrentString(strNew);
|
2014-01-21 17:55:49 +08:00
|
|
|
|
|
|
|
return true;
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
|
|
|
|
2014-01-22 14:57:11 +08:00
|
|
|
bool LabelTextFormatter::alignText(Label *theLabel)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
int lineNumber = 0;
|
2014-02-19 20:26:14 +08:00
|
|
|
int strLen = cc_wcslen(theLabel->_currentUTF16String);
|
2013-09-13 11:46:46 +08:00
|
|
|
vector<unsigned short> lastLine;
|
2014-02-19 20:26:14 +08:00
|
|
|
auto strWhole = theLabel->_currentUTF16String;
|
2014-01-22 14:57:11 +08:00
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
if (theLabel->_labelWidth > theLabel->_contentSize.width)
|
|
|
|
{
|
|
|
|
theLabel->setContentSize(Size(theLabel->_labelWidth,theLabel->_contentSize.height));
|
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
for (int ctr = 0; ctr <= strLen; ++ctr)
|
2014-01-22 14:57:11 +08:00
|
|
|
{
|
|
|
|
unsigned short currentChar = strWhole[ctr];
|
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
if (currentChar == '\n' || currentChar == 0)
|
|
|
|
{
|
2014-02-19 20:26:14 +08:00
|
|
|
auto lineLength = lastLine.size();
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
// if last line is empty we must just increase lineNumber and work with next line
|
2013-09-13 11:46:46 +08:00
|
|
|
if (lineLength == 0)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
|
|
|
lineNumber++;
|
|
|
|
continue;
|
|
|
|
}
|
2013-12-06 16:32:06 +08:00
|
|
|
int index = static_cast<int>(i + lineLength - 1 + lineNumber);
|
2013-07-11 02:59:05 +08:00
|
|
|
if (index < 0) continue;
|
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
auto info = & theLabel->_lettersInfo.at( index );
|
2013-10-29 20:25:03 +08:00
|
|
|
if(info->def.validDefinition == false)
|
|
|
|
continue;
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
float shift = 0;
|
2014-03-07 14:58:44 +08:00
|
|
|
switch (theLabel->_hAlignment)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
2013-07-27 07:04:21 +08:00
|
|
|
case TextHAlignment::CENTER:
|
2014-02-19 20:26:14 +08:00
|
|
|
{
|
|
|
|
float lineWidth = info->position.x + info->contentSize.width;
|
2014-03-07 14:58:44 +08:00
|
|
|
shift = theLabel->_contentSize.width/2.0f - lineWidth/2.0f;
|
2014-02-19 20:26:14 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-27 07:04:21 +08:00
|
|
|
case TextHAlignment::RIGHT:
|
2014-02-19 20:26:14 +08:00
|
|
|
{
|
|
|
|
float lineWidth = info->position.x + info->contentSize.width;
|
2014-03-07 14:58:44 +08:00
|
|
|
shift = theLabel->_contentSize.width - lineWidth;
|
2014-02-19 20:26:14 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-07-11 02:59:05 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shift != 0)
|
|
|
|
{
|
2013-09-13 11:46:46 +08:00
|
|
|
for (unsigned j = 0; j < lineLength; ++j)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
|
|
|
index = i + j + lineNumber;
|
|
|
|
if (index < 0) continue;
|
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
info = & theLabel->_lettersInfo.at( index );
|
2013-10-29 20:25:03 +08:00
|
|
|
if(info)
|
|
|
|
{
|
2014-01-22 14:57:11 +08:00
|
|
|
info->position.x += shift;
|
2013-10-29 20:25:03 +08:00
|
|
|
}
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
i += lineLength;
|
|
|
|
++lineNumber;
|
2013-07-11 02:59:05 +08:00
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
lastLine.clear();
|
2013-07-11 02:59:05 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-13 11:46:46 +08:00
|
|
|
lastLine.push_back(currentChar);
|
2013-07-11 02:59:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-22 14:57:11 +08:00
|
|
|
bool LabelTextFormatter::createStringSprites(Label *theLabel)
|
2013-07-11 02:59:05 +08:00
|
|
|
{
|
|
|
|
// check for string
|
2014-03-07 14:58:44 +08:00
|
|
|
unsigned int stringLen = theLabel->getStringLength();
|
|
|
|
theLabel->_limitShowCount = 0;
|
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
// no string
|
|
|
|
if (stringLen == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
int longestLine = 0;
|
2014-02-19 20:26:14 +08:00
|
|
|
unsigned int totalHeight = theLabel->_commonLineHeight * theLabel->_currNumLines;
|
|
|
|
int nextFontPositionX = 0;
|
|
|
|
int nextFontPositionY = totalHeight;
|
2014-03-07 14:58:44 +08:00
|
|
|
auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR();
|
|
|
|
|
|
|
|
if (theLabel->_labelHeight > 0)
|
|
|
|
{
|
2014-03-07 15:58:49 +08:00
|
|
|
auto labelHeightPixel = theLabel->_labelHeight * contentScaleFactor;
|
|
|
|
if (totalHeight > labelHeightPixel)
|
2014-03-07 14:58:44 +08:00
|
|
|
{
|
2014-03-07 15:58:49 +08:00
|
|
|
int numLines = labelHeightPixel / theLabel->_commonLineHeight;
|
2014-03-07 14:58:44 +08:00
|
|
|
totalHeight = numLines * theLabel->_commonLineHeight;
|
|
|
|
}
|
|
|
|
switch (theLabel->_vAlignment)
|
|
|
|
{
|
|
|
|
case TextVAlignment::TOP:
|
2014-03-07 15:58:49 +08:00
|
|
|
nextFontPositionY = labelHeightPixel;
|
2014-03-07 14:58:44 +08:00
|
|
|
break;
|
|
|
|
case TextVAlignment::CENTER:
|
2014-03-07 15:58:49 +08:00
|
|
|
nextFontPositionY = (labelHeightPixel + totalHeight) / 2.0f;
|
|
|
|
break;
|
|
|
|
case TextVAlignment::BOTTOM:
|
2014-03-07 18:31:33 +08:00
|
|
|
nextFontPositionY = totalHeight;
|
2014-03-07 14:58:44 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
Rect charRect;
|
|
|
|
int charXOffset = 0;
|
|
|
|
int charYOffset = 0;
|
|
|
|
int charAdvance = 0;
|
2014-01-22 14:57:11 +08:00
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
auto strWhole = theLabel->_currentUTF16String;
|
2014-03-07 14:58:44 +08:00
|
|
|
auto fontAtlas = theLabel->_fontAtlas;
|
2014-01-22 14:57:11 +08:00
|
|
|
FontLetterDefinition tempDefinition;
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector2 letterPosition;
|
2014-02-19 20:26:14 +08:00
|
|
|
const auto& kernings = theLabel->_horizontalKernings;
|
2014-03-24 14:16:27 +08:00
|
|
|
|
|
|
|
float clipTop = 0;
|
|
|
|
float clipBottom = 0;
|
|
|
|
int lineIndex = 0;
|
|
|
|
bool lineStart = true;
|
|
|
|
bool clip = false;
|
|
|
|
if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled)
|
|
|
|
{
|
|
|
|
clip = true;
|
|
|
|
}
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
for (unsigned int i = 0; i < stringLen; i++)
|
|
|
|
{
|
2014-01-22 14:57:11 +08:00
|
|
|
unsigned short c = strWhole[i];
|
|
|
|
if (fontAtlas->getLetterDefinitionForChar(c, tempDefinition))
|
|
|
|
{
|
|
|
|
charXOffset = tempDefinition.offsetX;
|
|
|
|
charYOffset = tempDefinition.offsetY;
|
|
|
|
charAdvance = tempDefinition.xAdvance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
charXOffset = -1;
|
|
|
|
charYOffset = -1;
|
|
|
|
charAdvance = -1;
|
|
|
|
}
|
2014-03-24 14:16:27 +08:00
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
if (c == '\n')
|
|
|
|
{
|
2014-03-24 14:16:27 +08:00
|
|
|
lineIndex++;
|
2013-07-11 02:59:05 +08:00
|
|
|
nextFontPositionX = 0;
|
2014-02-19 20:26:14 +08:00
|
|
|
nextFontPositionY -= theLabel->_commonLineHeight;
|
2013-10-29 20:25:03 +08:00
|
|
|
|
|
|
|
theLabel->recordPlaceholderInfo(i);
|
2014-03-07 15:58:49 +08:00
|
|
|
if(nextFontPositionY < theLabel->_commonLineHeight)
|
2014-03-07 14:58:44 +08:00
|
|
|
break;
|
|
|
|
|
2014-03-24 14:16:27 +08:00
|
|
|
lineStart = true;
|
2014-03-07 14:58:44 +08:00
|
|
|
continue;
|
2013-07-30 04:43:23 +08:00
|
|
|
}
|
2014-03-24 14:16:27 +08:00
|
|
|
else if (clip && tempDefinition.height > 0.0f)
|
|
|
|
{
|
|
|
|
if (lineStart)
|
|
|
|
{
|
|
|
|
if (lineIndex == 0)
|
|
|
|
{
|
|
|
|
clipTop = charYOffset;
|
|
|
|
}
|
|
|
|
lineStart = false;
|
|
|
|
clipBottom = tempDefinition.clipBottom;
|
|
|
|
}
|
|
|
|
else if(tempDefinition.clipBottom < clipBottom)
|
|
|
|
{
|
|
|
|
clipBottom = tempDefinition.clipBottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lineIndex == 0 && charYOffset < clipTop)
|
|
|
|
{
|
|
|
|
clipTop = charYOffset;
|
|
|
|
}
|
|
|
|
}
|
2013-07-11 02:59:05 +08:00
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor;
|
|
|
|
letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor;
|
2013-10-29 20:25:03 +08:00
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
if( theLabel->recordLetterInfo(letterPosition,tempDefinition,i) == false)
|
2013-10-29 20:25:03 +08:00
|
|
|
{
|
|
|
|
log("WARNING: can't find letter definition in font file for letter: %c", c);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-22 14:57:11 +08:00
|
|
|
nextFontPositionX += charAdvance + kernings[i];
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
if (longestLine < nextFontPositionX)
|
|
|
|
{
|
|
|
|
longestLine = nextFontPositionX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-19 20:26:14 +08:00
|
|
|
float lastCharWidth = tempDefinition.width * contentScaleFactor;
|
2014-03-07 14:58:44 +08:00
|
|
|
Size tmpSize;
|
2013-07-11 02:59:05 +08:00
|
|
|
// If the last character processed has an xAdvance which is less that the width of the characters image, then we need
|
|
|
|
// to adjust the width of the string to take this into account, or the character will overlap the end of the bounding
|
|
|
|
// box
|
2014-01-24 14:04:08 +08:00
|
|
|
if(charAdvance < lastCharWidth)
|
|
|
|
{
|
|
|
|
tmpSize.width = longestLine - charAdvance + lastCharWidth;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmpSize.width = longestLine;
|
|
|
|
}
|
2013-07-11 02:59:05 +08:00
|
|
|
|
|
|
|
tmpSize.height = totalHeight;
|
2014-03-24 14:16:27 +08:00
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
if (theLabel->_labelHeight > 0)
|
|
|
|
{
|
|
|
|
tmpSize.height = theLabel->_labelHeight * contentScaleFactor;
|
|
|
|
}
|
2014-03-24 14:16:27 +08:00
|
|
|
|
|
|
|
if (clip)
|
|
|
|
{
|
|
|
|
int clipTotal = (clipTop + clipBottom) / contentScaleFactor;
|
|
|
|
tmpSize.height -= clipTotal * contentScaleFactor;
|
|
|
|
clipBottom /= contentScaleFactor;
|
|
|
|
|
|
|
|
for (int i = 0; i < theLabel->_limitShowCount; i++)
|
|
|
|
{
|
|
|
|
theLabel->_lettersInfo[i].position.y -= clipBottom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-22 14:57:11 +08:00
|
|
|
theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize));
|
2014-03-24 14:16:27 +08:00
|
|
|
|
2013-07-11 02:59:05 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-08 15:05:36 +08:00
|
|
|
NS_CC_END
|