closed #4383: Fixed missing letters if using old LabelTTF and running on

iphone 64bit simulator(device).
This commit is contained in:
James Chen 2014-04-01 14:47:52 +08:00
parent c3334cb4ac
commit 47320e7c7c
1 changed files with 21 additions and 3 deletions

View File

@ -199,6 +199,18 @@ typedef struct
} tImageInfo;
static bool s_isIOS7 = false;
static inline void lazyCheckIOS7()
{
static bool isInited = false;
if (!isInited)
{
s_isIOS7 = [[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending;
isInited = true;
}
}
static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize)
{
NSArray *listItems = [str componentsSeparatedByString: @"\n"];
@ -209,7 +221,6 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize
textRect.height = constrainSize->height > 0 ? constrainSize->height
: 0x7fffffff;
for (NSString *s in listItems)
{
CGSize tmp = [s sizeWithFont:font constrainedToSize:textRect];
@ -222,6 +233,9 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize
dim.height += tmp.height;
}
dim.width = ceilf(dim.width);
dim.height = ceilf(dim.height);
return dim;
}
@ -230,8 +244,12 @@ static CGSize _calculateStringSize(NSString *str, id font, CGSize *constrainSize
#define ALIGN_CENTER 3
#define ALIGN_BOTTOM 2
static bool _initWithString(const char * text, cocos2d::Device::TextAlign align, const char * fontName, int size, tImageInfo* info)
{
// lazy check whether it is iOS7 device
lazyCheckIOS7();
bool bRet = false;
do
{
@ -376,7 +394,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
{
CGContextSetTextDrawingMode(context, kCGTextStroke);
if([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
if(s_isIOS7)
{
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.alignment = nsAlign;
@ -412,7 +430,7 @@ static bool _initWithString(const char * text, cocos2d::Device::TextAlign align,
// actually draw the text in the context
[str drawInRect: rect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:nsAlign];
CGContextEndTransparencyLayer(context);
// pop the context