显示带有特殊字符的字体 - UTF-8
我正在尝试在 linux 下运行的设备上显示 £ 这样的字符。 它使用 utf-8 字符集格式。 当我显示包含特殊字符的字符串时,它也会显示其他字符。 如果我在控制台上打印字符串,它看起来没问题,但是当我解析字符串以在屏幕上加载每个字母字体时,它会变得很奇怪,并且输出不是正确的。
有没有人经历过类似的事情或者能给我一些建议。
谢谢。
i am trying to display characters like £ on a device which runs under linux .
it is using utf-8 charset format .
when i get to display a string which contains special characters, it displays other characters too .
if i print the string on the console it appears ok, but when i parse the string to load each letter font on the screen it gets weird and the output is not the correct one .
Has anyone experienced something like this or is able to give me some advice .
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果字符串是UTF-8,则需要使用TTF_RenderUTF8_Solid()等调用。这就是 True Type 字体。
如果您有自己的字体和字形,那么您需要将 UTF-8 字符串转换为 UTF-16(最常用)或 UTF-32(如果支持 i18n),然后使用它来索引字形表。
当字体超过 ASCII 限制时,您无法将 utf-8 字符串的各个字节解析为有效字符。
请参考以下代码片段:http://unicode.org/faq/utf_bom.html
If the string is in UTF-8, you need to use call such as TTF_RenderUTF8_Solid(). Thats for True Type Fonts.
If you have your own fonts and glyphs for your fonts, then you need to convert your UTF-8 string into to UTF-16 (most commonly used) or UTF-32 (in case of i18n support) and then use it to index into the glyph table.
You can't parse individual bytes of your utf-8 string into a valid character, when the font crosses the ASCII limits.
Refer these code snippets: http://unicode.org/faq/utf_bom.html