Core Graphics 中的 Unicode 字符
我有一个 iPad 应用程序,我在 SQLite DB 中存储一些 unicode(非 ASCII)数据。后来,我检索该数据并需要将其写入 pdf。所有 ASCII 数据都很好,但 unicode 数据呈现为“编码字符”
该过程如下所示: 检索数据并将其写入控制台。一切顺利。以下是控制台的输出:LOOKUP:↑ 启用所有活动:FOR:COORDINATIONGOAL:(
向上的小箭头是我的 unicode 字符)
此时,数据存储在 NSString 中。接下来,我将其转换为字符,以便可以在核心图形中使用它:
NSString *t = [data objectForKey:pi.persistencekey];
char *text = " ";
if ([t length] > 0) {
text = [t UTF8String];
}
CGContextShowTextAtPoint (pdfContext, pi.x, pageRect.size.height - pi.y, text, strlen(text));
PDF 生成得很好,但生成的文本在向上箭头应该在的位置显示了奇怪的字符。
我尝试过其他解码方法,但都不起作用。
预先感谢您的任何帮助。
I have an iPad app where I am storing some unicode (non-ASCII) data in a SQLite DB. Later, I retrieve that data and need to write it to a pdf. All ASCII data does fine, but the unicode data is presenting as "encoded characters"
The process goes like this:
Retrieve the data and write it to the console. This goes fine. Here is the output to the console: LOOKUP:↑ to enable all activities:FOR:COORDINATIONGOAL:
(The little up arrow is my unicode character)
At this point, the data is stored in an NSString. So next, I convert it to a char so I can use it in core graphics:
NSString *t = [data objectForKey:pi.persistencekey];
char *text = " ";
if ([t length] > 0) {
text = [t UTF8String];
}
CGContextShowTextAtPoint (pdfContext, pi.x, pageRect.size.height - pi.y, text, strlen(text));
The PDF generates fine, but the text generated shows strange characters where the up arrow is supposed to be.
I have tried other decoding methods and none work.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CGContextShowTextAtPoint 在绘制 unicode 方面有一些已知的弱点。基本上没有。
你有两个选择:
NSString 的drawAtPoint 和它的朋友。它们可以通过在文档中搜索 UIStringDrawing 来找到。
或者,如果您需要进入低级,请使用 Core Text。
大多数时候(99%) 1. 已经足够好了。
CGContextShowTextAtPoint has some known weaknesses with drawing unicode. Basically it doesn't.
You have two options:
NSString's drawAtPoint and it's friends. They can be found by searching doc for UIStringDrawing.
or if you need to go low-level, Core Text.
Most of the time (99%) 1. is good enough.