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

查看:151
本文介绍了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天全站免登陆