在 iPhone 上绘制 Unicode 字符
为什么弄清楚如何在 iPhone 上绘制 Unicode 字符、导出简单的字体指标(例如所选字体中每个图像字形的宽度)如此困难?
看起来使用 NSLayoutManager 很容易,但该 API 显然在手机上不可用。 人们这样做的方式似乎是使用私有 API,CGFontGetGlyphsForUnichars
,这不会让你通过 Apple 看门人进入应用商店。
有人可以向我指出说明如何执行此操作的文档吗? 我正在迅速脱发。
霍华德
Why is it so hard to figure out how to draw Unicode characters on the iPhone, deriving simple font metrics along the way, such as how wide each imaged glyph is going to be in the font of choice?
It looks like it'd be easy with NSLayoutManager
, but that API apparently isn't available on the phone. It appears the way people are doing this is to use a private API, CGFontGetGlyphsForUnichars
, which won't get you past the Apple gatekeepers into the App store.
Can anybody point me to documentation that shows how to do this? I'm losing hair rapidly.
Howard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设排除
CGFontGetGlyphsForUnichars
这是一个疏忽而不是故意的举动,但我不是
把整个农场都押在上面。 因此,我使用
[NSString drawAtPoint:withFont:];
(在 UIStringDrawing.h 中)和
[NSString sizeWithFont];
这也具有执行适当替换的优点
关于字体中缺少的字符,
CGContextShowGlyphs 不这样做。
I assumed that the exclusion of
CGFontGetGlyphsForUnichars
was an oversight rather than a deliberate move, however I'm not
betting the farm on it. So instead I use
[NSString drawAtPoint:withFont:];
(in UIStringDrawing.h)and
[NSString sizeWithFont];
This also has the advantage of performing decent substitution
on characters missing from your font, something that
CGContextShowGlyphs
does not do.如果您想绘制 unicode 而不是 CGContextShowGlyphsAtPositions ,CoreText 就是答案。 如果您需要自定义绘图,它也比
[NSString drawAtPoint:withFont:]
更好。这是一个完整的例子:
CoreText is the answer if you want to draw unicode rather than
CGContextShowGlyphsAtPositions
. Also it's better than[NSString drawAtPoint:withFont:]
if you need custom drawing.Here is a complete example:
我已经为私有函数做了一个非常合适的替代。 在这里阅读:
http://thoughts.codemelody.com/2009/07/a -replacement-for-cgfontgetglyphsforunichars/
I've made a pretty suitable replacement for the private function. Read about it here:
http://thoughts.codemelody.com/2009/07/a-replacement-for-cgfontgetglyphsforunichars/