Hi all!
I think that I found a bug in CCLabelTTF (cocos2d-x 2.2)
I want create label with blank line in the middle using string like “some text\n\nsometext”. On Win32 all works properly but on iOS (any device) last line disappeared.
This sample code reproduce problem:
string text = "Lorem ipsum dolor sit amet, consectetuer \n\nadipiscing elit. Aenean commodo ligula eget dolor. \n\nAenean massa. Cum sociis natoque \n\npenatibus et magnis dis parturient montes, nascetur ridiculus mus\n\nend of text";
CCLabelTTF * label = CCLabelTTF::create(text.c_str(), "Arial", 14, CCSize(100,0), kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop);
We lost one line for each “”.
I take a look into calculateStringSize method of CCImage.mm and found:
<pre>
calculateStringSize(NSString str, id font, CGSizeconstrainSize)
static CGSize
{
NSArray *listItems = [str componentsSeparatedByString: @“”];
CGSize dim = CGSizeZero;
CGSize textRect = CGSizeZero;
textRect.width = constrainSize~~>width > 0 ? constrainSize~~>width
: 0x7fffffff;
textRect.height = constrainSize~~>height > 0 ? constrainSize~~>height
: 0x7fffffff;
for (NSString *s in listItems)
{
CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect]; // <— Warning
// this method deprecated in iOS 7
if (tmp.width > dim.width)
{
dim.width = tmp.width;
}
dim.height = tmp.height; // <— HERE we have 0 for blank line
// but must have + one line height
}
return dim;
}