How to choose the encoding based on the current language using CGContextSelectFont?
Using CGContextSelectFont to draw to a bitmap,开发者_高级运维 but using a certain encoding. When using a different language, this will not work. What is the recommended way of choosing the encoding based on current language? Please note that the localization is working fine.
CGContextDrawImage(context, rect, image.CGImage);
NSString *temp = [[NSString alloc] initWithFormat:@"%@%@",[Localization string:@"WaitingForDownloadFor"],title];
const char *text = [temp UTF8String];
CGContextSelectFont(context, "Arial", 18, kCGEncodingMacRoman); //*** line in question
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
CGContextShowTextAtPoint(context, 10, h/2, text, strlen(text));
Here is the code that answers the question, thanks for the pointers....The Localization class is a custom class.
NSString *temp = [[NSString alloc] initWithFormat:@"%@%@",[Localization string:@"Downloading"],title];
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
CGContextDrawImage(context, rect, image.CGImage);
UIGraphicsPushContext(context);
CGContextSetRGBFillColor(context, 1, 1, 1, 1);
UIFont* font = [UIFont fontWithName:@"Arial" size:18.0];
// need to do this or Mirrored Backwards
CGContextTranslateCTM(context, 0, h);
CGContextScaleCTM(context, 1.0, -1.0);
[temp drawAtPoint:CGPointMake(10.0,h/2) withFont:font];
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage *image2 = [[UIImage imageWithCGImage:imageRef] retain];
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
UIGraphicsPopContext();
精彩评论