CCImage.mm _calculateStringSize bug

When calculating multiline string height with some fonts I get wrong font heights for
size (width, 0)

Solution was found here:

And here is fixed function:

static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
{
    if (constrainSize->width > 0 && constrainSize->height == 0)
    {
        static UITextView * textView = [[UITextView alloc] init];

        textView.text = str;
        textView.font = font;
        textView.frame = CGRectMake(0.0f, 0.0f, constrainSize->width, CGFLOAT_MAX);
        [textView sizeToFit];
        CGSize dim = CGSizeZero;
        dim.width = constrainSize->width;
        dim.height = textView.frame.size.height;
        return  dim;
    }

    CGSize textRect = CGSizeZero;
    textRect.width = constrainSize->width > 0 ? constrainSize->width
                                              : 0x7fffffff;
    textRect.height = constrainSize->height > 0 ? constrainSize->height
                                              : 0x7fffffff;

    return [str sizeWithFont:font constrainedToSize:textRect lineBreakMode:NSLineBreakMode::NSLineBreakByWordWrapping];
}

It creates one static UITextView and never releases it… but it’s not so big price for right calculations :slight_smile:

Could anyone update sources?

@Igor Gedymin
Thanks.

Why not send a pull request including bug fix and test case for it?