Skip to content

Commit

Permalink
Label:The texture of system font should be cropped if the height of l…
Browse files Browse the repository at this point in the history
…abel is not enough to show the entire string on Mac.
  • Loading branch information
WenhaiLin committed Jul 29, 2015
1 parent 6de387b commit 20d445a
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions cocos/platform/mac/CCDevice-mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 20d445a

Please sign in to comment.