mirror of https://github.com/axmolengine/axmol.git
parent
f3caa09fd6
commit
f3b09563f8
|
@ -263,7 +263,6 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
|||
|
||||
// alignment
|
||||
NSTextAlignment textAlign = FontUtils::_calculateTextAlignment(align);
|
||||
|
||||
NSMutableParagraphStyle *paragraphStyle = FontUtils::_calculateParagraphStyle(enableWrap, overflow);
|
||||
[paragraphStyle setAlignment:textAlign];
|
||||
|
||||
|
@ -279,48 +278,50 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
|||
|
||||
NSSize realDimensions;
|
||||
|
||||
if (overflow == 2) {
|
||||
if (overflow == 2)
|
||||
realDimensions = _calculateRealSizeForString(&stringWithAttributes, font, dimensions, enableWrap);
|
||||
} else {
|
||||
realDimensions = _calculateStringSize(stringWithAttributes, font, &dimensions, enableWrap, overflow);
|
||||
}
|
||||
|
||||
else
|
||||
realDimensions = _calculateStringSize(stringWithAttributes, font, &dimensions, enableWrap, overflow);
|
||||
|
||||
// Mac crashes if the width or height is 0
|
||||
CC_BREAK_IF(realDimensions.width <= 0 || realDimensions.height <= 0);
|
||||
|
||||
|
||||
if(dimensions.width <= 0.f) {
|
||||
if(dimensions.width <= 0.f)
|
||||
dimensions.width = realDimensions.width;
|
||||
}
|
||||
if (dimensions.height <= 0.f) {
|
||||
dimensions.height = realDimensions.height;
|
||||
}
|
||||
|
||||
if (dimensions.height <= 0.f)
|
||||
dimensions.height = realDimensions.height;
|
||||
|
||||
//Alignment
|
||||
CGFloat xPadding = FontUtils::_calculateTextDrawStartWidth(align, realDimensions, dimensions);
|
||||
|
||||
|
||||
CGFloat yPadding = _calculateTextDrawStartHeight(align, realDimensions, dimensions);
|
||||
|
||||
|
||||
NSInteger POTWide = dimensions.width;
|
||||
NSInteger POTHigh = dimensions.height;
|
||||
NSRect textRect = NSMakeRect(xPadding, POTHigh - dimensions.height + yPadding,
|
||||
realDimensions.width, realDimensions.height);
|
||||
|
||||
|
||||
[[NSGraphicsContext currentContext] setShouldAntialias:NO];
|
||||
|
||||
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(POTWide, POTHigh)];
|
||||
[image lockFocus];
|
||||
// patch for mac retina display and lableTTF
|
||||
[[NSAffineTransform transform] set];
|
||||
|
||||
NSBitmapImageRep* offscreenRep = [[[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:POTWide
|
||||
pixelsHigh:POTHigh
|
||||
bitsPerSample:8
|
||||
samplesPerPixel:4
|
||||
hasAlpha:YES
|
||||
isPlanar:NO
|
||||
colorSpaceName:NSDeviceRGBColorSpace
|
||||
bitmapFormat: 0
|
||||
bytesPerRow:4 * POTWide
|
||||
bitsPerPixel:32] autorelease];
|
||||
|
||||
NSGraphicsContext* g = [NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep];
|
||||
[NSGraphicsContext saveGraphicsState];
|
||||
[NSGraphicsContext setCurrentContext:g];
|
||||
[stringWithAttributes drawInRect:textRect];
|
||||
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, POTWide, POTHigh)];
|
||||
[image unlockFocus];
|
||||
|
||||
auto data = (unsigned char*) [bitmap bitmapData]; //Use the same buffer to improve the performance.
|
||||
|
||||
[NSGraphicsContext restoreGraphicsState];
|
||||
|
||||
auto data = (unsigned char*) [offscreenRep bitmapData]; //Use the same buffer to improve the performance.
|
||||
|
||||
NSUInteger textureSize = POTWide * POTHigh * 4;
|
||||
auto dataNew = (unsigned char*)malloc(sizeof(unsigned char) * textureSize);
|
||||
if (dataNew) {
|
||||
|
@ -333,8 +334,6 @@ static bool _initWithString(const char * text, Device::TextAlign align, const ch
|
|||
info->isPremultipliedAlpha = true;
|
||||
ret = true;
|
||||
}
|
||||
[bitmap release];
|
||||
[image release];
|
||||
} while (0);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue