Skip to content

Commit

Permalink
Merge pull request cocos2d#13079 from zilongshanren/v3.7.1
Browse files Browse the repository at this point in the history
fix Mac system font crash issue
  • Loading branch information
pandamicro committed Aug 1, 2015
2 parents 3524af1 + a814076 commit f995ed8
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions cocos/platform/mac/CCDevice-mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,18 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0);

CGSize dimensions = CGSizeMake(info->width, info->height);


if(dimensions.width <= 0 && dimensions.height <= 0) {
dimensions.width = realDimensions.width;
dimensions.height = realDimensions.height;
} else if (dimensions.height <= 0) {
dimensions.height = realDimensions.height;
}
if(dimensions.width <= 0.f) {
dimensions.width = realDimensions.width;
}
if (dimensions.height <= 0.f) {
dimensions.height = realDimensions.height;
}

NSInteger POTWide = dimensions.width;
NSInteger POTHigh = MAX(dimensions.height, realDimensions.height);
unsigned char* data;
NSInteger POTWide = dimensions.width;
NSInteger POTHigh = dimensions.height;
unsigned char* data = nullptr;

//Alignment

CGFloat xPadding = 0;
switch (textAlign) {
case NSLeftTextAlignment: xPadding = 0; break;
Expand All @@ -180,13 +178,16 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
default: break;
}

// 1: TOP
// 2: BOTTOM
// 3: CENTER
CGFloat yPadding = (1 == vertFlag || realDimensions.height >= dimensions.height) ? (dimensions.height - realDimensions.height) // align to top
: (2 == vertFlag) ? 0 // align to bottom
: (dimensions.height - realDimensions.height) / 2.0f; // align to center

CGFloat yPadding = 0.f;
switch (vertFlag) {
// align to top
case 1: yPadding = dimensions.height - realDimensions.height; break;
// align to bottom
case 2: yPadding = 0.f; break;
// align to center
case 3: yPadding = (dimensions.height - realDimensions.height) / 2.0f; break;
default: break;
}

NSRect textRect = NSMakeRect(xPadding, POTHigh - dimensions.height + yPadding, realDimensions.width, realDimensions.height);
//Disable antialias
Expand Down

0 comments on commit f995ed8

Please sign in to comment.