不显示的Unicode字符 [英] Unicode Character Not Showing

查看:747
本文介绍了不显示的Unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用

CGContextSelectFont(context, "HelveticaNeue", textSize, kCGEncodingMacRoman);    
CGContextShowTextAtPoint(context, myCenter.x, myCenter.y + textHeight, [sName     cStringUsingEncoding:NSMacOSRomanStringEncoding], [sName length]); 

它显示为方形框或圆形。我发现这个符号是十进制的176和221E十六进制格式。我使用Helvetica作为我的字体,并试过没有运气的其他人。这是我使用的编码的一个问题?

It is displayed as a square box, or a circle. I have found out this symbol is in decimal 176 and 221E in Hexadecimal format. I am using Helvetica as my font, and have tried others with no luck. Is this a problem with the encoding I am using?

推荐答案

原来是CGContextSelectFont只支持MacRoman编码,只有一小组字符。为了在字符串中显示Unicode字符,您必须使用CGSetFont或Cocoa绘图系统。 CGSetFont要求你使用Cocoa无论如何将字符映射到字形,然后使用CGContextShowGlyphsAtPoint绘制字形。如果你真的需要显示Unicode字符,我建议你看看其他方法来绘制这些字符串。

It turns out that CGContextSelectFont only supports MacRoman encoding, which is basically has only a small set of characters. In order to display Unicode characters in a string, you have to use CGSetFont or the Cocoa drawing system. CGSetFont requires that you use Cocoa anyway to map characters to glyphs and then draw the glyphs using CGContextShowGlyphsAtPoint. I recommend that you look into other ways to draw these strings if you really need to display Unicode characters.

这段代码基本上会显示无穷大符号:

This code basically will display the infinity symbol:

- (void)drawRect:(CGRect)rect {
    unichar inf = 0x221E; // infinity symbol
    NSString* sName = [[NSString alloc] initWithCharacters:&inf length:1];
    UIFont* font = [UIFont fontWithName:@"Helvetica" size:32.0];
    [sName drawInRect:CGRectMake(20, 20, 40, 40)
             withFont:font];
    [sName release];
}

另外请注意,在iPhone上(和在Mac上)Helvetica Neue实际上不存在...它的名字只是映射回标准Helvetica。请参阅 http://daringfireball.net/misc/2007/07/上的表格iphone-osx-fonts 有关iPhone上可用字体的详细信息。

Also note that on the iPhone (and on the Mac) Helvetica Neue actually does not exist... its name just maps back to standard Helvetica. See the table at http://daringfireball.net/misc/2007/07/iphone-osx-fonts for more information on available fonts on the iPhone.

这篇关于不显示的Unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆