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);
CGSize dimensions = CGSizeMake(info->width, info->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 = dimensions.height;
unsigned char* data = nullptr;
if(dimensions.width <= 0) {
dimensions.width = realDimensions.width;
}
if (dimensions.height <= 0) {
dimensions.height = realDimensions.height;
}
NSInteger POTWide = dimensions.width;
NSInteger POTHigh = MAX(dimensions.height, realDimensions.height);
unsigned char* data;
//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