diff --git a/cocos/platform/mac/CCDevice-mac.mm b/cocos/platform/mac/CCDevice-mac.mm index 6629adbd1db5..ec5f237e5f47 100644 --- a/cocos/platform/mac/CCDevice-mac.mm +++ b/cocos/platform/mac/CCDevice-mac.mm @@ -158,21 +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.width = realDimensions.width; - } - - 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; @@ -181,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