显示“特殊”; UILabel 或类似中其他编码的字符

发布于 2024-11-29 17:07:55 字数 1339 浏览 2 评论 0原文

我希望能够在 iPhone 上模拟终端,使用我在真实 DEC 终端上喜欢的原始图形来玩 Nethack 等游戏。 Nethack 允许选择用于 vt 兼容终端的 DECgraphics 或用于代码页 437 支持的 IBMGraphics。

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

看起来 kCFStringEncodingMacVT100 和 kCFStringEncodingDOSLatinUS 是解决这个难题的关键。下面是一些部分代码,显示了我尝试将“特殊字符”字形添加到 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;

我尝试了从 0 到 255 的 c 值。我可以显示从空格到“~”的字符以及其间所有预期的内容使用此代码,但根本没有角点或其他线条字符。当没有字符可显示时,charString 为 nil。

现在我非常确定 Courier New TTF 具有这些字符 - 在我的 Mac 上,我可以使用设置为 Courier New 的终端字体来玩 Nethack,并且我可以设置 DECgraphics 并且显示正常。

所以问题是:

  • 上面的代码有什么问题?
  • 有哪些免费提供的等宽 truetype 字体支持 DEC 特殊字符和/或代码页 437?
  • 一旦获得 TTF,如何测试它以确保这些字形存在?
  • 如何在 UILabel 或类似内容中显示这些字形?

(我不想使用任何可用的图形图块集,我不喜欢它们。我知道至少有两个 Nethacks 可以免费使用,但没有一个具有我想要的简单键盘界面,我发现弹出一个窗口因为一切都非常缓慢且令人沮丧,我知道这不是一个容易的项目,有一天我可能会想要去 Angband。)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕巷 2024-12-06 17:07:55

CP437 中的大多数(全部?)字形在 Unicode 标准中都有相应的代码点,如这篇 Wikipedia 文章中的详细信息

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

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

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文