Cocos2d iphone cocos2d 1.0.1,用于解决带有Catalina的iMac 5K上的Mac文本输出问题

Cocos2d iphone cocos2d 1.0.1,用于解决带有Catalina的iMac 5K上的Mac文本输出问题,cocos2d-iphone,Cocos2d Iphone,我已经为mac开发了一个带有CoCoS2D1.0.1的mac应用程序 文本显示(CCLabelTTF)在带有Catalina的iMac 5K上不起作用 Mac pro、iMac和MacBook都没有问题 我认为这个代码是个问题 CCE2D.m: 已定义elif(允许使用MAC操作系统X版本) -(id)initWithString:(NSString*)字符串维度:(CGSize)维度对齐:(CCTextAlignment)对齐属性string:(NSAttributedString*)stri

我已经为mac开发了一个带有CoCoS2D1.0.1的mac应用程序

文本显示(
CCLabelTTF
)在带有Catalina的iMac 5K上不起作用

Mac pro、iMac和MacBook都没有问题

我认为这个代码是个问题

CCE2D.m:

已定义elif(允许使用MAC操作系统X版本) -(id)initWithString:(NSString*)字符串维度:(CGSize)维度对齐:(CCTextAlignment)对齐属性string:(NSAttributedString*)stringWithAttributes { NSAssert(stringWithAttributes,@“无效的stringWithAttributes”)

nsuiger POTWide=ccNextPOT(尺寸.宽度);
NSUPINTEGER POTTHIGH=ccNextPOT(尺寸、高度);
无符号字符*数据;
NSSize realDimensions=[stringWithAttributes size];
//对齐
浮点数=0;
//如果宽度或高度为0,Mac将崩溃
如果(realDimensions.width>0&&realDimensions.height>0){
开关(校准){
案例CCTextAlignmentLeft:xPadding=0;中断;
案例CCTextAlignmentCenter:xPadding=(dimensions.width realdmensions.width)/2.0f;中断;
案例CCTextAlignmentRight:xPadding=dimensions.width-realdmensions.width;break;
默认:中断;
}
//禁用反别名
[[NSGraphicsContext currentContext]setShouldAntialias:否];
NSImage*image=[[NSImage alloc]initWithSize:NSMakeSize(POTWide,POTHigh)];
[图像锁定焦点];
[stringWithAttributes drawAtPoint:NSMakePoint(xPadding,POTHigh dimensions.height)];//在偏移位置绘制
NSBitmapImageRep*位图=[[NSBitmapImageRep alloc]initWithFocusedViewRect:NSMakeRect(0.0f,0.0f,POTWide,POTHigh)];
[图像解锁焦点];
data=(unsigned char*)[bitmap bitmapData];//使用相同的缓冲区来提高性能。
NSUInteger textureSize=POTWide*POTHigh;
对于(int i=0;i噢,是的~~解决了~

固定-ccd.m-

-(id)initWithString:(NSString*)字符串维度:(CGSize)维度对齐:(CCTextAlignment)对齐属性string:(NSAttributedString*)stringWithAttributes { NSAssert(stringWithAttributes,@“无效的stringWithAttributes”)

//获取最接近的二次幂
NSSize POTSize=NSMakeSize(ccNextPOT(尺寸.宽度),ccNextPOT(尺寸.高度));
//获取实际渲染尺寸
NSRect boundingRect=[stringWithAttributes boundingRectWithSize:NSSizeFromCGSize(维度)选项:NSStringDrawingUserLineFragmentOrigin];
//如果宽度或高度为0,Mac将崩溃
如果(POTSize.width==0)
POTSize.width=2;
如果(POTSize.height==0)
POTSize.height=2;
CGSize offset=CGSizeMake(0,POTSize.height-dimensions.height);
//对齐
开关(校准){
案例cctexalignmentleft:中断;
案例CCTextAlignmentCenter:offset.width=(dimensions.width boundingRect.size.width)/2.0f;中断;
案例CCTextAlignmentRight:offset.width=dimensions.width-boundingRect.size.width;break;
默认:中断;
}
CGRect drawArea=CGRectMake(offset.width、offset.height、boundingRect.size.width、boundingRect.size.height);
NSInteger POTWide=POTSize.width;
NSInteger pothhigh=POTSize.height;
NSBitmapImageRep*位图=[[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
像素宽度
pixelsHigh:Pothhigh
位示例:8
样本每像素:4
哈萨法:是的
伊斯普兰:没有
colorSpaceName:NSDeviceRbColorSpace
位图格式:0
bytesPerRow:4*POTWide
比特像素:32]自动释放];
NSGraphicsContext*g=[NSGraphicsContext graphicsContextWithBitmapImageRep:bitmap];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:g];
[stringWithAttributes drawWithRect:drawArea选项:NSStringDrawingUsLineFragmentOrigin];
[NSGraphicsContext restoreGraphicsState];
unsigned char*data=(unsigned char*)[bitmapData];//使用相同的缓冲区来提高性能。
NSUInteger textureSize=POTWide*POTHigh;
无符号字符*dst=(无符号字符*)数据;
对于(int i=0;i'iMacros(Web自动化软件)与“iMac”完全无关,=>当您询问Qt/启动线程时,是否可以删除该标记并确保选择“正确”标记…?,这对于遵循特定标记的用户来说是“恼人的”…如果您不确定,请阅读标记的说明。。。
NSUInteger POTWide = ccNextPOT(dimensions.width);
NSUInteger POTHigh = ccNextPOT(dimensions.height);
unsigned char*            data;

NSSize realDimensions = [stringWithAttributes size];

//Alignment
float xPadding = 0;

// Mac crashes if the width or height is 0
if( realDimensions.width > 0 && realDimensions.height > 0 ) {
    switch (alignment) {
        case CCTextAlignmentLeft: xPadding = 0; break;
        case CCTextAlignmentCenter: xPadding = (dimensions.width-realDimensions.width)/2.0f; break;
        case CCTextAlignmentRight: xPadding = dimensions.width-realDimensions.width; break;
        default: break;
    }

    //Disable antialias
    [[NSGraphicsContext currentContext] setShouldAntialias:NO];

    NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(POTWide, POTHigh)];

    [image lockFocus];


    [stringWithAttributes drawAtPoint:NSMakePoint(xPadding, POTHigh-dimensions.height)]; // draw at offset position


    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithFocusedViewRect:NSMakeRect (0.0f, 0.0f, POTWide, POTHigh)];
    [image unlockFocus];

    data = (unsigned char*) [bitmap bitmapData];  //Use the same buffer to improve the performance.

    NSUInteger textureSize =  POTWide*POTHigh   ;

    for(int i = 0; i<textureSize; i++) //Convert RGBA8888 to A8
    {
        data[i] = data[i*4+3];

    }


    data = [self keepData:data length:textureSize];

    self = [self initWithData:data pixelFormat:kCCTexture2DPixelFormat_A8 pixelsWide:POTWide pixelsHigh:POTHigh contentSize:dimensions];


    [bitmap release];
    [image release];

} else {
    [self release];
    return nil;
}

return self;
// get nearest power of two
NSSize POTSize = NSMakeSize(ccNextPOT(dimensions.width), ccNextPOT(dimensions.height));

// Get actual rendered dimensions
NSRect boundingRect = [stringWithAttributes boundingRectWithSize:NSSizeFromCGSize(dimensions) options:NSStringDrawingUsesLineFragmentOrigin];

// Mac crashes if the width or height is 0
if( POTSize.width == 0 )
    POTSize.width = 2;

if( POTSize.height == 0)
    POTSize.height = 2;

CGSize offset = CGSizeMake(0, POTSize.height - dimensions.height);

//Alignment
switch (alignment) {
    case CCTextAlignmentLeft: break;
    case CCTextAlignmentCenter: offset.width = (dimensions.width-boundingRect.size.width)/2.0f; break;
    case CCTextAlignmentRight: offset.width = dimensions.width-boundingRect.size.width; break;
    default: break;
}


CGRect drawArea = CGRectMake(offset.width, offset.height, boundingRect.size.width, boundingRect.size.height);



NSInteger POTWide = POTSize.width;
NSInteger POTHigh = POTSize.height;


NSBitmapImageRep* bitmap = [[[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:bitmap];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:g];

[stringWithAttributes drawWithRect:drawArea options:NSStringDrawingUsesLineFragmentOrigin];
[NSGraphicsContext restoreGraphicsState];

unsigned char *data = (unsigned char*) [bitmap bitmapData];  //Use the same buffer to improve the performance.

NSUInteger textureSize = POTWide * POTHigh  ;

unsigned char *dst = (unsigned char*)data;
for(int i = 0; i<textureSize; i++)
{
    dst[i] = data[i*4+3];                    //Convert RGBA8888 to A8
}

data = [self keepData:dst length:textureSize];

self = [self initWithData:data pixelFormat:kCCTexture2DPixelFormat_A8 pixelsWide:POTSize.width pixelsHigh:POTSize.height contentSize:dimensions];

//[bitmap release];
//[image release];

return self;