开发者

Displaying 'special' characters from other encodings in UILabel or similar

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.

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.

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;

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.

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.

So the questions are:

  • 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?

(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.)


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

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜