从UILabel或类似的其他编码显示“特殊”字符 [英] Displaying 'special' characters from other encodings in UILabel or similar

查看:187
本文介绍了从UILabel或类似的其他编码显示“特殊”字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在我的iPhone上模拟一个终端,使用我在真正DEC终端上享用的原始图形来玩Nethack之类的游戏。 Nethack允许选择用于vt兼容终端的Decgraphics或用于代码页437支持的IBM图形。

I'd like to be able to simulate a terminal on my iPhone to play games like Nethack using the primitive graphics I enjoyed on a real DEC terminal. Nethack allows selection of DECgraphics for vt-compatible terminals or IBMGraphics for codepage 437 support.

我知道这些特殊图形字符是由发送到终端的字符串生成的(vt100.net有大量信息,包括终端手册和测试程序)。我可以接收和解释这些字符串,但我需要能够在UIView中重现和显示这些字符。

I know that these special graphics characters are generated by strings sent to the terminal (vt100.net has a huge amount of information including the terminal manuals and test programs). I can receive and interpret those strings but I need to be able to reproduce and display those characters in a UIView.

它看起来像kCFStringEncodingMacVT100和kCFStringEncodingDOSLatinUS是关键的谜题。这里有一些部分代码显示我试图做什么来获得特殊字符字形到UILabel:

It looks like kCFStringEncodingMacVT100 and kCFStringEncodingDOSLatinUS are the keys to the puzzle. Here's a bit of partial code showing what I tried to do to get "special characters" glyphs onto a UILabel:

            UInt8 c = some value...
            NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingMacVT100);
            NSData *charData = [NSData dataWithBytes:&c length:1];
            NSString *charString = [[NSString alloc] initWithData:charData encoding:stringEncoding];
            label.font = [UIFont fontWithName:@"Courier New" size:20.f];
            label.text = charString;

我尝试了c的值从0到255.我可以显示空格到'〜'的字符所有的期望东西之间使用这段代码,但没有角或其他线条字符。当没有字符显示时,charString是nil。

I tried values of c from 0 to 255. I can display characters from space to '~' with all the expected stuff in between using this code but there are no corners or other line characters at all. When there is no character to display, charString is nil.

现在我很确定Courier New TTF有这些字符 - 在我的Mac上我可以玩Nethack终端字体设置为Courier New,我可以设置DECgraphics,显示OK。

Now I'm pretty sure the Courier New TTF has these characters - on my Mac I can play Nethack with the terminal font set to Courier New and I can set DECgraphics and the display is OK.

所以问题是:


  • 上面的代码有什么问题?

  • 什么免费可用的单行格式字体支持DEC特殊字符和/或代码页437?

  • 如何在UILabel或类似的软件中显示这些字形?
  • li>
  • what's wrong with the code above?
  • what freely available monospaced truetype fonts are there supporting the DEC special characters and/or codepage 437?
  • how can you test a TTF once you have it to be sure those glyphs are there?
  • how can you display these glyphs in a UILabel or similar?

(我不想使用任何图形图块,我不喜欢它们,我知道至少有两个Nethacks已经可以免费,但没有一个简单的键盘界面我想要的,我发现弹出窗口一切接近真的很慢和令人沮丧,我知道这不是一个容易的项目。 )

(I don't want to use any of the graphical tilesets available, I don't like them. I know there are at least two Nethacks available for free already but none have the straightforward keyboard interface I want, I find the popup a window for everything approach really slow and frustrating. I know it's not an easy project. And I might want to to Angband one day.)

推荐答案

CP437中的字形的大部分(全部?)都有相应的代码点符合Unicode标准,详情请参阅此维基百科文章

Most (all?) of the glyphs in CP437 have corresponding code points in the Unicode standard, as detailed on this Wikipedia article.

例如,要显示俱乐部,您可以执行以下操作。它使用默认的 UILabel 字体:

For example, to display a club, you can do the following. It works with the default UILabel font:

UniChar club = 0x2663;
NSString *clubString = [NSString stringWithCharacters:&club length:1];
[label setText:clubString];

这篇关于从UILabel或类似的其他编码显示“特殊”字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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