Label:The texture of system font should be cropped if the height of label is not enough to show the entire string on Mac.

This commit is contained in:
WenhaiLin 2015-07-29 16:11:27 +08:00
parent 6de387b3ac
commit 20d445ad1a
1 changed files with 20 additions and 20 deletions

View File

@ -158,21 +158,18 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0); CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0);
CGSize dimensions = CGSizeMake(info->width, info->height); CGSize dimensions = CGSizeMake(info->width, info->height);
if(dimensions.width <= 0.f) {
if(dimensions.width <= 0) {
dimensions.width = realDimensions.width; dimensions.width = realDimensions.width;
} }
if (dimensions.height <= 0.f) {
if (dimensions.height <= 0) {
dimensions.height = realDimensions.height; dimensions.height = realDimensions.height;
} }
NSInteger POTWide = dimensions.width; NSInteger POTWide = dimensions.width;
NSInteger POTHigh = MAX(dimensions.height, realDimensions.height); NSInteger POTHigh = dimensions.height;
unsigned char* data; unsigned char* data = nullptr;
//Alignment
//Alignment
CGFloat xPadding = 0; CGFloat xPadding = 0;
switch (textAlign) { switch (textAlign) {
case NSLeftTextAlignment: xPadding = 0; break; case NSLeftTextAlignment: xPadding = 0; break;
@ -181,13 +178,16 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
default: break; default: break;
} }
// 1: TOP CGFloat yPadding = 0.f;
// 2: BOTTOM switch (vertFlag) {
// 3: CENTER // align to top
CGFloat yPadding = (1 == vertFlag || realDimensions.height >= dimensions.height) ? (dimensions.height - realDimensions.height) // align to top case 1: yPadding = dimensions.height - realDimensions.height; break;
: (2 == vertFlag) ? 0 // align to bottom // align to bottom
: (dimensions.height - realDimensions.height) / 2.0f; // align to center 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); NSRect textRect = NSMakeRect(xPadding, POTHigh - dimensions.height + yPadding, realDimensions.width, realDimensions.height);
//Disable antialias //Disable antialias